Time for Action – Using scales
Using scales is another way we can control the zoom levels on our map. Let's take a look.
Create your map object using
minScale
andmaxScale
as follows:map = new OpenLayers.Map('map_element', { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher() ], maxScale: 27683990.15625, minScale: 221471921.25 });
You should see something like this:
Now, let's go back to the code and recreate our map object. This time, we'll pass in a scales array.
//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() ], scales: [ 55367980.3125, 27683990.15625, 13841995.078125, 6920997.5390625], });
You should see something like this:
What Just Happened?
We just used scales to...