Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • OpenLayers 2.10 Beginner's Guide
  • Toc
  • feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)

Overview of this book

Table of Contents (18 chapters)
close
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...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete