Hi Erik, 
I just looked at some old code I used to animate things in a
StyledMapPane,
The main body of the animation loop boiled down to:
        synchronized (this.getTreeLock()){
            invalidate();
            repaint((java.awt.geom.Rectangle2D) null);
        }

The getTreeLock() method will provide you with an object to use as a
lock to avoiding threading problems.
The argument to the repaint method is the area to repaint, as I
remember, if it is null it repaints everything but I think maybe that
was unnecessary and repaint() does exactly the same thing.

I don't know why your code doesn't work but I would guess that the Timer
isn't behaving the way you expect it to... 
Is that actionPerformed method definitely getting called?
If you call invalidate(); repaint(); from  somewhere else (after you've
added the AnimationLayer) do the rendered marks appear?
As I say, just guesses, sorry if you've checked such things already,

colin


________________________________

        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Palmer, Erik
        Sent: 23 May 2006 17:11
        To: [email protected]
        Subject: [Geotools-gt2-users] Simple animation repaint issues
        
        

        Hello, 

        Environment: geotools-bin-2.2.RC2 and Java 1.5.0_06. 

        Issue: I have been working on a custom layer to perform a simple
animation of a point moving along a path defined by latitude and
longitude coordinates. I started with the framework from the MapViewer
sample and created a StyledMapPane to display a shapefile and then added
my animation layer to the via
mapPane.getRenderer().addLayer(AnimationLayer). My AnimationLayer
extends RenderedMarks and contains a timer whose callback function
updates the current coordinates and then invokes invalidate and repaint.
The problem is that the points are never displayed, UNLESS I perform a
zoom (Zoom In, Zoom Out) or pan (Left, Right, Up, Down) operation. So it
appears that I need to perform some operation that is a subset of the
pan and zoom functionality, but I'm having trouble determining exactly
what it is. Any help or suggestions would be greatly appreciated.

        My custom layer and Iterator are as follows: 

        import java.awt.Color; 
        import java.awt.Shape; 
        import java.awt.event.ActionEvent; 
        import java.awt.event.ActionListener; 
        import java.awt.geom.Ellipse2D; 
        import java.awt.geom.Point2D; 
        import java.util.Vector; 
        import javax.swing.Timer; 
        import org.geotools.renderer.j2d.GeoMouseEvent; 
        import org.geotools.renderer.j2d.MarkIterator; 
        import org.geotools.renderer.j2d.RenderedMarks; 

        /** 
         * Custom animation layer to test the performance of a single 
         * point moving along a simple path. 
         */ 
        public class AnimationLayer extends RenderedMarks implements
ActionListener{ 

           /**Timer to handle simple point animation */ 
           private Timer m_Timer = null; 
            
           /**Timer update rate in milliseconds */ 
           private int m_UpdateRateMilliSecs = 1000; 
                
           /**Stores a collection of points to be drawn on this layer*/ 
           private Vector<Point2D.Double> m_Points = new
Vector<Point2D.Double>(); 
            
           /**Current latitude */ 
           private double m_CurrLatDeg  = 0.0; 
            
           /**Current longitude*/ 
           private double m_CurrLongDeg = 0.0; 
            
           /** Creates a new instance of an animation layer */ 
           public AnimationLayer() {   
                      
              //Create and start the animation timer. 
              m_Timer = new Timer(m_UpdateRateMilliSecs, this); 
              m_Timer.start(); 
           } 
            
           /**Handles timer action */ 
           public void actionPerformed (ActionEvent e){ 
                  
              //Remove all points. 
              m_Points.clear(); 
               
              //Add the current position. 
              m_Points.add(new Point2D.Double(m_CurrLongDeg,
m_CurrLatDeg)); 
               
              //Update current position. 
              m_CurrLatDeg  += 5.0; 
              if(m_CurrLatDeg > 90) 
                 m_CurrLatDeg = 0.0; 
              m_CurrLongDeg += 0.0; //keep fixed, for now. 
               
              //Update the layer? This does not seem to repaint the
layer correctly unless zoom or pan is invoked. 
              invalidate(); 
              repaint(); 
           } 
            
           public MarkIterator getMarkIterator() { 
              return new PointIterator(m_Points); 
           } 
            
           /** 
            * The PointIterator class provides the capability for the
animation 
            * layer to retrieve the points it will display. 
            */ 
           class PointIterator extends MarkIterator { 
                
              private final Vector coordinates; 
              private int index = -1; 

              PointIterator(Vector coordinates) { 
                 this.coordinates = coordinates; 
              } 

              public int getIteratorPosition() { 
                 return index; 
              } 

              public void setIteratorPosition(int index) { 
                 this.index = index; 
              } 

              public boolean next() { 
                 return ++index < coordinates.size(); 
              } 

              public Point2D position() { 
                 return (Point2D)coordinates.get(index); 
              } 
               
              public Shape markShape(){ 
                 Ellipse2D.Float markerShape = 
                    new Ellipse2D.Float(0.0f, 0.0f, 20.0f, 20.0f); 
                 return markerShape;        
              } 
              
              public java.awt.Paint markPaint(){ 
                 return Color.YELLOW; 
              } 
              
              public java.lang.String label(){ 
                 Point2D pos = (Point2D)coordinates.get(index); 
                 String label  = "Lat: " + pos.getY() + " "; 
                        label += "Lon: " + pos.getX(); 
                 return label; 
              } 
              
              protected  String getToolTipText(GeoMouseEvent event){ 
                 return null; 
              } 
           } 
        } 

        MapPane creation is as follows...... 

        private StyledMapPane createMapPane(FeatureCollection fc, Style
style)  { 

               // Create a Context 
               context = new DefaultMapContext(); 
               MapLayer layer = new DefaultMapLayer(fc, style); 
                context.addLayer(layer); 
                
               //Create animation layer. 
               AnimationLayer animationLayer = new AnimationLayer(); 
               
               StyledMapPane mapPane = null; 
               try { 
                  // Create MapPane 
                  mapPane = new StyledMapPane(); 
                  mapPane.setMapContext(context); 
                  mapPane.getRenderer().addLayer(new
RenderedMapScale()); 
               } catch (Exception e) { 
                    // I'm sure they won't be thrown since I'm working
with a FeatureCollection 
               } 
               mapPane.getRenderer().addLayer(animationLayer); 
        } 





-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid7521&bid$8729&dat1642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to