Commiting fix for #716, "Make LayerSwitcher support displayInLayerSwitcher
for Base Layers", reviewed by Erik, tested by tschaub. git-svn-id: http://svn.openlayers.org/trunk/openlayers@3853 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -185,6 +185,7 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.clearLayersArray("data");
|
||||
|
||||
var containsOverlays = false;
|
||||
var containsBaseLayers = false;
|
||||
|
||||
var layers = this.map.layers.slice();
|
||||
if (!this.ascending) { layers.reverse(); }
|
||||
@@ -192,11 +193,13 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, {
|
||||
var layer = layers[i];
|
||||
var baseLayer = layer.isBaseLayer;
|
||||
|
||||
if (baseLayer || layer.displayInLayerSwitcher) {
|
||||
if (layer.displayInLayerSwitcher) {
|
||||
|
||||
if (!baseLayer) {
|
||||
if (baseLayer) {
|
||||
containsBaseLayers = true;
|
||||
} else {
|
||||
containsOverlays = true;
|
||||
}
|
||||
}
|
||||
|
||||
// only check a baselayer if it is *the* baselayer, check data
|
||||
// layers if they are visible
|
||||
@@ -256,6 +259,9 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
// if no overlays, dont display the overlay label
|
||||
this.dataLbl.style.display = (containsOverlays) ? "" : "none";
|
||||
|
||||
// if no baselayers, dont display the baselayer label
|
||||
this.baseLbl.style.display = (containsBaseLayers) ? "" : "none";
|
||||
|
||||
return this.div;
|
||||
},
|
||||
@@ -426,11 +432,11 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.layersDiv.style.height = "100%";
|
||||
|
||||
|
||||
var baseLbl = document.createElement("div");
|
||||
baseLbl.innerHTML = "<u>Base Layer</u>";
|
||||
baseLbl.style.marginTop = "3px";
|
||||
baseLbl.style.marginLeft = "3px";
|
||||
baseLbl.style.marginBottom = "3px";
|
||||
this.baseLbl = document.createElement("div");
|
||||
this.baseLbl.innerHTML = "<u>Base Layer</u>";
|
||||
this.baseLbl.style.marginTop = "3px";
|
||||
this.baseLbl.style.marginLeft = "3px";
|
||||
this.baseLbl.style.marginBottom = "3px";
|
||||
|
||||
this.baseLayersDiv = document.createElement("div");
|
||||
this.baseLayersDiv.style.paddingLeft = "10px";
|
||||
@@ -449,14 +455,14 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.dataLayersDiv.style.paddingLeft = "10px";
|
||||
|
||||
if (this.ascending) {
|
||||
this.layersDiv.appendChild(baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLayersDiv);
|
||||
this.layersDiv.appendChild(this.dataLbl);
|
||||
this.layersDiv.appendChild(this.dataLayersDiv);
|
||||
} else {
|
||||
this.layersDiv.appendChild(this.dataLbl);
|
||||
this.layersDiv.appendChild(this.dataLayersDiv);
|
||||
this.layersDiv.appendChild(baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLayersDiv);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user