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 resolutions array


Setting the resolutions array is one way to specify the number of zoom levels. Let's see it in action.

  1. In the map object definition specify the resolution array as the following:

    map = new OpenLayers.Map('map_element', {
      resolutions: [ 1.40625,0.703125, 0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125 ]
    });
  2. Zoom around on the map. Because we've only provided five possible resolutions, you should be able to zoom in five times.

What Just Happened?

Using the resolutions array, we were able to specify the number of zoom levels. Unless we're using a cached tile service, this isn't necessarily the easiest way to specify the number of zoom levels. We have mentioned earlier we can also use scales, and we can also use minResolution and maxResolution.

Map/Layer property inheritance

Resolutions/scales/max extent etc. properties can be specified in the map object or layer objects. Preferably, they should be specified in the map, as you won't have to worry...