[fusion-commits] r2849 - sandbox/adsk/2.5k/widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Thu Jun 19 23:48:03 PDT 2014
Author: liuar
Date: 2014-06-19 23:48:03 -0700 (Thu, 19 Jun 2014)
New Revision: 2849
Modified:
sandbox/adsk/2.5k/widgets/Legend.js
Log:
ticket #616 http://trac.osgeo.org/fusion/ticket/616
Don't show empty group folders in legend of flexible layout.
Modified: sandbox/adsk/2.5k/widgets/Legend.js
===================================================================
--- sandbox/adsk/2.5k/widgets/Legend.js 2014-06-17 12:45:14 UTC (rev 2848)
+++ sandbox/adsk/2.5k/widgets/Legend.js 2014-06-20 06:48:03 UTC (rev 2849)
@@ -249,7 +249,13 @@
*/
bIncludeVisToggle: true,
offsetsCalculated: false,
-
+
+ /**
+ * Property: bHideEmptyGroups
+ * {Boolean} Determine if a group which has non-visible layer must be draw in the legend.
+ */
+ bHideEmptyGroups: true,
+
initialize: function(legend, widgetTag) {
Fusion.Widget.Legend.LegendRenderer.prototype.initialize.apply(this, [legend]);
@@ -287,7 +293,8 @@
this.showRootFolder = (json.ShowRootFolder && json.ShowRootFolder[0] == 'true') ? true:false;
//do show the map folder by default
this.showMapFolder = (json.ShowMapFolder && json.ShowMapFolder[0] == 'false') ? false:true;
-
+ this.bHideEmptyGroups = true;
+
if (!this.showRootFolder) {
//console.log('supressing root folder');
this.oRoot = this.oTree;
@@ -515,8 +522,25 @@
for (var i=0; i<map.layerRoot.layers.length; i++) {
this.updateLayer(map.layerRoot.layers[i], currentScale);
}
+ if (this.bHideEmptyGroups) {
+ for (var i=0; i<map.layerRoot.groups.length; i++) {
+ this.hideEmptyGroup(map.layerRoot.groups[i]);
+ }
+ }
},
+ hideEmptyGroup: function(group) {
+ for (var i=0; i<group.groups.length; i++) {
+ this.hideEmptyGroup(group.groups[i])
+ }
+ if (group.hasVisibleLayers) {
+ if (group.parentGroup.legend && group.parentGroup.legend.treeItem)
+ group.parentGroup.legend.treeItem.add(group.legend.treeItem);
+ } else {
+ group.parentGroup.legend.treeItem.remove(group.legend.treeItem);
+ }
+ },
+
/**
* remove the dom objects representing the legend layers and groups
*/
@@ -547,18 +571,39 @@
}
}
},
-
+
updateGroupLayers: function(group, fScale) {
+ group.hasVisibleLayers = false;
for (var i=0; i<group.groups.length; i++) {
this.updateGroupLayers(group.groups[i], fScale);
}
for (var i=0; i<group.layers.length; i++) {
this.updateLayer(group.layers[i], fScale);
}
+
+ // Hide empty groups if necessary.
+ if (!this.bHideEmptyGroups)
+ return;
+ // Check if the group has visible layers
+ for (var i=0; i<group.layers.length; i++) {
+ if (group.layers[i].visibleInGroupLegend) {
+ group.hasVisibleLayers = true;
+ break;
+ }
+ }
+ if (group.hasVisibleLayers)
+ return;
+ for (var i=0; i<group.groups.length; i++) {
+ if (group.groups[i].hasVisibleLayers) {
+ group.hasVisibleLayers = true;
+ break;
+ }
+ }
},
updateLayer: function(layer, fScale) {
/* no need to do anything if we are hiding the layer */
if (!layer.displayInLegend || !layer.legend) {
+ layer.visibleInGroupLegend = false;
return;
}
/* check the layer's current scale range against the previous one
@@ -664,9 +709,12 @@
}
}
if (layer.legend.treeItem) {
+ layer.visibleInGroupLegend = true;
layer.legend.treeItem.options.data = layer;
if (!layer.isBaseMapLayer) //Tiled layers don't have a checkbox so there's nothing to check
layer.legend.treeItem.check(layer.visible);
+ } else {
+ layer.visibleInGroupLegend = false;
}
},
getThemeExpandContextMenu: function(node) {
More information about the fusion-commits
mailing list