[OpenLayers-Users] Dependent layers in overlay of LayerSwitcher
Arnd Wippermann
arnd.wippermann at web.de
Sat Oct 11 08:46:20 EDT 2008
Register the event "changelayer"
* - *changelayer* triggered after a layer name change, order change,
or
* visibility change (due to resolution thresholds). Listeners
will
* receive an event object with *layer* and *property* properties.
The
* *layer* property will be a reference to the changed layer. The
* *property* property will be a key to the changed property (name,
* visibility, or order).
And use something like this:
map.events.register("changelayer", map, function (e) {
if(e.layer.name==map.layers[1].name)
{
map.layers[4].setVisibility(e.layer.visibility);
}
else if(e.layer.name==map.layers[2].name)
{
map.layers[5].setVisibility(e.layer.visibility);
}
else if(e.layer.name==map.layers[3].name)
{
map.layers[6].setVisibility(e.layer.visibility);
}
});
Or
map.events.register("changelayer", map, function (e) {
for(var i=1;i<4;i++)
if(e.layer.name==map.layers[i].name)
map.layers[i+3].setVisibility(e.layer.visibility);
});
You don't need to modify the layerswitcher.
Arnd Wippermann
-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von S.Reena
Gesendet: Samstag, 11. Oktober 2008 10:19
An: users at openlayers.org
Betreff: [OpenLayers-Users] Dependent layers in overlay of LayerSwitcher
Hi,
I have made Overlay so that it consists on 7 layers..last three not being
shown in LayerSwitcher. I want that if I uncheck layer 2...layer 5 shud also
disappear from map same for layers (3,6) and (4,7). I modified the
LayerSwitcher like this:
updateMap: function() {
// set the newly selected base layer
for(var i=0; i < this.baseLayers.length; i++) {
var layerEntry = this.baseLayers[i];
if (layerEntry.inputElem.checked) {
this.map.setBaseLayer(layerEntry.layer, false);
}
}
// set the correct visibilities for the overlays
for(var i=0; i < this.dataLayers.length; i++) {
// alert(i);
var layerEntry = this.dataLayers[i];
layerEntry.layer.setVisibility(layerEntry.inputElem.checked);
// Added By Reena
if((i==1)&& (layerEntry.layer.visibility==false))
{
var layerEntry1 = this.dataLayers[5];
layerEntry1.layer.setVisibility(false);
}
if((i==2)&& (layerEntry.layer.visibility==false))
{
var layerEntry1 = this.dataLayers[6];
layerEntry1.layer.setVisibility(false);
}
if ((i==3)&& (layerEntry.layer.visibility==false))
{
var layerEntry1 = this.dataLayers[7];
layerEntry1.layer.setVisibility(false);
}
}
},
..................
The problem is that if I dont show the last three layers in LayerSwitcher
...its not working ...but if I do then it is....the value of 'i' is not
incrementing till the last layer but to the displayed layer only.
The layers I have made is like this
--------------------------------------
wms[5] = new OpenLayers.Layer.WMS.Untiled(
"
label","http://gis.rtbi-iitm.in/cgi-bin/mapserv?map=/var/www/html/v1/mapfile
/dist_label.map",
{'layers':
"TN_District",'transparent':"true"},{'displayInLayerSwitcher':true},{'isBase
Layer':false});
wms[6] = new OpenLayers.Layer.WMS.Untiled(
"
label","http://gis.rtbi-iitm.in/cgi-bin/mapserv?map=/var/www/html/v1/mapfile
/taluk_label.map",
{'layers':
"Tnd_Taluk",'transparent':"true"},{'displayInLayerSwitcher':true},{'isBaseLa
yer':false});
wms[7] = new OpenLayers.Layer.WMS.Untiled(
"
label","http://gis.rtbi-iitm.in/cgi-bin/mapserv?map=/var/www/html/v1/mapfile
/vill_label.map",
{'layers':"Tnd_Village",'transparent':"true"},{'displayInLayerSwitcher':true
},{'isBaseLayer':false});
-------------------------------------------
Can any1 help?
Cheers,
Reena.
--
View this message in context:
http://www.nabble.com/Dependent-layers-in-overlay-of-LayerSwitcher-tp1993061
6p19930616.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users
More information about the Users
mailing list