[fusion-users] legend.js layer-group show

Paul Spencer pspencer at dmsolutions.ca
Wed Jan 26 21:59:20 EST 2011


Usually if I run into this kind of problem I try wrapping the individual calls in a setTimeout.

Is there not some existing behaviour with groups in the legend where checking/unchecking changes the display of the layers within the group?  I believe it should hide them but remember which layers in the group were 'on' and which were 'off' when toggled.  Is this not working or is it not what you are looking for?

Also, the fact that it doesn't work without the alerts might indicate a subtle bug in how the layer state is updated.  Reading the code, it seems you should be able to do layer.hide(false) or layer.show(false) where the parameter should prevent the map from being redrawn immediately (i.e. you manually have to call map.redraw() at a later time).  However, that being said, it seems that for MapServer, there is no support for this (there is for MapGuide)  This seems to be a error of omission as it should be relatively straight forward to use the same logic in MapServer.js showLayer/hideLayer to allow a second parameter to indicate if the map should redraw immediately or not (it is supported in map.showGroup/hideGroup for instance).

Perhaps instead of using setTimeout, you could try modifying MapServer.js around line 532 (latest svn) to something like this:

    showLayer: function( sLayer, noDraw ) {
        this.aVisibleLayers.push(sLayer.layerName);
        if (!noDraw) {
	  this.drawMap();
        }
    },

    hideLayer: function( sLayer, noDraw ) {
        for (var i=0; i<this.aLayers.length; i++) {
            if (this.aVisibleLayers[i] == sLayer.layerName) {
                this.aVisibleLayers.splice(i,1);
                break;
            }
        }
        if (!noDraw) {
	  this.drawMap();
        }
    },

and then change your code to use layer.show(true)/layer.hide(true).  Once all the layers are changed, then you can do layer.oMap.drawMap() on any of the layers to cause the redraw to happen once.

Cheers

Paul

On 2011-01-26, at 2:21 AM, Jorge Soria wrote:

> 
> Good morning everyone, I have an issue enabling a group of layers
> simultaneously.
> I'm trying to modify the behaviour of the legend widget in fusion.
> What I want the legend to do is:
> If the user clicks in the group's checkbox --> enable/disable all the layers
> from that group.
> I call to the method layer.show() for every layer, but the layers are shown
> randomly.
> The weird thing is that if I make a pause between calls (alert, for
> example), the layers are shown correctly.
> 
> I think that some calls in my for loop are missing due to a timing/"not
> waiting for the map" issue.
> 
> Thanks in advance, Jorge.
> -- 
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/legend-js-layer-group-show-tp5961859p5961859.html
> Sent from the Fusion Users mailing list archive at Nabble.com.
> _______________________________________________
> fusion-users mailing list
> fusion-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fusion-users


__________________________________________

   Paul Spencer
   Chief Technology Officer
   DM Solutions Group Inc
   http://research.dmsolutions.ca/



More information about the fusion-users mailing list