Search code examples
androidosmdroid

OSMDroid Limit the map in North/South


I am working with the OSMDroid API and I'm wondering if there's a way to limit the map in north and south. I mean, is this possible to prevent the map from endlessly repeating itself on the Y-Axis.

I found this issue on the Github's "osmdroid" project but the code of the patch is too old and cannot be applied to the new version of osmdroid (4.2)

EDIT

I tried the setScrollableAreaLimit method but there is a bug (maybe) in the upper-left point. The map jump on the other side when I come close to its end.

Thank you by advance


Solution

  • I modified two lines in the class MapView.

    I replaced x += worldSize; by x=0; and y += worldSize; by y=0;

          public void scrollTo(int x, int y) {
            final int worldSize = TileSystem.MapSize(this.getZoomLevel(false));
            while (x < 0) {
                //x += worldSize;
             x=0;
            }
            while (x >= worldSize) {
                x -= worldSize;
            }
           while (y < 0) {
              // y += worldSize;
               y=0;
            }
            while (y >= worldSize) {
                y -= worldSize;
            }
         [...]
         }