I've solved it. I needed to put this.displayInLayerSwitcher=true before setVisibility(), as the layerswitch redraw chain checks that property and it isn't set by the setVisibility() method (and that's right!).<br>
<br>Bye<br><br><div class="gmail_quote">2008/11/8 G. Allegri <span dir="ltr"><<a href="mailto:giohappy@gmail.com">giohappy@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi.<br>I know this is an old question, but I can't figure out why the usual method to add/remove layers from LayerSwitch on the base of zoom doesn't work for me.<br><br>I have two layers:<br><br> GMLcomuni = new OpenLayers.Layer.GML("GMLcomuni","IET2.gml", {isBaseLayer:true,group:"base"});<br>
GMLsezioni = new OpenLayers.Layer.GML("GMLsezioni","IET2.gml", {group:"base",maxResolution: 10,visibility: false,displayInLayerSwitcher:false});<br> <br> map.addLayers([GMLcomuni,GMLsezioni]);<br>
layerswitch = new OpenLayers.Control.LayerSwitcher();<br> map.addControl(layerswitch);<br> map.events.register("zoomend",GMLsezioni, function(){<br> if(map.resolution<10){<br> this.setVisibility(true);<br>
//this.displayInLayerSwitcher=true;<br> }<br> });<br><br>The setVisibility() method triggers both the changelayer and the <span>visibilitychanged events, but the layerswitcher seems to ignore them, leaving only the first baselayer.<br>
</span> (and the layer get drawn on the map), but the layerswitcher control doesn't react. Debuggin with FB I've seen that the layerswitcher.checkRedraw() method returns false, so the redraw() returns nothin, but I've checked<span> that layerswitch.layerStates[1].visibility property before and after </span>setVisibility(), and they change so I would expect the checkRedraw to return true!. I'm a bit confused...<br>
<br>Any hint?<br><br>Giovanni<br>
</blockquote></div><br>