[mapguide-commits] r7586 - branches/2.4/MgDev/Desktop/MapViewer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Jun 9 06:23:35 PDT 2013


Author: jng
Date: 2013-06-09 06:23:35 -0700 (Sun, 09 Jun 2013)
New Revision: 7586

Modified:
   branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs
Log:
Copy entire updated MgLegendControlPresenter back to 2.4, this includes the fix for #2288 and the fixes for draw ordering and infinite loops.

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs	2013-06-09 13:17:13 UTC (rev 7585)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgLegendControlPresenter.cs	2013-06-09 13:23:35 UTC (rev 7586)
@@ -352,12 +352,12 @@
 
         public TreeNode[] CreateNodes()
         {
-            List<TreeNode> output = new List<TreeNode>();
-            var nodesById = new Dictionary<string, TreeNode>();
-
+            List<TreeNode> topLevelNodes = new List<TreeNode>();
             var scale = _map.ViewScale;
             if (scale < 10.0)
-                return output.ToArray();
+                return topLevelNodes.ToArray();
+            var nodesById = new Dictionary<string, TreeNode>();
+            var groupsById = new Dictionary<string, TreeNode>();
 
             var groups = _map.GetLayerGroups();
             var layers = _map.GetLayers();
@@ -372,7 +372,7 @@
                 if (!group.GetDisplayInLegend())
                     continue;
 
-                //Add ones without parents first.
+                //Add ones without parents first. Queue up child groups
                 if (group.Group != null)
                 {
                     remainingNodes.Add(group);
@@ -380,22 +380,32 @@
                 else
                 {
                     var node = CreateGroupNode(group);
-                    output.Add(node);
+                    topLevelNodes.Add(node);
                     nodesById.Add(group.GetObjectId(), node);
+                    groupsById.Add(group.GetObjectId(), node);
                 }
             }
 
+            //Process child groups
             while (remainingNodes.Count > 0)
             {
                 List<MgLayerGroup> toRemove = new List<MgLayerGroup>();
+                //Establish parent-child relationship for any child groups here
                 for (int j = 0; j < remainingNodes.Count; j++)
                 {
                     var parentId = remainingNodes[j].Group.GetObjectId();
                     if (nodesById.ContainsKey(parentId))
                     {
-                        var node = CreateGroupNode(remainingNodes[j]);
+                        MgLayerGroup grp = remainingNodes[j];
+                        var node = CreateGroupNode(grp);
                         nodesById[parentId].Nodes.Add(node);
-                        toRemove.Add(remainingNodes[j]);
+
+                        //Got to add this group node too, otherwise we could infinite
+                        //loop looking for a parent that's not registered
+                        nodesById.Add(grp.GetObjectId(), node);
+                        groupsById.Add(grp.GetObjectId(), node);
+
+                        toRemove.Add(grp);
                     }
                 }
                 //Whittle down this list
@@ -414,7 +424,8 @@
             var layerMetaNodesToUpdate = new Dictionary<string, MgLayerBase>();
             //Now process layers. Layers without metadata nodes or without layer definition content
             //are added to the list
-            for (int i = 0; i < layers.GetCount(); i++)
+            int layerCount = layers.GetCount();
+            for (int i = 0; i < layerCount; i++)
             {
                 var lyr = layers.GetItem(i);
                 bool display = lyr.DisplayInLegend;
@@ -425,30 +436,34 @@
                 if (!visible)
                     continue;
 
-                if (_layers.ContainsKey(lyr.GetObjectId()))
+                var lyrObjId = lyr.GetObjectId();
+                if (_layers.ContainsKey(lyrObjId))
                 {
-                    if (string.IsNullOrEmpty(_layers[lyr.GetObjectId()].LayerDefinitionContent))
+                    if (string.IsNullOrEmpty(_layers[lyrObjId].LayerDefinitionContent))
                     {
                         var ldfId = lyr.LayerDefinition;
-                        layerIds.Add(ldfId.ToString());
-                        layerMetaNodesToUpdate[ldfId.ToString()] = lyr;
+                        var ldfIdStr = ldfId.ToString();
+                        layerIds.Add(ldfIdStr);
+                        layerMetaNodesToUpdate[ldfIdStr] = lyr;
                     }
                 }
                 else
                 {
                     var ldfId = lyr.LayerDefinition;
-                    layerIds.Add(ldfId.ToString());
-                    layerMetaNodesToUpdate[ldfId.ToString()] = lyr;
+                    var ldfIdStr = ldfId.ToString();
+                    layerIds.Add(ldfIdStr);
+                    layerMetaNodesToUpdate[ldfIdStr] = lyr;
                 }
             }
 
-            if (layerIds.GetCount() > 0)
+            int layerIdCount = layerIds.GetCount();
+            if (layerIdCount > 0)
             {
                 int added = 0;
                 int updated = 0;
                 //Fetch the contents and create/update the required layer metadata nodes
                 MgStringCollection layerContents = _resSvc.GetResourceContents(layerIds, null);
-                for (int i = 0; i < layerIds.GetCount(); i++)
+                for (int i = 0; i < layerIdCount; i++)
                 {
                     string lid = layerIds.GetItem(i);
                     var lyr = layerMetaNodesToUpdate[lid];
@@ -470,11 +485,16 @@
                 Trace.TraceInformation("CreateNodes: {0} layer contents added, {1} layer contents updated", added, updated); //NOXLATE
             }
 
+            //Now create our layer nodes
             List<MgLayerBase> remainingLayers = new List<MgLayerBase>();
-            for (int i = 0; i < layers.GetCount(); i++)
+            //NOTE: We're taking a page out of the Fusion playbook of reverse iterating the layer
+            //collection and prepending the nodes, as this control suffered the same problem as the
+            //Legend widget in Fusion. Doing it this way eliminates the need for doing an extra pass to fix
+            //the layer/group ordering, which may make an impact on really chunky maps.
+            for (int i = layerCount - 1; i >= 0; i--)
             {
                 var layer = layers.GetItem(i);
-                
+
                 bool display = layer.DisplayInLegend;
                 bool visible = _provider.IsLayerPotentiallyVisibleAtScale(layer, false);
                 if (!display)
@@ -493,7 +513,7 @@
                     var node = CreateLayerNode(layer);
                     if (node != null)
                     {
-                        output.Add(node);
+                        topLevelNodes.Insert(0, node);
                         nodesById.Add(layer.GetObjectId(), node);
                         if (layer.ExpandInLegend)
                             node.Expand();
@@ -504,7 +524,7 @@
             while (remainingLayers.Count > 0)
             {
                 List<MgLayerBase> toRemove = new List<MgLayerBase>();
-                for (int j = 0; j < remainingLayers.Count; j++)
+                for (int j = remainingLayers.Count - 1; j >= 0; j--)
                 {
                     var parentGroup = remainingLayers[j].Group;
                     var parentId = parentGroup.GetObjectId();
@@ -513,13 +533,13 @@
                         var node = CreateLayerNode(remainingLayers[j]);
                         if (node != null)
                         {
-                            nodesById[parentId].Nodes.Add(node);
+                            nodesById[parentId].Nodes.Insert(0, node);
                             if (remainingLayers[j].ExpandInLegend)
                                 node.Expand();
                         }
                         toRemove.Add(remainingLayers[j]);
                     }
-                    else //Check parent group visibility. Could explain it
+                    else
                     {
                         if (!parentGroup.GetDisplayInLegend())
                             toRemove.Add(remainingLayers[j]);
@@ -549,7 +569,7 @@
                 }
             }
             Trace.TraceInformation("{0} calls made to GenerateLegendImage", legendCallCount); //NOXLATE
-            return output.ToArray();
+            return topLevelNodes.ToArray();
         }
 
         private static bool IsThemeLayerNode(TreeNode node)
@@ -868,7 +888,7 @@
             {
                 base.IsGroup = false;
                 this.Layer = layer;
-                this.Checkable = (layer.Group != null && layer.Group.LayerGroupType == MgLayerGroupType.Normal);
+                this.Checkable = (layer.LayerType != MgLayerType.BaseMap);
                 this.IsSelectable = (layer != null) ? layer.Selectable : false;
                 this.DrawSelectabilityIcon = (layer != null && bInitiallySelectable);
                 this.WasInitiallySelectable = bInitiallySelectable;
@@ -1069,4 +1089,4 @@
             }
         }
     }
-}
+}
\ No newline at end of file



More information about the mapguide-commits mailing list