[mapguide-commits] r7139 - trunk/MgDev/Web/src/viewerfiles
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri Oct 19 08:51:15 PDT 2012
Author: jng
Date: 2012-10-19 08:51:15 -0700 (Fri, 19 Oct 2012)
New Revision: 7139
Modified:
trunk/MgDev/Web/src/viewerfiles/legendctrl.templ
trunk/MgDev/Web/src/viewerfiles/legendui.templ
Log:
#1012: Add an AJAX Viewer API to Expand and Collapse layer and group nodes in the legend. These expanded/collapsed states are only client-side, for these states to be persistent (ie. stay the same after legend refresh) the calling application must invoke a server-side script that calls SetExpandInLegend() on the appropriate MgLayer and MgLayerGroup objects. This has been remarked in the updated Viewer API documentation (coming after this)
Modified: trunk/MgDev/Web/src/viewerfiles/legendctrl.templ
===================================================================
--- trunk/MgDev/Web/src/viewerfiles/legendctrl.templ 2012-10-19 15:01:03 UTC (rev 7138)
+++ trunk/MgDev/Web/src/viewerfiles/legendctrl.templ 2012-10-19 15:51:15 UTC (rev 7139)
@@ -42,6 +42,16 @@
return thisFrame.legendUiFrame.GetBaseGroups(onlyVisible,scale);
}
+function ExpandLayerInLegend(layerName, expandInLegend)
+{
+ return thisFrame.legendUiFrame.ExpandLayerInLegend(layerName, expandInLegend);
+}
+
+function ExpandGroupInLegend(groupName, expandInLegend)
+{
+ return thisFrame.legendUiFrame.ExpandGroupInLegend(groupName, expandInLegend);
+}
+
// private functions -----------------------------------------------
//
function IsUiReady()
Modified: trunk/MgDev/Web/src/viewerfiles/legendui.templ
===================================================================
--- trunk/MgDev/Web/src/viewerfiles/legendui.templ 2012-10-19 15:01:03 UTC (rev 7138)
+++ trunk/MgDev/Web/src/viewerfiles/legendui.templ 2012-10-19 15:51:15 UTC (rev 7139)
@@ -1222,12 +1222,98 @@
function SetShowInvisibleLayers(isInvisibleLayersVisible)
{
- showInvisibleLayers = isInvisibleLayersVisible;
- GetMainFrame().Refresh();
+ showInvisibleLayers = isInvisibleLayersVisible;
+ GetMainFrame().Refresh();
}
+function ExpandLayerInLegend(layerName, expandInLegend)
+{
+ if (tree == null) return;
+ var nodeLayer = FindLayerByName(tree,layerName);
+ if (nodeLayer != null)
+ {
+ if (expandInLegend)
+ Expand(nodeLayer);
+ else
+ Collapse(nodeLayer);
+
+ }
+}
+
+function ExpandGroupInLegend(groupName, expandInLegend)
+{
+ if (tree == null)
+ return;
+ var nodeGroup = FindGroupByName(tree, groupName);
+ if (nodeGroup != null)
+ ExpandAllGroupParentInLegend(expandInLegend,nodeGroup);
+}
+
+function FindGroupByName(nodes, groupName)
+{
+ for (var i=0; i < nodes.length; i++)
+ {
+ var node = nodes[i];
+ if (node.type == 0)// only group
+ {
+ if (node.name.toLowerCase() == groupName.toLowerCase())
+ return node;
+ if (node.children != null)
+ {
+ var child = FindGroupByName(node.children, groupName.toLowerCase());
+ if (child != null)
+ return child;
+ }
+ }
+ }
+ return null;
+}
+
+function FindLayerByName(nodes, layerName)
+{
+ for (var i=0; i < nodes.length; i++)
+ {
+ var node = nodes[i];
+ if (node.type == 1)// only layer
+ {
+ if (node.name.toLowerCase() == layerName.toLowerCase())
+ return node;
+ }
+ else (node.type == 0) // only group
+ {
+ if (node.children != null)
+ {
+ var child = FindLayerByName(node.children, layerName.toLowerCase());
+ if (child != null)
+ return child;
+ }
+ }
+ }
+ return null;
+}
+
+// if expandInLegend==true => node group and all parents of this group are expanded
+// if expandInLegend==false => only node group is collapsed
+function ExpandAllGroupParentInLegend(expandInLegend,node)
+{
+ if (expandInLegend)
+ {
+ Expand(node);
+ if (node.parent!= null)
+ ExpandAllGroupParentInLegend(expandInLegend,node.parent);
+ }
+ else Collapse(node);
+}
+
+function GetGroupByLayer(layerName)
+{
+ if (tree == null) return null;
+ var nodeLayer = FindLayerByName(tree,layerName);
+ if ((nodeLayer != null) && (nodeLayer.parent != null))
+ return nodeLayer.parent;
+ return null;
+}
</script>
-
</head>
<body id="legendUi" onload="InitDocument()" leftmargin=3 topmargin=3 rightmargin=3 bottommargin=3 marginwidth=3 marginheight=3>
<div id="Tree"></div>
More information about the mapguide-commits
mailing list