Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Min/max zoom level in OpenLayers

Tags:

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?

like image 941
David Pfeffer Avatar asked Nov 21 '10 21:11

David Pfeffer


People also ask

What is Openlayer resolution?

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.

What does zoom level mean?

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.


1 Answers

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

like image 112
Jonathan Avatar answered Oct 14 '22 19:10

Jonathan