JMapViewer add mouse listener to MapMarkerDot

六眼飞鱼酱① 提交于 2019-12-17 07:53:15

问题


I am trying to add a mouse listener to a MapMarker, so that when a mouse will hover a MapMarker, I could react with an event.

I implemented the mouseListener, but I can't really add a listener. The issue is that I did not find a way the MapMarker will addMouseListener, due to the fact that non of the hierarchy implements JPanel.

Any help appreciated


回答1:


As noted here, the default JMapViewer constructor uses a DefaultMapController, "which implements map moving by pressing the right mouse button and zooming by double click or by mouse wheel." To see map coordinates, extend DefaultMapController, override mouseClicked() and use one of the viewer's getPosition() methods. You can use your controller as shown in comments at line 65 of Demo.java, r30377.

 new DefaultMapController(map){

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println(map.getPosition(e.getPoint()));
    }
};


来源:https://stackoverflow.com/questions/24588492/jmapviewer-add-mouse-listener-to-mapmarkerdot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!