第一步:根据鼠标点击处的点,找到被选中的要素
1 public IFeature Find2(IPoint pPoint) 2 { 3 ITopologicalOperator pTopoOpe = pPoint as ITopologicalOperator; 4 double dis = m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(5); 5 if (dis < 0.01) 6 dis = 0.01; 7 IGeometry pBuffer = pTopoOpe.Buffer(dis); 8 pBuffer.SpatialReference = m_pMapControl.Map.SpatialReference; 9 10 UIDClass id = new UIDClass(); 11 id.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; 12 IEnumLayer pEnumLayer = m_pMapControl.Map.get_Layers(id, true); 13 pEnumLayer.Reset(); 14 IFeatureLayer pFLayer = pEnumLayer.Next() as IFeatureLayer; 15 16 ISpatialFilter pSpatialFilter = new SpatialFilterClass(); 17 pSpatialFilter.Geometry = pBuffer; 18 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; 19 pSpatialFilter.WhereClause = ""; 20 21 while (pFLayer != null) 22 { 23 if (pFLayer.Visible == false) 24 { 25 pFLayer = pEnumLayer.Next() as IFeatureLayer; 26 continue; 27 } 28 IFeatureCursor pCursor = pFLayer.Search(pSpatialFilter, false); 29 IFeature pFeat = pCursor.NextFeature(); 30 if (pFeat != null) 31 { 32 return pFeat; 33 } 34 System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); 35 pFLayer = pEnumLayer.Next() as IFeatureLayer; 36 } 37 return null; 38 }