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?
The resolution is the size of 1 pixel in map units. Let's say your map projection is EPSG:3857 whose unit is meters. For example if the current resolution is 20000 m/px, this means that 1 px represents 20000m.
A zoom level or scale is a number that defines how large or small the contents of a map appear in a map view . Scale is a ratio between measurements on a map view and measurements in the real-world.
You could override the isValidZoomLevel
function. Something like this (not tested):
OpenLayers.Map.isValidZoomLevel = function(zoomLevel) { return ( (zoomLevel != null) && (zoomLevel >= 2) && // set min level here, could read from property (zoomLevel < this.getNumZoomLevels()) ); }
EDIT
Or you would need to override the available resolutions, see the example here: http://dev.openlayers.org/examples/zoomLevels.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With