javagpsjmapviewerworld-map

how can i get the mouse click position from my JMapViewer world map


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

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

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.

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


Solution

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