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 different projection codes


Let's create a basic map using a different projection.

  1. Using the template code, recreate your map object the following way. We'll be specifying the projection property, along with the maxExtent, maxResolution, and units properties. If we use a projection other than the default projection, we need to tell OpenLayers the type of coordinates to use, and setting the maxExtent is one way to do this. The projection we're going to use is EPSG:900913, a projection used by Google Maps and other third party APIs.

    map = new OpenLayers.Map('map_element', {
     projection: 'EPSG:900913',
      maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
        20037508, 20037508.34),
      maxResolution: 156543.0339,
      units: 'm'
    });
  2. Save the file, we'll refer to it as chapter4_ex1.html.

  3. You should see something like the following:

What Just Happened?

We just created a map with the projection EPSG:900913. You'll notice that it looks quite a bit different than the maps we've...