# OpenLayers.Control.LayerSwitcher

The LayerSwitcher control displays a table of contents for the map. This allows the user interface to switch between BaseLasyers and to show or hide Overlays. By default the switcher is shown minimized on the right edge of the map, the user may expand it by clicking on the handle.

To create the LayerSwitcher outside of the map, pass the Id of a html div as the first argument to the constructor.

#### Inherits from

- OpenLayers.Control

Summary

OpenLayers.Control.LayerSwitcher | The LayerSwitcher control displays a table of contents for the map.
Properties |
roundedCorner | {Boolean} If true the Rico library is used for rounding the corners of the layer switcher div, defaults to false.
roundedCornerColor | {String} The color of the rounded corners, only applies if roundedCorner is true, defaults to “darkblue”.
layerStates | {Array(Object)} Basically a copy of the “state” of the map’s layers the last time the control was drawn.
layersDiv | {DOMElement}
baseLayersDiv | {DOMElement}
baseLayers | {Array(Object)}
dataLbl | {DOMElement}
dataLayersDiv | {DOMElement}
dataLayers | {Array(Object)}
minimizeDiv | {DOMElement}
maximizeDiv | {DOMElement}
ascending | {Boolean}
Constructor |
OpenLayers.Control.LayerSwitcher |
Functions |
destroy |
setMap |
draw | {DOMElement} A reference to the DIV DOMElement containing the switcher tabs.
onButtonClick |
clearLayersArray | User specifies either “base” or “data”.
checkRedraw | Checks if the layer state has changed since the last redraw() call.
redraw | Goes through and takes the current state of the Map and rebuilds the control to display that state.
updateMap | Cycles through the loaded data and base layer input arrays and makes the necessary calls to the Map object such that that the map’s visual state corresponds to what the user has selected in the control.
maximizeControl | Set up the labels and divs for the control
minimizeControl | Hide all the contents of the control, shrink the size, add the maximize icon
showControls | Hide/Show all LayerSwitcher controls depending on whether we are minimized or not
loadContents | Set up the labels and divs for the control

### Properties

### roundedCorner

{Boolean} If true the Rico library is used for rounding the corners of the layer switcher div, defaults to false. Deprecated. Use CSS3’s border-radius instead. If this option is set to true the Rico/Corner.js script must be loaded in the page, and therefore listed in the build profile.

### roundedCornerColor

{String} The color of the rounded corners, only applies if roundedCorner is true, defaults to “darkblue”.

### layerStates

{Array(Object)} Basically a copy of the “state” of the map’s layers the last time the control was drawn. We have this in order to avoid unnecessarily redrawing the control.

### layersDiv

{DOMElement}

### baseLayersDiv

{DOMElement}

### baseLayers

{Array(Object)}

### dataLbl

{DOMElement}

### dataLayersDiv

{DOMElement}

### dataLayers

{Array(Object)}

### minimizeDiv

{DOMElement}

### maximizeDiv

{DOMElement}

### ascending

{Boolean}

### Constructor

### OpenLayers.Control.LayerSwitcher

#### Parameters

options | {Object}

### Functions

### destroy

> destroy: function()

### setMap

> setMap: function( | map | )

#### Properties

map | {OpenLayers.Map}

### draw

> draw: function()

#### Returns

{DOMElement} A reference to the DIV DOMElement containing the switcher tabs.

### onButtonClick

> onButtonClick: function( | evt | )

#### Parameters

evt | {Event}

### clearLayersArray

> clearLayersArray: function( | layersType | )

User specifies either “base” or “data”. we then clear all the corresponding listeners, the div, and reinitialize a new array.

#### Parameters

layersType | {String}

### checkRedraw

> checkRedraw: function()

Checks if the layer state has changed since the last redraw() call.

#### Returns

{Boolean} The layer state changed since the last redraw() call.

### redraw

> redraw: function()

Goes through and takes the current state of the Map and rebuilds the control to display that state. Groups base layers into a radio-button group and lists each data layer with a checkbox.

#### Returns

{DOMElement} A reference to the DIV DOMElement containing the control

### updateMap

> updateMap: function()

Cycles through the loaded data and base layer input arrays and makes the necessary calls to the Map object such that that the map’s visual state corresponds to what the user has selected in the control.

### maximizeControl

> maximizeControl: function( | e | )

Set up the labels and divs for the control

#### Parameters

e | {Event}

### minimizeControl

> minimizeControl: function( | e | )

Hide all the contents of the control, shrink the size, add the maximize icon

#### Parameters

e | {Event}

### showControls

> showControls: function( | minimize | )

Hide/Show all LayerSwitcher controls depending on whether we are minimized or not

#### Parameters

minimize | {Boolean}

### loadContents

> loadContents: function()

Set up the labels and divs for the control

> destroy: function()

> setMap: function( | map | )

> draw: function()

{DOMElement} A reference to the DIV DOMElement containing the switcher tabs.

> onButtonClick: function( | evt | )

> clearLayersArray: function( | layersType | )

User specifies either “base” or “data”.

> checkRedraw: function()

Checks if the layer state has changed since the last redraw() call.

> redraw: function()

Goes through and takes the current state of the Map and rebuilds the control to display that state.

> updateMap: function()

Cycles through the loaded data and base layer input arrays and makes the necessary calls to the Map object such that that the map’s visual state corresponds to what the user has selected in the control.

> maximizeControl: function( | e | )

Set up the labels and divs for the control

> minimizeControl: function( | e | )

Hide all the contents of the control, shrink the size, add the maximize icon

> showControls: function( | minimize | )

Hide/Show all LayerSwitcher controls depending on whether we are minimized or not

> loadContents: function()

Set up the labels and divs for the control
Controls affect the display or behavior of the map.
Instances of OpenLayers.Map are interactive maps embedded in a web page.
Close