Sunday, August 7, 2011

Java - JXMapKit - restrict user scrolling outside the world's edges

After playing around a little bit with JXMapKit, monitoring the map for hover events and drawing items to specified geoPositions, I found that my hover detection would not work when the map had been scrolled around the world a complete turn (that is dragging the map to the left or right again and again until you've reached the same spot again where you started).

As I did not succeed in correctly computing the GeoLocations back to the viewport (as they were now computed outside of the viewport because of the scrolling), I decided to restrict the user in scrolling over the left / right edges of the map.

Looking at the JXMapViewer source code, I found 2 undocumented methods which, if used in the right way, do just what I required. Call them this way to ensure horizontal scrolling outside of the regular maparea is disabled:

mapKit.getMainMap().setRestrictOutsidePanning(true);
mapKit.getMainMap().setHorizontalWrapped(false);

1 comment:

  1. Hello Florian,
    That was a really good information. Even I am working on JxMApViewer and we have very less resource available on JxMapViewer over the internet. Thanks to you for providing such useful tips.

    ReplyDelete