public void WorkIdentify()
{
IMxDocument doc = ArcMap.Application.Document as IMxDocument;
IActiveView activeView = doc.ActiveView;
IPoint mouseLocation = GetScreenCoordinatesFromMapCoorindates(doc.CurrentLocation, activeView);
System.Int32 x = (System.Int32) mouseLocation.X;
System.Int32 y = (System.Int32) mouseLocation.Y;
if (activeView == null)
{
return;
}
ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
ESRI.ArcGIS.CartoUI.IIdentifyDialog identifyDialog = new ESRI.ArcGIS.CartoUI.IdentifyDialogClass();
identifyDialog.Map = map;
//Clear the dialog on each mouse click
identifyDialog.ClearLayers();
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ESRI.ArcGIS.Display.IDisplay display = screenDisplay; // Implicit Cast
identifyDialog.Display = display;
ESRI.ArcGIS.CartoUI.IIdentifyDialogProps identifyDialogProps = (ESRI.ArcGIS.CartoUI.IIdentifyDialogProps)identifyDialog; // Explicit Cast
ESRI.ArcGIS.Carto.IEnumLayer enumLayer = identifyDialogProps.Layers;
enumLayer.Reset();
ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next();
//
while (!(layer == null))
{
identifyDialog.AddLayerIdentifyPoint(layer, x, y);
layer = enumLayer.Next();
}
identifyDialog.Show();
}
Hello Kaspatoo,
I think you misunderstood my questions below, but it was a nice consideration from you.
Please note the following scenario in order to be more clear with my questions:
- I have four layers loaded in ArcMap 9.3 and the 3rd one called "X"
- I generated a form that contain a datagridview in order to preview the details of the selected X feature when a user click on the map. (same functionality as Identify tool)
- I want to get the "OBJECT ID" of the X feature that lies under the xy of the mouse click (polygon feature that covers the location of the mouse click) in order to query the details of the this X feature from my personal datatable and not from the layer in arcmap.
I think it is possible to get the "Object Id" of the feature located under the mouse click. Isn`t it?
The second think is that: I want to flash the selected feature in ArcMap programmtically, So how would be the code to do that?
Please help...
public static void CaptureMapCoordinates(int x, int y)
{
// get the map coordinates from the screen coordinates
IPoint pScreenPoint = new ESRI.ArcGIS.Geometry.Point();
IPoint pMapPoint = new ESRI.ArcGIS.Geometry.Point();
IEnvelope pEnv = new EnvelopeClass();
pScreenPoint.X = x;
pScreenPoint.Y = y;
pMapPoint = GetMapCoordinatesFromScreenCoordinates(pScreenPoint, pActiveView);
pEnv = pActiveView.Extent;
pEnv.CenterAt(pMapPoint);
pActiveView.Extent = pEnv;
pActiveView.Refresh();
}
private static IPoint GetMapCoordinatesFromScreenCoordinates(IPoint pScreenPoint, IActiveView pActiveView)
{
IScreenDisplay pScreenDisplay;
IDisplayTransformation pDisplayTransformation;
if (pScreenPoint == null || pScreenPoint.IsEmpty || pActiveView == null)
{
return null;
}
pScreenDisplay = pActiveView.ScreenDisplay;
pDisplayTransformation = pScreenDisplay.DisplayTransformation;
return pDisplayTransformation.ToMapPoint((int)pScreenPoint.X, (int)pScreenPoint.Y);
}