JMapViewer add mouse listener to MapMarkerDot

后端 未结 1 1225
一整个雨季
一整个雨季 2020-11-30 15:22

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

相关标签:
1条回答
  • 2020-11-30 15:43

    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()));
        }
    };
    
    0 讨论(0)
提交回复
热议问题