I'm using OpenLayers to display a map in a web page. I am using tiles from CloudMade, but the same issues occur with the Mapnik tiles from OpenStreetMap.
I'm trying to restrict the map so that the user cannot zoom all the way out to world view -- I want them to stay at roughly a city level zoom at minimum.
I have tried using the minZoomLevel
/ maxZoomLevel
/ numZoomLevels
properties; only the maxZoomLevel
and numZoomLevels
properties seem to work, whereas the minZoomLevel
property seems to be completely ignored.
Is there another way to accomplish this?
I ended up with this solution as i could not figure out how to use zoomOffset in my setup.
I found the simplest way to restrict the maxZoom levels for a XYZ layer was to override the getNumZoomLevels method:
This pevents zooming beyond level 10 and also draws the zoomBar control correctly. This and a combination of the
zoomOffset
option should allow you to easily control min/max zoom without having to mess around with resolutions or subclasses.You could override the
isValidZoomLevel
function. Something like this (not tested):EDIT
Or you would need to override the available resolutions, see the example here: http://dev.openlayers.org/examples/zoomLevels.html
Defining resolutions doesn't solve the problem (even in v2.1) - I didn't find any pernament fix for this, so I made my own zoombar in JS - that's what I would recommend to anyone who encounters issues with zoombar using custom tiles.
I tried something like this and it works for me:
Now i use this in the "View":
And it works fine