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 – creating an OpenStreetMap Layer

  1. For the OpenStreetMap layer, we do not need to include a script; we can access it outside of the box.
  2. This will be pretty simple. We just need to create an OSM layer object:
    var osm_layer = new OpenLayers.Layer.OSM( 
        'OpenStreetMap Layer' 
    );
  3. Then, we just add the layer object to the map. Even though we're only passing in one layer object, we'll use the addLayers function to keep our code consistent:
    map.addLayers([osm_layer]);
  4. You should see something like this:
    Time for Action – creating an OpenStreetMap Layer

What Just Happened?

The map we just created is showing an OpenStreetMap layer. Unlike the previous layers, we did not have to provide an API key ...

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