Time for Action – using Min and Max resolution
Let's look at how to use the minResolution
and maxResolution
properties and how they affect our zoom levels.
Instantiate your map object, by specifying the the min/max resolution properties:
//Create a map with an empty array of controls map = new OpenLayers.Map('map_element', { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher() ], minResolution: 0.02197265625, maxResolution: 0.3515625 });
You should see something like this, with limited zoom levels:
Now, let's recreate the map element and set the
maxResolution
andnumZoomLevels
properties:map = new OpenLayers.Map('map_element', { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher() ], maxResolution: 0.3515625, numZoomLevels:8 });
The map should now show...