Time for Action – defining a global layer object variable
Let's make the layer objects global variables access some properties of a layer, and call one of the layer's methods.
Make a copy of
chapter3_ex2_options_config.html
. Add the following lines right above theinit()
function:var wms_layer_map, wms_state_lines, wms_labels, wms_water_depth, wms_roads;
Inside your
init()
function, remove thevar
declaration before each of the layer object names. For example, the first line of yourwms_layer_map
definition should now look like this:wms_layer_map = new OpenLayers.Layer.WMS(
Save the file (we'll refer to it as
chapter3_ex5_global_variables.html
).Open it up in Firefox and enable the Firebug console.
In the console panel, input and run:
wms_layer_map;
. You should see some output like this:Object { options=Object, more... }
Input and run the following command in Firebug:
wms_layer_map.name
Here we are directly accessing a property of the layer. You should see the layer's
name
property output:Base...