1

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?

Community
  • 1
  • 1
Igor Popov
  • 9,795
  • 7
  • 55
  • 68
  • even i m following osmdroid, let me knw if u get a workaround , probably it has got smthn to do wit zoom controls when v use mapview.setBuiltinZoomControls().. – Pratik Bhat Jan 03 '12 at 17:51

3 Answers3

10

The MapView class defines the public function getMaxZoomLevel(). A trivial extension of MapView will let you override that function to return whatever you want without having to recompile the osmdroid source into a JAR:

public class ZoomLimitMapView extends MapView
{
    /* snip the constructors */

    @Override
    public int getMaxZoomLevel()
    {
        return 4;
    }
}

You don't need a minimum zoom level, but if you did, getMinZoomLevel() is also public and could be overridden. And obviously using the constant literal 4 is probably a bad idea; better to load dynamically from SharedPreferences unless you know your imagery will never, ever change.

jatowler
  • 101
  • 1
  • 3
  • This works perfectly. I think this should be the accepted answer. Just remember that you need to change to the overloaded class in your layout files as well. – Einar Sundgren Nov 21 '13 at 00:06
3

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! :)

Dominik
  • 98
  • 1
  • 7
  • this means I need to add the osmdroid project as a library project (ie. not as a jar file), don't I? Can you please detail a bit the process, so I can accept the answer? – Igor Popov Jan 05 '12 at 19:36
  • At the moment our project has a dependency to osmdroid-android. If you want to implement this project as a jar, I suggest you have to change it and afterwards export it as a new jar. – Dominik Jan 06 '12 at 08:20
  • Beware of doing this since OSMDroid is LGPL. If you change the source and publish that you are obliged to publish under LGPL and include the changed source. – Einar Sundgren Nov 20 '13 at 23:49
1

You can find detailed intruction how to build the jar here here

Changing MAXIMUM_ZOOMLEVEL in both org.osmdroid.views.util.constants.MapViewConstants and org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants should do the job.

Get the osmdroid source from SVN http://osmdroid.googlecode.com/svn/branches/release_3_0_5 I recomend this version cause it will be easier to eventualy apply the scroll limit patch beside the zoom limit.

andrejc
  • 480
  • 4
  • 6