/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Control/LayerSwitcher.js */ /** * Class: 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.LayerSwitcher = OpenLayers.Class(OpenLayers.Control.LayerSwitcher, { // DOM Elements /** * Property: routeLayersDiv * {DOMElement} */ routeLayersDiv: null, /** * Property: routeLayers * {Array()} */ routeLayers: [], /** * Property: routeHierarchy * {Object()} */ routeHierarchy: null, /** * Method: redraw * 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 */ redraw: function() { //if the state hasn't changed since last redraw, no need // to do anything. Just return the existing div. if (!this.checkRedraw()) { return this.div; } //clear out previous layers this.clearLayersArray("base"); this.clearLayersArray("data"); this.clearLayersArray("route"); var containsOverlays = false; var containsBaseLayers = false; // Save state -- for checking layer if the map state changed. // We save this before redrawing, because in the process of redrawing // we will trigger more visibility changes, and we want to not redraw // and enter an infinite loop. var len = this.map.layers.length; this.layerStates = new Array(len); for (var i = 0; i < len; i++) { var layer = this.map.layers[i]; this.layerStates[i] = { 'name': layer.name, 'visibility': layer.visibility, 'inRange': layer.inRange, 'id': layer.id }; } var layers = this.map.layers.slice(); if (!this.ascending) { layers.reverse(); } for(var i=0, len=layers.length; i