Overview

You will learn: 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 configurations that provide users with custom functionality specific to their organization or industry.

In this lab, you will use C# to create a new map tool for feature identification which will allow 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.

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".

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 press Add to close the dialog box.

  2. Open the Config.daml file and modify the tool item as follows:

       <tool id="MapToolIdentify_IdentifyTool"
             caption="Identify Features"
             className="IdentifyTool"
             loadOnClick="true"
             smallImage="Images\GenericButtonRed16.png"
             largeImage="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 using Build > Build Solution. Once the build succeeds, start the debugger by clicking Start which will start ArcGIS Pro. When the Pro start page appears, select the previously-installed Pro sample project: "C:\Data\Interacting with Maps\Interacting with Maps.aprx".

  4. Confirm that your new add-in's map tool UI is working by clicking the Add-In tab and check to see that your tool appears on the ribbon with the caption, tooltip, and other updates from step 4 above. 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:

    using ArcGIS.Desktop.Framework.Threading.Tasks;
    using ArcGIS.Desktop.Framework.Dialogs;
    
  2. Modify the IdentifyTool() constructor as follows:

         public IdentifyTool()
         {
             IsSketchTool = true;
             SketchType = SketchGeometryType.Circle;
             SketchOutputMode = SketchOutputMode.Screen;
         }
    
  3. Modify the OnSketchCompleteAsync method by copying or typing in the following code, and adding the "async" keyword to the method declaration:

         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.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 begin debugging which will start ArcGIS Pro. Open the same "Interacting With Maps" project from the earlier step.

  5. Zoom in on an area of the map containing features from the different feature layers and try your new Identify tool – click and hold to define a center point of your selection circle, and dragging 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.

Congratulations, you're done!

Check out and compare with our completed solution project.

Challenge

Review the online documentation

Read more information about map tools in the ProConcepts Map Exploration document, and also review the many Map Tools ProGuides listed on the main documentation page under the Map Exploration > Map Tools topic section along the right-hand margin.

Review the API reference

Review the Pro SDK API reference and find the MapTool class for more information, methods and additional behavior.

Try community samples

Download and try the many Map Exploration community samples which use map tools for feature identification, selection and more.