O'Reilly logo

OpenLayers 3 : Beginner's Guide by Erik Hazzard, Paul Spencer, Thomas Gratier

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 a Stamen layer

Follow these steps to create a Stamen layer:

  1. We can access the Stamen layer from the outside of the box. This will be pretty simple. First, we just need to create a layer object:
      var stamenLayer = new ol.layer.Tile({
        source: new ol.source.Stamen({
          layer: 'toner'
        })
      });
  2. Then, we just construct the map directly, adding the view and the layer already configured at startup:
      var map = new ol.Map({

        layers: [stamenLayer],
        target: 'map',
        view: new ol.View({
         center: ol.proj.transform([2.35239, 48.858391], 'EPSG:4326', 'EPSG:3857'),
          zoom: 12
        })
      });
  3. You should see something like the following screenshot:
    Time for action – creating a Stamen layer

What just happened? ...

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