每当用户点击地图时,我想在地图上添加航点。用户点击时我在地图上得到了航点,但是问题是前一个航点消失并且没有在地图上显示,只显示由于当前点击而绘制的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);
}
}
答案 0 :(得分:0)
没有完整的源代码我只能假设问题可能在 1-用于存储WayPoints的模型:确保将新单击的点添加到模型中,而不是由最后一个覆盖(检查所选WayPoints的大小) 要么 2-您正在使用的视图完全重新绘制每个添加事件;在最后画的元素之前造成所有损失。