diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index 05e78543c9..671f21127f 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -28,14 +28,17 @@ OpenLayers.Control.LayerSwitcher.prototype = /** @type String */ nonActiveColor: "", + /** @type String */ + mode: "checkbox", /** * @constructor */ - initialize: function() { - OpenLayers.Control.prototype.initialize.apply(this, arguments); + initialize: function(options) { this.activeColor = OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; this.nonActiveColor = OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; + this.backdrops = []; + OpenLayers.Control.prototype.initialize.apply(this, arguments); }, /** @@ -71,10 +74,16 @@ OpenLayers.Control.LayerSwitcher.prototype = //clear out previous incarnation of LayerSwitcher tabs this.div.innerHTML = ""; - + var visible = false; for( var i = 0; i < this.map.layers.length; i++) { + if (visible && this.mode == "radio") { + this.map.layers[i].setVisibility(false); + } else { + visible = this.map.layers[i].getVisibility(); + } this.addTab(this.map.layers[i]); } + return this.div; }, @@ -84,10 +93,19 @@ OpenLayers.Control.LayerSwitcher.prototype = singleClick: function(evt) { var div = Event.element(evt); var layer = div.layer; - var visible = layer.getVisibility(); - - this.setTabActivation(div, !visible); - layer.setVisibility(!visible); + if (this.mode == "radio") { + for(var i=0; i < this.backdrops.length; i++) { + this.setTabActivation(this.backdrops[i], false); + this.backdrops[i].layer.setVisibility(false); + } + this.setTabActivation(div, true); + layer.setVisibility(true); + } else { + var visible = layer.getVisibility(); + + this.setTabActivation(div, !visible); + layer.setVisibility(!visible); + } Event.stop(evt); }, @@ -132,6 +150,8 @@ OpenLayers.Control.LayerSwitcher.prototype = // add label to div backdropLabelOuter.appendChild(backdropLabel); + this.backdrops.append(backdropLabel); + // add div to main LayerSwitcher Div this.div.appendChild(backdropLabelOuter);