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

Creating layer objects

The process to work with layers consists of two steps:

  1. Create the layer object.
  2. Add the layer object to the map. You can use either map.addLayer(layer) to add an individual layer, or map.addLayers([layer1, layer2, ...]) to add an array of layers, like in the previous example.

These two steps can actually be combined into one step (by instantiating the layer object when calling the addLayer function—this works, but I don't recommend it as it makes it a little harder to work with the layer object). By now, we have a bit of experience instantiating objects from the WMS Layer class. Let's take a look at the code that creates our wms_base layer object.

var wms_layer_map = new OpenLayers.Layer.WMS( 'Base layer', 'http://vmap0.tiles.osgeo.org/wms/vmap0', ...

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