0

I am using the jxmapkit to show a map in a java frame. Now i am trying to translate a click x,y position into Lat, Long.

This is what I have so far:

 public void mouseClicked(MouseEvent e)
        {               
            Point point = e.getPoint();               
            JXMapViewer map = mainMap.getMainMap();
            Rectangle bounds = map.getViewportBounds();
            int x = (int)(point.getX() - bounds.getX());
            int y = (int)(point.getY() - bounds.getY());
            GeoPosition mappos =   map.getTileFactory().pixelToGeo(new Point(x,y), map.getZoom());

But the bounds x and y are too big 282723 and 205680 so the translation is obviously failing.

Does Rectangle bounds = map.getViewportBounds(); work or am I doing something wrong?

Marcom
  • 4,621
  • 8
  • 54
  • 78

1 Answers1

1

are you tried to put that into JScrollPane and then just move with Rectangle to Visible ViewPort, I think that's job for that ...

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • but the map is visible and fits in the frame. Why is a scrollpane needed ? – Marcom May 04 '11 at 08:57
  • there's alternative http://stackoverflow.com/questions/5841747/displaying-location-on-a-world-map/5841804#5841804 – mKorbel May 04 '11 at 11:19