简体   繁体   English

JMapViewer将鼠标侦听器添加到MapMarkerDot

[英]JMapViewer add mouse listener to MapMarkerDot

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. 我正在尝试将鼠标侦听器添加到MapMarker,以便当鼠标将鼠标悬停在MapMarker上时,我可以对事件做出反应。

I implemented the mouseListener, but I can't really add a listener. 我实现了mouseListener,但是我不能真正添加​​一个监听器。 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. 问题是由于没有层次结构实现JPanel,所以我没有找到MapMarker添加addMouseListener的方法。

Any help appreciated 任何帮助表示赞赏

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." 如前所述这里 ,默认JMapViewer构造采用了DefaultMapController “它实现了Map按下鼠标右键,并通过双击或通过鼠标滚轮缩放移动。” To see map coordinates, extend DefaultMapController , override mouseClicked() and use one of the viewer's getPosition() methods. 要查看地图坐标,请扩展DefaultMapController ,重写mouseClicked()并使用查看器的getPosition()方法之一。 You can use your controller as shown in comments at line 65 of Demo.java , r30377. 您可以使用Demo.java第65行的注释中显示的控制器,r30377。

 new DefaultMapController(map){

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM