开发者

Java mapkit viewportbounds

开发者 https://www.devze.com 2023-03-01 13:43 出处:网络
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.

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开发者_StackOverflow中文版 am I doing something wrong?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消