[fusion-commits] r3008 - in sandbox/adsk/3.1n: layers/MapGuide lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Sep 28 21:50:52 PDT 2017


Author: zhanga
Date: 2017-09-28 21:50:52 -0700 (Thu, 28 Sep 2017)
New Revision: 3008

Modified:
   sandbox/adsk/3.1n/layers/MapGuide/MapGuide.js
   sandbox/adsk/3.1n/lib/Map.js
   sandbox/adsk/3.1n/widgets/Legend.js
   sandbox/adsk/3.1n/widgets/MapMenu.js
Log:
This submission solved 3 issues:
1. Hide group in legend tree if it is empty.
2. Set map initial active state in "Maps" menu.
3. If there are more than one base layer groups and one of them is invisible initially, the features of the layer in the group cannot be selected after show the group. It is because we don't save the map object when clicking the check box of base layer group. I added a call of GETVISIBLEMAPEXTENT to workaround this issue.

Modified: sandbox/adsk/3.1n/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/adsk/3.1n/layers/MapGuide/MapGuide.js	2017-09-06 06:03:49 UTC (rev 3007)
+++ sandbox/adsk/3.1n/layers/MapGuide/MapGuide.js	2017-09-29 04:50:52 UTC (rev 3008)
@@ -1616,6 +1616,11 @@
                     this.oLayersOLTile[i].setVisibility(true);
                 }
             }
+            this.aShowGroups.push(group.uniqueId);
+            if (this.drawDelay > 0) {
+                this.aHideGroups.erase(group.uniqueId);
+            }
+            this.mapExtentsChanged();
         } else {
             this.aShowGroups.push(group.uniqueId);
             //A group cannot be both hidden and shown, which can be the case if there is a draw
@@ -1640,6 +1645,11 @@
                     this.oLayersOLTile[i].setVisibility(false);
                 }
             }
+            this.aHideGroups.push(group.uniqueId);
+            if (this.drawDelay > 0) {
+                this.aShowGroups.erase(group.uniqueId);
+            }
+            this.mapExtentsChanged();
         } else {
             this.aHideGroups.push(group.uniqueId);
             //A group cannot be both hidden and shown, which can be the case if there is a draw
@@ -1712,14 +1722,21 @@
       if (!this.singleTile) {
           var center = this.mapWidget.oMapOL.getCenter();
           var display = this.mapWidget.oMapOL.getSize();
-          
+          var showGroups = this.aShowGroups.length > 0 ? this.aShowGroups.toString() : null;
+          var hideGroups = this.aHideGroups.length > 0 ? this.aHideGroups.toString() : null;
+          this.aShowGroups = [];
+          this.aHideGroups = [];
           var r = new Fusion.Lib.MGRequest.MGGetVisibleMapExtent(this.getSessionID(),
                                                               this._sMapname,
                                                               center.lon, center.lat,
                                                               this.mapWidget.oMapOL.getScale(),
                                                               null,
                                                               this._nDpi,
-                                                              display.w, display.h);
+                                                              display.w, display.h,
+                                                              null,
+                                                              null,
+                                                              showGroups,
+                                                              hideGroups);
           Fusion.oBroker.dispatchRequest(r);
       }
     },

Modified: sandbox/adsk/3.1n/lib/Map.js
===================================================================
--- sandbox/adsk/3.1n/lib/Map.js	2017-09-06 06:03:49 UTC (rev 3007)
+++ sandbox/adsk/3.1n/lib/Map.js	2017-09-29 04:50:52 UTC (rev 3008)
@@ -415,6 +415,14 @@
         var startIndex = loadOverlays?1:0;
         for (var i = this.aMaps.length-1; i >= startIndex; i--) {
           if (this.aMaps[i].oLayerOL) {
+            if (this.aMaps[i].oLayerOL2) {
+                this.aMaps[i].oLayerOL2.destroy();
+            }
+            if (this.aMaps[i].oLayersOLTile) {
+                for (var j = 0; j < this.aMaps[i].oLayersOLTile.length; j++) {
+                    this.aMaps[i].oLayersOLTile[j].destroy();
+                }
+            }
             this.aMaps[i].oLayerOL.destroy();
             this.aMaps.splice(i,1);
           }
@@ -422,6 +430,9 @@
  
         this._fMetersperunit = -1;
         this.oMapOL.center = null;
+        this.oMapOL.minPx = null;
+        this.oMapOL.maxPx = null;
+        this.oMapOL.zoom = null;
         this.maxExtent = new OpenLayers.Bounds();
         var storedBase;
         if (loadOverlays) {

Modified: sandbox/adsk/3.1n/widgets/Legend.js
===================================================================
--- sandbox/adsk/3.1n/widgets/Legend.js	2017-09-06 06:03:49 UTC (rev 3007)
+++ sandbox/adsk/3.1n/widgets/Legend.js	2017-09-29 04:50:52 UTC (rev 3008)
@@ -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;
@@ -543,9 +550,27 @@
         for (var i=map.layerRoot.layers.length-1; i>=0; 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]);
+            }
+        }
         this.oTree.thaw();
     },
    
+    hideEmptyGroup: function(group) {
+        if (group.hasVisibleLayers) {
+            if (group.legend.treeItem) {
+                group.legend.treeItem.domObj.style.display = 'block';
+            }
+            for (var i=0; i<group.groups.length; i++) {
+                this.hideEmptyGroup(group.groups[i])
+            }
+        } else {
+            group.legend.treeItem.domObj.style.display = 'none';
+        }
+    },
+   
     /**
      * remove the dom objects representing the legend layers and groups
      */
@@ -576,6 +601,7 @@
         }
       }
     },
+
     addLayerStyleTreeItems: function(treeItem, items) {
         treeItem.tree.freeze();
         treeItem.add(items);
@@ -601,7 +627,9 @@
         //above are still valid.
         treeItem.add(layerTreeItem, 0);
     },
+
     updateGroupLayers: function(group, fScale) {
+        group.hasVisibleLayers = false;
         for (var i=0; i<group.groups.length; i++) {
             this.updateGroupLayers(group.groups[i], fScale);
         }
@@ -609,10 +637,30 @@
         for (var i=group.layers.length-1 ; i >= 0; 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
@@ -721,9 +769,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) {

Modified: sandbox/adsk/3.1n/widgets/MapMenu.js
===================================================================
--- sandbox/adsk/3.1n/widgets/MapMenu.js	2017-09-06 06:03:49 UTC (rev 3007)
+++ sandbox/adsk/3.1n/widgets/MapMenu.js	2017-09-29 04:50:52 UTC (rev 3008)
@@ -80,6 +80,7 @@
         
         var mapGroups = Fusion.applicationDefinition.mapGroups;
         this.mapGroupData = {};
+        var oMap = this.getMap();
         var buttonSet = new Jx.ButtonSet();
         for (var key in mapGroups) {
             if (mapGroups[key].mapId) {
@@ -95,6 +96,8 @@
                     });
                     buttonSet.add(menuItem);
                     this.uiObj.add(menuItem);
+                    if (oMap && oMap.mapGroup.mapId == mapGroup.mapId)
+                        menuItem.setActive(true);
                 }
             }
         }



More information about the fusion-commits mailing list