Book Image

OpenLayers 2.10 Beginner's Guide

Book Image

OpenLayers 2.10 Beginner's Guide

Overview of this book

Table of Contents (18 chapters)
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  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(), 
            new OpenLayers.Control.PanZoomBar(), 
            new OpenLayers.Control.LayerSwitcher() 
        ], 
        scales: [ 55367980.3125, 27683990.15625, 13841995.078125, 6920997.5390625],
    });
  4. You should see something like this:

What Just Happened?

We just used scales to...