每当用户单击地图时,我想在地图上添加航点。每当用户单击时,我都会在地图上找到路点,但问题是前一个路点消失并且未显示在地图上,仅显示由于当前单击而绘制的 wapoint。以下是航点的代码。
public class MapPanel {
public static void acc(GeoPosition loc){
MapPanel.drawNew(loc);
}
public static void drawNew(GeoPosition location ){
GeoPosition fp = new GeoPosition(location.getLatitude(),location.getLongitude());
List<GeoPosition> track = Arrays.asList(fp);
// Create waypoints from the geo-positions
Set<Waypoint> waypoints = new HashSet<Waypoint>(Arrays.asList(
new DefaultWaypoint(fp)));
// Create a waypoint painter that takes all the waypoints
waypointPainter.setWaypoints(waypoints);
// Create a compound painter that uses both the route-painter and the waypoint-painter
List<org.jxmapviewer.painter.Painter<org.jxmapviewer.JXMapViewer>> painters = new ArrayList<org.jxmapviewer.painter.Painter<org.jxmapviewer.JXMapViewer>>();
painters.add(waypointPainter);
CompoundPainter<org.jxmapviewer.JXMapViewer> painter = new CompoundPainter<org.jxmapviewer.JXMapViewer>(painters);
frameWork.mapViewer.setOverlayPainter(painter);
}
public static void main (String args) {
frame.setContentPane(frameWork.mainPanel);
// Create a TileFactoryInfo for OpenStreetMap
TileFactoryInfo info = new OSMTileFactoryInfo();
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
frameWork.mapViewer.setTileFactory(tileFactory);
// Set the Default Location
GeoPosition chemnitz = new GeoPosition(50.833333, 12.916667);
//Set the focus
frameWork.mapViewer.setZoom(1);
frameWork.mapViewer.setAddressLocation(chemnitz);
// Add interactions
MouseInputListener mia = new PanMouseInputListener(frameWork.mapViewer);
frameWork.mapViewer.addMouseListener(mia);
frameWork.mapViewer.addMouseMotionListener(mia);
frameWork.mapViewer.addMouseListener(new CenterMapListener(frameWork.mapViewer));
frameWork.mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(frameWork.mapViewer));
frameWork.mapViewer.addKeyListener(new PanKeyListener(frameWork.mapViewer));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.pack();
frame.setSize(900, 600);
frame.setVisible(true);
}
}