我想添加在地图上,每当用户点击地图上的路点。每当用户点击时,我都会得到地图上的路点,但问题是之前的路点消失了,没有显示在地图上,只有由于当前单击而绘制的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);
}
}发布于 2016-08-08 21:09:32
如果没有完整的源代码,我只能假设问题可能出在1-你用来存储WayPoints的模型中:确保新的单击点被添加到模型中,而不是被最后一个所覆盖(检查所选WayPoints的大小)或2-你正在使用的视图为每个添加事件完全重新绘制;导致最后绘制的元素之前的所有丢失。
https://stackoverflow.com/questions/38829700
复制相似问题