class SelectFeatureTool : ESRI.ArcGIS.Desktop.AddIns.Tool
{
protected override void OnMouseDown(MouseEventArgs arg)
{
IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
IActiveView activeView = mxDocument.ActiveView;
IMap map = mxDocument.FocusMap;
ILayer layer = map.get_Layer(0); //Get 1st Layer
IFeatureLayer featureLayer = (IFeatureLayer) layer;
IPoint identifyPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
ESRI.ArcGIS.Carto.IIdentify identifyLayer = (IIdentify)layer;
IArray array = identifyLayer.Identify(identifyPoint);
int oid = -1;
if (array != null)
{
object obj = array.get_Element(0);
IFeatureIdentifyObj fobj = obj as IFeatureIdentifyObj;
IRowIdentifyObject irow = fobj as IRowIdentifyObject;
IFeature feature = irow.Row as IFeature;
oid = feature.OID;
}
HighlightClickedFeature(featureLayer, oid, activeView);
}
Friday, April 14, 2017
Code Snippet: Select feature polygon(s) on Mouse Click ArcObjects C#
Code snippet of custom feature(s) selection tool on mouse click and highlight it using ArcObjects and C#.
Subscribe to:
Posts
(
Atom
)