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 Min and Max resolution


Let's look at how to use the minResolution and maxResolution properties and how they affect our zoom levels.

  1. 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 
    });
  2. You should see something like this, with limited zoom levels:

  3. Now, let's recreate the map element and set the maxResolution and numZoomLevels 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 
    });
  4. The map should now show...