Dear Ian,
thank you for your quick reply!
I am going to try DirectLayer soon.
Now I act like this way:
Step 1 Extend JMapPane to GPSMapPane
Step 2 declare a list of GPSPoint to store all the GPS points which should be 
displayed at the screen
Step 3 Override paintComponent method to further draw all GPS points, after 
paint components
Step 4 In another JFrame, declare a object of GPSMapPane. Add a GPSPoint to the 
list of GPSMapPane and repaint the mappane
---------------------------------------------------------
public class GPSMapPane extends JMapPane {
    public  List<GPSPoint> gps = new ArrayList<GPSPoint>();
    
    public GPSMapPane(MapContent map) {
// TODO Auto-generated constructor stub
    super(map);
}


@Override 
    protected void paintComponent(Graphics g) { 
        //animationTimer.stop(); 
        super.paintComponent(g); 
        drawSprite(g);


    } 
    
    public void drawSprite(Graphics g) { 
        for(GPSPoint p : gps){
        setSpritePosition((Graphics2D) g,p.lon,p.lat);    
        }     
    }
    
    private void setSpritePosition(Graphics2D g, double x, double y) {
        ReferencedEnvelope worldBounds = null;
        //worldBounds = getMapContext().getLayerBounds();
worldBounds = getMapContent().getMaxBounds();


        CoordinateReferenceSystem crs = 
worldBounds.getCoordinateReferenceSystem();


        Rectangle screenBounds = getVisibleRect();
        
        AffineTransform worldToScreen = getWorldToScreenTransform();
        Point2D worldPoint = new Point2D.Double(x, y);
        System.out.println("world point: " + worldPoint.getX() + "," + 
worldPoint.getY());
        Point2D screenPoint = worldToScreen.transform(worldPoint, null);
        System.out.println("screen point: " + screenPoint.getX() + "," + 
screenPoint.getY());
        
        Rectangle r = new Rectangle((int)screenPoint.getX() - 7, 
(int)screenPoint.getY() - 7, 
        14, 14); 
        
        g.setColor(Color.blue);
        g.fillOval(r.x,r.y,(int)r.getWidth(),(int)r.getHeight());


    }
}
When the number of points is not very large, this way works. But I think as you 
said when the number of points is large, another way is needed.
Plus, above way has a weakness that: when you have ZOOM or PAN action, the 
layers will move first, then the position of GPS points will be recomputed and 
move to new place.....
I do not know if DIrectLayer can avoid this....
If above code has some serious problem, pls kindly give me your comments.
Thx.



在 2015-02-11 16:21:54,"Ian Turton" <ijtur...@gmail.com> 写道:

you could use a DirectLayer 
(http://docs.geotools.org/stable/javadocs/org/geotools/map/DirectLayer.html) - 
but you might need to think of a different plan if you have a lot of clients 
sending data as pretty soon you whole map will be covered in points?



Ian


On Wed Feb 11 2015 at 7:17:46 AM wbh <wangbaohua2...@163.com> wrote:

Plus, if I create a feature whenever I received a lon/lat, will this way slow 
down the system when many many TCP/IP clients sending data to it?







At 2015-02-11 14:57:34, "wbh" <wangbaohua2...@163.com> wrote:

Hi all,
I want to display a serie of points, which are drew based on lon/lat received 
from a TCP/IP client (Yes, a simple GPS tracker)
These points are not going to be built as features. 
Although I can get the screen position based on the lon/lat, I find when I have 
PAN or ZOOM action, those points which have been drawn will disappear while new 
points are still showing successfully.
To keep those points showing, my idea is storing the lon/lat of all received 
points, when repainting, the screen position of all those stored points will be 
recomputed and redrawed.
But is this the best way to do this?
If someone can provide me example code, I will appreciate much.
Thx.







------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. 
http://goparallel.sourceforge.net/_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to