第一步:根据鼠标点击处的点,找到被选中的要素
public IFeature Find2(IPoint pPoint)
{
ITopologicalOperator pTopoOpe = pPoint as ITopologicalOperator;
double dis = m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints();
if (dis < 0.01)
dis = 0.01;
IGeometry pBuffer = pTopoOpe.Buffer(dis);
pBuffer.SpatialReference = m_pMapControl.Map.SpatialReference; UIDClass id = new UIDClass();
id.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
IEnumLayer pEnumLayer = m_pMapControl.Map.get_Layers(id, true);
pEnumLayer.Reset();
IFeatureLayer pFLayer = pEnumLayer.Next() as IFeatureLayer; ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pBuffer;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
pSpatialFilter.WhereClause = ""; while (pFLayer != null)
{
if (pFLayer.Visible == false)
{
pFLayer = pEnumLayer.Next() as IFeatureLayer;
continue;
}
IFeatureCursor pCursor = pFLayer.Search(pSpatialFilter, false);
IFeature pFeat = pCursor.NextFeature();
if (pFeat != null)
{
return pFeat;
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
pFLayer = pEnumLayer.Next() as IFeatureLayer;
}
return null;
}
第二步:取出被选要素的属性值
IFields pFields = pFeat.Fields;
for (int i = ; i < pFields.FieldCount; i++)
{
IField pField = pFields.get_Field(i);
if (pField.Type != esriFieldType.esriFieldTypeBlob & pField.Type != esriFieldType.esriFieldTypeOID
& pField.Type != esriFieldType.esriFieldTypeGeometry)
{
checkedListBox1.Items.Add(pField.AliasName);
}
}
第三步:在mapcontrol中显示属性,用到ICallout 加ITextElement
ICallout pCallout = new ESRI.ArcGIS.Display.BalloonCalloutClass();
pCallout.AnchorPoint = pPoint;
pCallout.LeaderTolerance = ; ITextElement pTextElement = new TextElementClass();
IElement pElement = pTextElement as IElement;
ITextSymbol pTextSysmbol = pTextElement.Symbol;
IFormattedTextSymbol pFormattedTextSymbol = new TextSymbolClass();
pFormattedTextSymbol.Background = pCallout as ITextBackground;
pFormattedTextSymbol.Size = ;
pFormattedTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
pTextElement.Symbol = pFormattedTextSymbol;
pTextElement.Text = labelString; pElement.Geometry = pPoint;
m_pMapControl.ActiveView.GraphicsContainer.AddElement(pElement, );
m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pMapControl.Extent);