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

Time for Action – creating a map with multiple layers


Let's create a map with two WMS layers. One layer will act as our base layer, and the other will be an overlay layer containing labels for country, state, and city names.

  1. Create a copy of the file you made for the last example of Chapter 1 and remove the existing WMS layer code (or, use the template from http://vasir.net/openlayers_book/). You can name it whatever you'd like, but we'll refer to it as chapter3_ex1_wms_layers.html. Make sure it is in the same directory as your OpenLayers.js file.

  2. First we're going to remove everything that was in the init() function. Your function should now look like this:

    function init() {
    }
    
  3. Next, inside the init() function, we're going to setup our map object like before:

    map = new OpenLayers.Map('map_element', {});
  4. Now we're going to create our first layer. We'll use a WMS layer and ask the WMS server for the layer 'basic' (a layer on the WMS service). We'll also explicitly set it to be a base layer.

      var...