[fusion-dev] wasVisibleInGroup not set properly upon loading info from Mapfile in MapServer.js

Bernhard Schneider schneiderei at hispeed.ch
Thu Dec 10 15:30:49 EST 2009


Dear Fusioners,

It wouldn't surprise me if this issue has been spotted and dealt with already, but I thought I point it out anyway, maybe someone will have a look at it.

I am using Fusion 2 beta with MapServer, and I found that in MapServer.js, the layer property wasVisibleInGroup is not set properly when the map info is loaded from the mapfile.

The method Fusion.Layers.MapServer.mapLoaded(..) forwards the map layer and group info to Fusion.Layers.MapServer.parseMapLayersAndGroups(..). mapLoaded(..) receives the tree of layers and groups back and continues with setting up the array this.aVisibleLayers. The problem is that when doing this, it does not take into account that a layer may well be visible, but that its parent group may not be. This causes the layer's attribute visible to be left to true when it actually should be false. Moreover, in this situation there should be an attribute wasVisibleInGroup assigned to the layer, and this attribute should be set to true. (The layer attributes visible and wasVisibleInGroup are used in the legend and when querying the map, maybe elsewhere too.)

And there is more: When building the array this.aVisibleLayers, it does not suffice to check for the visible-attribute of the layer. Instead, the visible-state of the parent group should be checked as well.

I suggest changing a block of code in the method Fusion.Layers.MapServer.mapLoaded(..) as follows.

The version I downloaded:

            for (var i=0; i<this.aLayers.length; i++) {
              if (this.aLayers[i].visible) {
                this.aVisibleLayers.push(this.aLayers[i].layerName);
              }
              minScale = Math.min(minScale, this.aLayers[i].minScale);
              maxScale = Math.max(maxScale, this.aLayers[i].maxScale);
            }

My suggested code, works fine in my application:

            for (var i=0; i<this.aLayers.length; i++) {
              // if (this.aLayers[i].visible) {
              if ((this.aLayers[i].visible) && (this.aLayers[i].parentGroupIsVisible())) {
                this.aVisibleLayers.push(this.aLayers[i].layerName);
              }
              if ((this.aLayers[i].visible) && (!this.aLayers[i].parentGroupIsVisible())) {
                this.aLayers[i].wasVisibleInGroup = true;
                this.aLayers[i].visible = false;
              }            
              minScale = Math.min(minScale, this.aLayers[i].minScale);
              maxScale = Math.max(maxScale, this.aLayers[i].maxScale);
            }


The suggested change requests adding the layer method parentGroupIsVisible to Fusion.Layers.Layer in Layers.js:

    parentGroupIsVisible: function() {
		if ((this.parentGroup) && (this.parentGroup.isVisible))
    			return this.parentGroup.isVisible();
    		else
    			return true;
    },

In this method, I assume that a group may have its own parent group (nested groups), in which case the same method needs to be added to the class Fusion.Layers.Group.

Again, this may have been dealt with already, or I may have missed something and my changes aren't doing any good. Hopefully, it is still helpful in one way or the other.

Bernhard



More information about the fusion-dev mailing list