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.
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 yourOpenLayers.js
file.First we're going to remove everything that was in the
init()
function. Your function should now look like this:function init() { }
Next, inside the
init()
function, we're going to setup our map object like before:map = new OpenLayers.Map('map_element', {});
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...