[OpenLayers-Users] add/remove layers from layerswitcher

G. Allegri giohappy at gmail.com
Sat Nov 8 13:23:49 EST 2008


Hi.
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.

I have two layers:

    GMLcomuni = new OpenLayers.Layer.GML("GMLcomuni","IET2.gml",
{isBaseLayer:true,group:"base"});
    GMLsezioni = new OpenLayers.Layer.GML("GMLsezioni","IET2.gml",
{group:"base",maxResolution: 10,visibility:
false,displayInLayerSwitcher:false});

    map.addLayers([GMLcomuni,GMLsezioni]);
    layerswitch = new OpenLayers.Control.LayerSwitcher();
    map.addControl(layerswitch);
    map.events.register("zoomend",GMLsezioni, function(){
        if(map.resolution<10){
            this.setVisibility(true);
            //this.displayInLayerSwitcher=true;
        }
    });

The setVisibility() method triggers both the changelayer and the
visibilitychanged
events, but the layerswitcher seems to ignore them, leaving only the first
baselayer.
 (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 that
layerswitch.layerStates[1].visibility property before and after
setVisibility(),
and they change so I would expect the checkRedraw to return true!. I'm a bit
confused...

Any hint?

Giovanni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081108/e48a18bb/attachment.html


More information about the Users mailing list