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

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',
  {layers: 'basic'},
  {isBaseLayer: true}
);

Each item inside the parentheses, after OpenLayers.Layer.WMS(, are called arguments which we pass in while creating the object. But how did I know what arguments to pass in?

We...