Creating layer objects
The process to work with layers consists of two steps:
Create the layer object.
Add the layer object to the map. You can use either
map.addLayer(layer)
to add an individual layer, ormap.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...