public TreeItem(string name, bool isGroup, object rtObject, string layerData) { this.name = name; this.isGroup = isGroup; this.rtObject = rtObject; this.layerData = layerData; if (isGroup) { this.children = new System.Collections.ArrayList(); } else { this.children = null; } this.parent = null; }
private void BuildLayerTree(MgMap map) { System.Collections.Hashtable knownGroups = new System.Collections.Hashtable(); System.Collections.ArrayList unresolved = new System.Collections.ArrayList(); MgLayerGroupCollection groups = map.GetLayerGroups(); for (int i = 0; i < groups.GetCount(); i++) { MgLayerGroup rtGroup = groups.GetItem(i); Legend.TreeItem node = new Legend.TreeItem(rtGroup.GetName(), true, rtGroup, null); knownGroups.Add(node.name, node); MgLayerGroup parentGroup = rtGroup.GetGroup(); if (parentGroup == null) { this.tree.Add(node); } else { string parentName = parentGroup.GetName(); Legend.TreeItem parentNode = (Legend.TreeItem)knownGroups[parentName]; if (parentNode != null) { parentNode.Attach(node); } else { node.parentName = parentName; unresolved.Add(node); } } } if (unresolved.Count > 0) { for (int i = 0; i < unresolved.Count; i++) { Legend.TreeItem node = (Legend.TreeItem)unresolved[i]; Legend.TreeItem parentNode = (Legend.TreeItem)knownGroups[node.parentName]; if (parentNode != null) { parentNode.Attach(node); } else { this.tree.Add(node); } } } MgLayerCollection layers = map.GetLayers(); for (int i = 0; i < layers.GetCount(); i++) { if (layers.GetItem(i).GetDisplayInLegend()) { MgLayer rtLayer = (MgLayer)layers.GetItem(i); MgResourceIdentifier resId = rtLayer.GetLayerDefinition(); Legend.TreeItem node = new Legend.TreeItem(rtLayer.GetName(), false, rtLayer, this.resSrvc.GetResourceContent(resId).ToString()); MgLayerGroup parentGroup = rtLayer.GetGroup(); if (parentGroup == null) { this.tree.Add(node); } else { Legend.TreeItem parentNode = (Legend.TreeItem)knownGroups[parentGroup.GetName()]; if (parentNode != null) { parentNode.Attach(node); } else { this.tree.Add(node); } } } } }