O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for Action – Using scales

Using scales is another way we can control the zoom levels on our map. Let's take a look.

  1. Create your map object using minScale and maxScale 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
    });
  2. You should see something like this:
    Time for Action – Using scales
  3. 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(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required