首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在用户点击地图时在地图(OSM)上添加标记(航点)?

如何在用户点击地图时在地图(OSM)上添加标记(航点)?
EN

Stack Overflow用户
提问于 2016-08-08 20:50:14
回答 1查看 759关注 0票数 0

我想添加在地图上,每当用户点击地图上的路点。每当用户点击时,我都会得到地图上的路点,但问题是之前的路点消失了,没有显示在地图上,只有由于当前单击而绘制的wapoint才会显示出来。以下是该路点的代码。

代码语言:javascript
复制
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);


}
}
EN

回答 1

Stack Overflow用户

发布于 2016-08-08 21:09:32

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38829700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档