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 class="code-string">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 class="code-string"> 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>