0

每当用户单击地图时,我想在地图上添加航点。每当用户单击时,我都会在地图上找到路点,但问题是前一个路点消失并且未显示在地图上,仅显示由于当前单击而绘制的 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);


}
}
4

1 回答 1

0

如果没有完整的源代码,我只能假设问题可能出在 1-您用来存储航点的模型中:确保将新点击的点添加到模型中,而不是被最后一个覆盖(检查选定的航点)或 2- 您正在使用的视图为每个添加事件完全重新绘制;导致所有在最后绘制的元素之前丢失。

于 2016-08-08T13:09:32.120 回答