Select to view content in your preferred language

Issue Combining ProSnippets for arcgis pro sdk

1161
4
01-17-2019 09:53 AM
KarenRobbins
Occasional Contributor

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)

Create a tool to the return coordinates of the point clicked in the map

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");

        });

    }

}

 

Create a tool to identify the features that intersect the sketch geometry

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;

        });

    }

}

0 Kudos
4 Replies
CharlesMacleod
Esri Regular Contributor

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;

KarenRobbins
Occasional Contributor

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?

0 Kudos
CharlesMacleod
Esri Regular Contributor

correct. Change SketchOutputMode to map.

KarenRobbins
Occasional Contributor

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?

0 Kudos