O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required