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:
@@ -28,14 +28,17 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
/** @type String */
|
/** @type String */
|
||||||
nonActiveColor: "",
|
nonActiveColor: "",
|
||||||
|
|
||||||
|
/** @type String */
|
||||||
|
mode: "checkbox",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
initialize: function() {
|
initialize: function(options) {
|
||||||
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
|
||||||
this.activeColor = OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
this.activeColor = OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR;
|
||||||
this.nonActiveColor = OpenLayers.Control.LayerSwitcher.NONACTIVE_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
|
//clear out previous incarnation of LayerSwitcher tabs
|
||||||
this.div.innerHTML = "";
|
this.div.innerHTML = "";
|
||||||
|
var visible = false;
|
||||||
for( var i = 0; i < this.map.layers.length; i++) {
|
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]);
|
this.addTab(this.map.layers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.div;
|
return this.div;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -84,10 +93,19 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
singleClick: function(evt) {
|
singleClick: function(evt) {
|
||||||
var div = Event.element(evt);
|
var div = Event.element(evt);
|
||||||
var layer = div.layer;
|
var layer = div.layer;
|
||||||
|
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();
|
var visible = layer.getVisibility();
|
||||||
|
|
||||||
this.setTabActivation(div, !visible);
|
this.setTabActivation(div, !visible);
|
||||||
layer.setVisibility(!visible);
|
layer.setVisibility(!visible);
|
||||||
|
}
|
||||||
Event.stop(evt);
|
Event.stop(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -132,6 +150,8 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
|||||||
// add label to div
|
// add label to div
|
||||||
backdropLabelOuter.appendChild(backdropLabel);
|
backdropLabelOuter.appendChild(backdropLabel);
|
||||||
|
|
||||||
|
this.backdrops.append(backdropLabel);
|
||||||
|
|
||||||
// add div to main LayerSwitcher Div
|
// add div to main LayerSwitcher Div
|
||||||
this.div.appendChild(backdropLabelOuter);
|
this.div.appendChild(backdropLabelOuter);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user