2011-05-05 64 views
1

我使用JXMapKit與openStreetMap作爲提供程序,我試圖找到一種方法來顯示地圖上的路線。然後使用路線,以便車輛可以跟隨它們。無論如何這樣做還是有其他選擇嗎?JXMapKit OpenStreetmaps創建路由

在此先感謝。

回答

1

是的,你可以。從這個鏈接摘自:http://www.naxos-software.com/blog/index.php?/archives/92-TracknMash-Openstreetmap-Karten-in-JavaSwing-mit-JXMapViewer.html

你寫你自己的畫家類並覆蓋paint方法來畫線:

public void paint... { 
g = (Graphics2D) g.create(); 
    // convert from viewport to world bitmap 
    Rectangle rect = object.getViewportBounds(); 
    g.translate(-rect.x, -rect.y); 

    //set the line properties 
    g.setColor(Color.RED); 
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
    g.setStroke(new BasicStroke(2)); 

    // do the drawing 
    int lastX = -1; 
    int lastY = -1; 
    for (GeoPosition point : points) { 
     Point2D pt = object.getTileFactory().geoToPixel(point, object.getZoom()); 
     if (lastX != -1 && lastY != -1) { 
      g.drawLine(lastX, lastY, (int) pt.getX(), (int) pt.getY()); 
     } 
     lastX = (int) pt.getX(); 
     lastY = (int) pt.getY(); 
    } 
} 

點在哪裏你GeoPosition對象,形成路線的列表。

然後你這個畫家添加到您的MapKit作爲OverlayPainter:

myMapKit.getMainMap().setOverlayPainter(new MyPainter(myMockPoints));