[OpenLayers-Users] Mutually exclusive layers

Derek Watling derek at cmainfo.co.za
Mon Feb 2 08:30:22 EST 2009


On my map I have 3 overlay layers, 2 of which need to be mutually exclusive,
ie. can't both be on at the same time.

I have be playing with the layer events and tried both "visibilitychanged"
and "loadstart". I am getting the same result with both of these in that the
event is triggered for each layer I have registered it on when the page
first loads, but when switching the layers on/off in the LayerSwitcher the
event isn't triggered.

My code looks like:

function init() {
...
    streetNumbers = new OpenLayers.Layer.WMS("Street Numbers",
"http://dev/Tilecache/tilecache.py?", { layers: "StreetNumbers", format:
"image/png"});
    streetNumbers.setZIndex(0);
    streetNumbers.setVisibility(false);
    streetNumbers.setIsBaseLayer(false);
    streetNumbers.displayOutsideMaxExtent = 0;
    streetNumbers.transitionEffect = "resize";
    map.addLayer(streetNumbers);

    erfNumbers = new OpenLayers.Layer.WMS("Erf Numbers",
"http://dev/Tilecache/tilecache.py?", {layers: "ErfNumbers", format:
"image/png"});
    erfNumbers.setZIndex(0);
    erfNumbers.setVisibility(false);
    erfNumbers.setIsBaseLayer(false);
    erfNumbers.displayOutsideMaxExtent = 0;
    erfNumbers.transitionEffect = "resize";
    map.addLayer(erfNumbers);
    
    zoneLabel = new OpenLayers.Layer.WMS("Zone",
"http://dev/Tilecache/tilecache.py?", {layers: "Zone", format:
"image/png"});
    zoneLabel.setZIndex(0);
    zoneLabel.setVisibility(false);
    zoneLabel.setIsBaseLayer(false);
    zoneLabel.displayOutsideMaxExtent = 0;
    zoneLabel.transitionEffect = "resize";
    map.addLayer(zoneLabel);

    streetNumbers.events.register('loadstart', null,
LayerChanged(streetNumbers));
    erfNumbers.events.register('loadstart', null, LayerChanged(erfNumbers));
...
}

function LayerChanged(Layer) {
    alert(Layer.name);
...
}

-- 
View this message in context: http://n2.nabble.com/Mutually-exclusive-layers-tp2257921p2257921.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list