Search code examples
androidmapsosmdroid

How to set maximum zoom in osmdroid?


I already checked this answer, but the example does nothing else than show gray tiles (I'm in offline mode) for zoom level greater than the limit I give (4 in my case)...

OnlineTileSourceBase source = new XYTileSource("tiles", ResourceProxy.string.offline_mode, 0, 4, 256, ".png", "");

The following code shows maxZoom=4:

int zoomLevel = source.getMaximumZoomLevel();
Toast.makeText(this, "maxZoom=" + zoomLevel, Toast.LENGTH_SHORT).show();

For zoom levels between 0 and 4 my code works as expected: it loads map tiles from the SD card. My understanding of the problem is that the code shows all the tiles for each zoom it finds and when no other zooms are found it still zooms in.

The API clearly specifies setting the max zoom level in the constructor of XYTileSource (final int aZoomMaxLevel):

public XYTileSource(final String aName, final string aResourceId, final int aZoomMinLevel,
                        final int aZoomMaxLevel, final int aTileSizePixels, final String aImageFilenameEnding,
                        final String... aBaseUrl)

Any workarounds? What am I doing wrong? How can I block the zoom so that the user can't go beyond level 4?


Solution

  • We found a workaround to set the maximum zoomlevel globally for the whole application.You have to change the value to your desired level in the file OpenStreetMapTileProviderConstants in the package org.osmdroid.tileprovider.constants in the osmdroid-android project. It´s not the proper way, but works quite fine for us! :)