Build a map identification tool

This tutorial demonstrates how to create an ArcGIS Pro add-in with a custom map identification tool.

With the ArcGIS Pro SDK for .NET, you can extend ArcGIS Pro with your own unique tools and workflows. Using Microsoft Visual Studio and the Pro SDK, developers can build Pro add-ins and solution configurations that provide users with custom functionality specific to their organization or industry.

In this tutorial, you will use C# to create a new map tool for feature identification which allows you to draw a circular selection area on the map and view the total number of features per feature layer found within the selection area.

Prerequisites

Steps

Create a new ArcGIS Pro Add-In Visual Studio Project

  1. Start Visual Studio.

  2. Choose File > New > Project and then from ArcGIS templates group, select ArcGIS Pro Module Add-in. Name the add-in project "MapToolIdentify".

    By default, the Config.daml file opens in Visual Studio. The Module1.cs file contains add-in module code.

    Note also in the Config.daml file that the id attribute of the insertModule tag matches the ID within the Module1.cs file and that the className attribute matches the class name of the module.

    The ArcGIS templates group is located in Templates > Visual C# > ArcGIS. Confirm that the latest .NET Framework is selected.

Create a new Pro map tool

  1. Right-click the project and choose Add > New Item and then from the ArcGIS Pro Add-ins group select ArcGIS Pro Map Tool from the list of item templates. Name the new class file IdentifyTool.cs and then click Add to close the dialog box.

    Once added, IdentifyTool.cs should open by default. The Map Tool template provides the contents of the class file as well as corresponding code in the Config.daml file for the ArcGIS Pro UI, so the tool can be activated. The Config.daml should be updated first.

  2. Open the Config.daml file and modify the tool item as shown in the following code:

    When you update the Config.daml, you change how the tool displays in the Create Features pane UI, providing helpful information to the user about the tool's name and purpose.

    • Change the caption to Identify Features.

    • Change the tooltip heading to Identify Features and the ToolTip text to Identify features on the current map using a circular sketch.

    Use dark colors for code blocksCopy
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
       <tool id="MapToolIdentify_IdentifyTool"
             caption="Identify Features"
             className="IdentifyTool"
             loadOnClick="true"
             smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed16.png"
             largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed32.png"
             condition="esri_mapping_mapPane">
          <tooltip heading="Identify Features">Identify features on the current map using a circular sketch.<disabledText /></tooltip>
       </tool>
  3. Compile and build the add-in project with Build > Build Solution.

  4. Once the build succeeds, click Start to start the debugger in ArcGIS Pro. When the ArcGIS Pro start page appears, select the previously-installed Pro SDK Community sample project: C:\\Data\\Interacting with Maps\\Interacting with Maps.aprx.

  5. Click the Add-In tab to confirm that your new map tool UI appears on the ribbon with the caption, tooltip, and the other modifications from step 4.

  6. Close ArcGIS Pro and stop debugging.

Create the identify map tool code and test

  1. Open the IdentifyTool.cs file and add the following using statements:

    Including the Framework assembly’s Threading.Tasks and Dialogs namespaces allows for easy coding with the QueuedTask and MessageBox classes.

    Use dark colors for code blocksCopy
      
    1
    2
       using ArcGIS.Desktop.Framework.Threading.Tasks;
       using ArcGIS.Desktop.Framework.Dialogs;
  2. Modify the IdentifyTool() constructor as follows:

    These changes allow you to use the tool in a 3D scene as well as a 2D map.

    • Ensure IsSketchTool is set to true

    • Change SketchType to SketchGeometryType.Circle

    • Change SketchOutputMode to SketchOutputMode.Screen

    Use dark colors for code blocksCopy
          
    1
    2
    3
    4
    5
    6
       public IdentifyTool()
       {
             IsSketchTool = true;
             SketchType = SketchGeometryType.Circle;
             SketchOutputMode = SketchOutputMode.Screen;
       }
  3. Modify the OnSketchCompleteAsync as follows, adding the async keyword to the method declaration:

    The OnSketchCompleteAsync method is found at the bottom of the IdentifyTool class.

    Use dark colors for code blocksCopy
                          
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
       protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
       {
             var mv = MapView.Active;
             var identifyResult = await QueuedTask.Run(() =>
             {
                var sb = new StringBuilder();
    
                // Get the features that intersect the sketch geometry.
                var features = mv.GetFeatures(geometry);
    
                // Get all layer definitions.
                var lyrs = mv.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
                foreach (var lyr in lyrs)
                {
                   var fCnt = features.ToDictionary().ContainsKey(lyr) ? features[lyr].Count : 0;
                   sb.AppendLine($@"{fCnt} {(fCnt == 1 ? "record" : "records")} for {lyr.Name}");
                }
                return sb.ToString();
             });
             MessageBox.Show(identifyResult);
             return true;
       }
  4. Rebuild your solution and fix any compilation errors. Click Start to start the debugger in ArcGIS Pro. Open the same Interacting with Maps.aprx project from the previous step.

  5. Zoom in on an area of the map containing features from the different feature layers to confirm that your new Identify tool functions as expected. Click and hold to define the center point of your selection circle, and drag away to define the radius. Once you release the mouse button, a message box should appear with the number of visible features found within the circle you defined.

    Your identify tool will only return features that are both visible and selectable, as defined in the Contents pane for List By Drawing Order and List By Selection.

What's Next?

Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.