I am trying to use two ProSnippets within a SINGLE ArcGIS Pro tool and need help. Here are the two snippets, but I cannot seem to make them both work within a single tool. I did this within an Add-In tool in ArcGIS Desktop, but I'm not sure what is going on with Pro. Can anyone steer me in the right direction. I want a single click to give me Coordinates AND access to the underlying layers. (Once coded, I don't really need the info in MessageBoxes)
internal class GetMapCoordinates : MapTool
{
protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
{
if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
e.Handled = true; //Handle the event args to get the call to the corresponding async method
}
protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
{ return QueuedTask.Run(() =>
{
//Convert the clicked point in client coordinates to the corresponding map coordinates.
var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}", mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
});
}
}
internal class CustomIdentify : MapTool
{ public CustomIdentify()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point; //In the Snippet this is Rectangle, I just want it the point.
//To perform a interactive selection or identify in 3D or 2D, sketch must be created in screen coordinates.
SketchOutputMode = SketchOutputMode.Screen;
}
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{ return QueuedTask.Run(() =>
{
var mapView = MapView.Active;
if (mapView == null)
return true;
//Get all the features that intersect the sketch geometry and flash them in the view.
var results = mapView.GetFeatures(geometry);
mapView.FlashFeature(results);
//Show a message box reporting each layer the number of the features.
MessageBox.Show(
String.Join("\n", results.Select(kvp => String.Format("{0}: {1}", kvp.Key.Name, kvp.Value.Count()))),
"Identify Result");
return true;
});
}
}
As your tool is using point as its sketch type then cast the Geometry input parameter in the OnSketchCompleteAsync callback to MapPoint and you have it.
MapPoint mp = (MapPoint)geometry;
It works, (THANK YOU!) except it's giving me screen coordinates instead of State Plane coordinates. (When I ran it individually it gave me the correct coordinates)
I'm guessing this has to do with this:
//To perform a interactive selection or identify in 3D or 2D, sketch must be created in screen coordinates.
SketchOutputMode = SketchOutputMode.Screen;
Any ideas?
correct. Change SketchOutputMode to map.
That worked. Thanks again.
Just curious, then why does it say "//To perform a interactive selection or identify in 3D or 2D, sketch must be created in screen coordinates." if the identify still works?