Geoportal Extension for OpenLayers API Reference

Class: LayerSwitcher

ol.control.LayerSwitcher

OpenLayers Control to manage map layers : their order, visibility and opacity, and display their informations (title, description, legends, metadata...)

new LayerSwitcher(lsOptions)

OpenLayers/Controls/LayerSwitcher.js, line 45
Name Type Description
lsOptions Object

control options

Name Type Description
layers Array optional

list of layers to be configured. Each array element is an object, with following properties :

Name Type Description
layer ol.layer.Layer optional

ol.layer.Layer layer to be configured (that has been added to map)

config Object optional

custom configuration object for layer information (title, description, legends, metadata, quicklook url), with following properties :

Name Type Description
title String optional

layer alias, to be displayed in widget layer list. E.g. : "Cartes IGN"

description String optional

layer description, to be displayed on title hover, or in layer information panel.

quicklookUrl String optional

link to a quick look image for this layer.

legends Array optional

array of layer legends. Each array element is an object, with following properties :

 - url (String, mandatory) : link to a legend
 - minScaleDenominator (Number, optional) : min scale denominator for legend validity.
metadata Array optional

array of layer metadata. Each array element is an object, with property url (String, mandatory) : link to a metadata

options Object optional

ol.control.Control options (see ol.control.Control)

Name Type Description
collapsed Boolean optional

Specify if widget has to be collapsed (true) or not (false) on map loading. Default is true.

Example
map.addControl(new ol.control.LayerSwitcher(
 [
     {
         layer : wms1,
         config : {
             title : "test layer name 1",
             description : "test layer desc 1",
         }
     }
 ],
 {
     collapsed : true
 }
));

Extends

  • ol.control.Control

Members

collapsed

{Boolean} true if widget is collapsed, false otherwise

Methods

addLayer(layer, config)

OpenLayers/Controls/LayerSwitcher.js, line 190

Add a new layer to control (when added to map) or add new layer configuration

Name Type Description
layer ol.layer.Layer

layer to add to layer switcher

config Object optional

additional options for layer configuration

Name Type Description
title Object optional

layer title (default is layer identifier)

description Object optional

layer description (default is null)

legends Object optional

layer legends (default is an empty array)

metadata Object optional

layer metadata (default is an empty array)

quicklookUrl Object optional

layer quicklookUrl (default is null)

Example
layerSwitcher.addLayer(
      gpParcels,
      {
          title : "Parcelles cadastrales",
          description : "description de la couche",
          quicklookUrl : "http://quicklookUrl.fr"
      }
  )

getCollapsed(){Boolean}

OpenLayers/Controls/LayerSwitcher.js, line 405

Returns true if widget is collapsed (minimize), false otherwise

Returns:
collapsed

getLayerDOMId(olLayer){String}

OpenLayers/Controls/LayerSwitcher.js, line 1044

Returns Layer Container Id associated with given olLayer

Name Type Description
olLayer ol.layer.Layer

ol layer object

Returns:
container Id ; null if layer not found.

removeLayer(layer)

OpenLayers/Controls/LayerSwitcher.js, line 325

Remove a layer from control

Name Type Description
layer ol.layer.Layer

layer.

Deprecated
  • on the future version ...

    setCollapsed(collapsed)

    OpenLayers/Controls/LayerSwitcher.js, line 381

    Collapse or display control main container

    Name Type Description
    collapsed Boolean

    True to collapse control, False to display it

    setMap(map)

    OpenLayers/Controls/LayerSwitcher.js, line 101

    Overload setMap function, that enables to catch map events, such as movend events.

    Name Type Description
    map ol.Map

    Map.

    setRemovable(layer, removable)

    OpenLayers/Controls/LayerSwitcher.js, line 415

    Display or hide removeLayerPicto from layerSwitcher for this layer

    Name Type Description
    layer ol.layer.Layer

    ol.layer to be configured

    removable Boolean

    specify if layer can be remove from layerSwitcher (true) or not (false). Default is true