JMapViewer将鼠标侦听器添加到MapMarkerDot [英] JMapViewer add mouse listener to MapMarkerDot

查看:113
本文介绍了JMapViewer将鼠标侦听器添加到MapMarkerDot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向MapMarker添加鼠标监听器,这样当鼠标悬停在MapMarker上时,我就可以对事件作出反应。

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.

我实现了mouseListener,但我无法真正添加一个监听器。
问题是我没有找到MapMarker将addMouseListener的方法,因为层次结构的非实现JPanel。

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.

感谢任何帮助

推荐答案

如上所述其他,默认的 JMapViewer 构造函数使用 DefaultMapController ,通过按下鼠标右键并通过双击或鼠标滚轮进行缩放来实现地图移动。要查看地图坐标,请扩展 DefaultMapController ,覆盖 mouseClicked()并使用其中一个查看器 getPosition()方法。您可以使用您的控制器,如 Demo.java ,r30377第65行的注释所示。

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()));
    }
};

这篇关于JMapViewer将鼠标侦听器添加到MapMarkerDot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆