private void ExecuteIdentify(List <LayerFilterProperties> searchLayers, IGeometry identifyGeom) { object Missing = Type.Missing; IEnvelope searchEnvelope = GetIdentifyEnvelope(identifyGeom.Envelope); identifiedResultsList.Clear(); int identifiedObjCount = 0; //获取用于查询的图层的数量 int searchLayersCount = searchLayers.Count; //初始化进度条 //IdentifyProgress.Visible = true; //IdentifyProgress.Maximum = searchLayersCount; ////初始化闪烁对象 //flashObjects.MapControl = associateMapControl.Object as IMapControl2; //flashObjects.Init(); //遍历所有图层 for (int i = 0; i < searchLayersCount; i++) { LayerFilterProperties filterProps = searchLayers[i]; ILayer layer = filterProps.TargetLayer; //新建查询结果列表对象 LayerIdentifiedResult layerIdentifiedResult = new LayerIdentifiedResult(); //先保存查询图层对象 layerIdentifiedResult.IdentifyLayer = layer; layerIdentifiedResult.GeometryType = filterProps.LayerFeatureType; //首先获得查询结果列表对象,以备后面往里添加结果使用 List <IFeatureIdentifyObj> identifiedObjList = layerIdentifiedResult.IdentifiedFeatureObjList; //执行查询,返回查询结果 IArray identifyResult = Identify(layer, searchEnvelope); //处理异常情况 if (identifyResult != null) { //依次获取每一个查询结果对象 for (int k = 0; k < identifyResult.Count; k++) { identifiedObjCount++; IFeatureIdentifyObj identifiedFeatureObj = identifyResult.get_Element(k) as IFeatureIdentifyObj; //闪烁要素 IFeature identifiedFeature = (identifiedFeatureObj as IRowIdentifyObject).Row as IFeature; //添加闪烁图形 //flashObjects.AddGeometry(identifiedFeature.Shape); //保存查询结果 identifiedObjList.Add(identifiedFeatureObj); } identifiedResultsList.Add(layerIdentifiedResult); } //显示查询进度 //IdentifyProgress.Value = i + 1; Application.DoEvents(); } //隐藏进度条 // IdentifyProgress.Visible = false; //显示查询到的要素数量 // lblFeatureCount.Text = "查询到 " + identifiedObjCount + " 条记录"; }
private void ShowClickedNodeInfo(TreeNode nodeClicked, bool doFlash) { if (nodeClicked == null) { //初始化树型显示窗口 InitializeAttributesList(); return; } //获取点击点对应的要素 int nodeLevel = nodeClicked.Level; //获取点击的是图层还是图层下的要素 //若featureIndex < 0则表示点击的是图层,闪烁图层下选中的所有要素 //反之,则表示点击的是图层下的要素,获取图层索引和要素索引, //用于在结果列表中安索引获取要素或要素集属性 int layerIndex = -1; int featureIndex = -1; if (nodeLevel > 0) { TreeNode parentNode = nodeClicked.Parent; layerIndex = parentNode.Index; featureIndex = nodeClicked.Index; } else { layerIndex = nodeClicked.Index; } //获取对应要素 LayerIdentifiedResult layerResult = identifiedResultsList[layerIndex]; //点击了图层下的要素 if (featureIndex > -1) { IFeatureIdentifyObj identifyObjDefault = layerResult.IdentifiedFeatureObjList[featureIndex]; IFeature featureDefault = (identifyObjDefault as IRowIdentifyObject).Row as IFeature; //显示属性 ShowFeatureAttributes(featureDefault); DisplayCoordinates(featureDefault.Shape); if (ZoomToShape) { EsriUtils.ZoomToGeometry(featureDefault.Shape, _context.MapControl.Map, 2); if (doFlash) { FlashUtility.FlashGeometry(featureDefault.Shape, _context.MapControl); } } } //点击了图层,同时闪烁图层下的所有要素图形 else { //flashObjects.FlashObjects(layerResult); } }
private void DisplayIdentifyResults() { //清空以前所有显示结果 trvFeatures.Nodes.Clear(); //初始化属性显示窗口数据 lstAttribute.Items.Clear(); lstAttribute.Columns.Clear(); //声明变量 List <IFeatureIdentifyObj> IdentifyObjs = null; IFeatureIdentifyObj IdentifyObj = null; //列出查询结果 int resultsCount = identifiedResultsList.Count; for (int i = 0; i < resultsCount; i++) { LayerIdentifiedResult layerIdentifiedResult = identifiedResultsList[i]; //添加图层节点 TreeNode layerNode = trvFeatures.Nodes.Add(layerIdentifiedResult.IdentifyLayer.Name); //添加要素节点 IdentifyObjs = layerIdentifiedResult.IdentifiedFeatureObjList; for (int k = 0; k < IdentifyObjs.Count; k++) { IdentifyObj = IdentifyObjs[k]; IRowIdentifyObject rowIdentifyObj = IdentifyObj as IRowIdentifyObject; IFeature identifyFeature = rowIdentifyObj.Row as IFeature; layerNode.Nodes.Add(identifyFeature.OID.ToString()); } } //展开所有节点 trvFeatures.ExpandAll(); //默认显示第一图层的第一个查询要素 if (trvFeatures.Nodes.Count < 1) { ShowClickedNodeInfo(null, false); } //显示第一图层的第一个查询要素 else { TreeNode topNode = trvFeatures.Nodes[0].Nodes[0]; //显示第一节点 trvFeatures.TopNode = topNode.Parent; ShowClickedNodeInfo(topNode, false); } }