我正在使用JXMapKit和openStreetMap作为提供者,我正在尝试找到一种在地图上显示路线的方法。然后使用这些路线,以便车辆可以跟随它们。无论如何都有这样做或有其他选择吗?
提前致谢。
答案 0 :(得分:1)
您编写自己的Painter类并重写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();
}
}
其中points是您的路线的GeoPosition对象列表。
然后将此Painter作为OverlayPainter添加到MapKit:
myMapKit.getMainMap().setOverlayPainter(new MyPainter(myMockPoints));