Layer object ************ OpenLayers supports `number of layer types `_, among others **OGC WMS** **MapServer** **Image** for the raster layers **OGC WFS** **GeoRSS** **KML** **GML** for the vector layers **Google** **VirtualEarth** **YahooMaps** for commercial "free" public mapping applications (all together they are more then 30 layer types). Let us have a look on some layer types more closer: OpenLayers.Layer ================ `OpenLayers.Layer `_ is parent class for all layer classes. You will probably never work with this base layer class, but it has some important attributes and methods, which is good to know: **isBaseLayer** -- indicates, whether the layer is **base layer** or not **displayInLayerSwitcher** -- indicates, whether the layer is to be displayed in the layerswitcher **visibility** -- indicates, whether the layer is visible or not **units, scales, resolutions, projection, min- max- Scale, Resolution, Extent** **transtionEffect** -- transition effect to use when the map is panned or zoomed. **redraw** (force) -- redraw the layer **getVisibility, setVisibility** -- self explaining **calculateInRange** () -- should the layer be displayed in this zoom scale or not **setOpacity** (Float) -- set layer opacity OpenLayers.Layer.WMS ==================== `OpenLayers.Layer.WMS `_ is interface to `OGC Web Mapping Service `_. It is relatively simple to `initialize `_ such layer type: Let's have a look at some parameters (they are located in parent class `OpenLayers.Layer.Grid `_): **singleTile** -- to tile or not to tile, that is a question ... **ratio** -- how big should the buffer be, if singleTile is true **buffer** -- how big should the buffer be, if singleTile is false (default) .. code-block:: javascript var layer = new OpenLayers.Layer.WMS("Layer Name", "http://foo/bar/wms",{layers:"foo"}); Or more complex way: .. code-block:: javascript var layer = new OpenLayers.Layer.WMS("Layer Name", "http://foo/bar/wms", { // here comes WMS parameters layers: "foo,bar", format: "image/png", style:"default" }, { // here comes OpenLayers.Layer.WMS parameters isBaseLayer: false, visibility: true, singleTile: true, ratio: 1, minResolution: 0.5 } ); Add the end (and same applies for other layer types), add the layer to map: .. code-block:: javascript map.addLayer(layer) or, if there are more .. code-block:: javascript map.addLayers([layer1,layer2,...]) Vector layer ============ Basic class for all vector-type layers (`WFS `_, `GML `_, ...) is `OpenLayers.Layer.Vector `_. WMS or GML are initialized in the `similar way `_ as the WMS layer is. Initialize OpenLayers.Layer.Vector is simple: .. code-block:: javascript var vlayer = new OpenLayers.Layer.Vector("Vector layer Name"); Vector layers do have several interesting `attributes `_: **features** -- list of features in the vector layer **style** -- style describing the graphical representation of the layer and `methods `_: **addFeatures** ([OpenLayers.Feature]) -- add features to the map **drawFeature** (OpenLayers.Feature, OpenLayers.Style) -- draw feature with specified style **onFeatureInsert, preFeatureInsert** -- empty methods called on specified events, which can be redefined by the user The vector layer is used for displaying the vector features in the map canvas. They are use for other tools, like editing, area and length measurements. Example: add layers to map ========================== Create new map and add several layers, see `02_layers.html <../_static/02_layers.html>`_. .. literalinclude:: ../_static/02_layers.html :language: html :linenos: :lines: 1-5,40-47 Add map .. literalinclude:: ../_static/02_layers.html :language: javascript :linenos: :lines: 9-15 Create and add WMS layer and vector layer .. literalinclude:: ../_static/02_layers.html :language: javascript :linenos: :lines: 17-26 Set map center .. literalinclude:: ../_static/02_layers.html :language: javascript :linenos: :lines: 28-30 Create vector feature, add to vector layer .. literalinclude:: ../_static/02_layers.html :language: javascript :linenos: :lines: 33-38 All together: .. literalinclude:: ../_static/02_layers.html :language: javascript :linenos: :lines: 7-39