我如何从我的JMapViewer世界地图中获取鼠标点击位置 [英] how can i get the mouse click position from my JMapViewer world map

查看:166
本文介绍了我如何从我的JMapViewer世界地图中获取鼠标点击位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 JMapViewer jar来在JPanel上显示世界地图。

Im using the JMapViewer jar to show the world map on a JPanel.

在地图上添加 MapMarkerDot的这些都是gps点。

On the map im adding MapMarkerDot's which are gps points.

问题是当我在地图上点击 MapMarkerDot 时,我无法找到
接口或侦听器来捕捉点击并给我点击$
点击 MapMarkerDot 身份。

The problem is when i click a MapMarkerDot on the map i cannot
find an interface or listener to catch the click and give me the
clicked MapMarkerDot identity.

有任何人在这里工作的代码或可以给我一些想法做什么。

has anyone here worked with the code or can give me some ideas what to do.

我不想修改jar源代码,但也许我必须输入一个界面。

I would not like to modify the jar source but maybe i have to input an interface.

我知道这是一个抽象的问题,但希望得到帮助

I know this is kind of an abstract question but hoping for help

推荐答案

回答我自己的问题。

通过比较
MapMarker位置和鼠标点击位置的原始x / y计算基本解决了这个问题。

Answering my own question.
Basically solved this by raw x/y calculation comparing the
MapMarker position against mouse click position.

if (e.getButton() == MouseEvent.BUTTON1) {
    Point p = e.getPoint();
    int X = p.x+3;
    int Y = p.y+3;
    List<MapMarker> ar = map.getMapMarkerList();
    Iterator<MapMarker> i = ar.iterator();
    while (i.hasNext()) {

        MyMapMarkerDot mapMarker = (MyMapMarkerDot) i.next();

        if(mapMarker.position != null){

            int centerX =  mapMarker.position.x;
            int centerY = mapMarker.position.y;

            // calculate the radius from the touch to the center of the dot
            double radCircle  = Math.sqrt( (((centerX-X)*(centerX-X)) + (centerY-Y)*(centerY-Y)));

            // if the radius is smaller then 23 (radius of a ball is 5), then it must be on the dot
            if (radCircle < 8){
                ShowClickedUser(mapMarker.Tag);
            }

        }
    }
}

这篇关于我如何从我的JMapViewer世界地图中获取鼠标点击位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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