Implement radio button support in LayerSwitcher. Pass in {mode:'radio'} to constructor to switch away from checkbox mode, which is default. This allows us to complete the original part of #32, although we do not yet support the concept of 'base layers' described in that ticket, which has been split to #62.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@361 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-25 15:29:53 +00:00
parent 4c684565ef
commit 44454ba193

View File

@@ -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);