Select to view content in your preferred language

How can I create a custom select tool that has the same behavior as the default ArcGIS Pro select tool on the Edit tab/ribbon?

4023
7
Jump to solution
06-02-2021 11:39 AM
VidmasKondratas
Esri Contributor

I need to create a custom polygon select tool in Pro that has the same behavior as the default rectangle select tool in ArcGIS Pro. The default behavior is the if you click once, the polygon will be selected (multiple polygons with Shift key pressed down); if you click and drag, you select by rectangle. (Similar to the old IRubberBand in Arc Objects). I cannot figure out how to emulate this behavior using the Pro SDK. I’ve developed a custom point select tool with the Shift multi select behavior using

SketchType = SketchGeometryType.Point;
public bool IsShiftKey()
{
  return (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift));
}
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
  Key keyboardKey = Key.None;
  if(IsShiftKey())
  {
    keyboardKey = Key.LeftShift;
  }
  SIPAS.Events.SketchGeometryUpdatedEvent.Publish(new SIPAS.Events.SketchGeometryUpdatedEventArgs(this, geometry, keyboardKey));
  return base.OnSketchCompleteAsync(geometry);
}       

But this does not let you select by rectangle by dragging. If I use

SketchType = SketchGeometryType.Rectangle;

I cannot multiselect by click or Shift click. I have to click twice to create a rectangle to select a single polygon (which my customer is highly annoyed by).

How can I create a custom select tool that has the same behavior as the default Pro select tool on the Edit tab/ribbon?

0 Kudos
2 Solutions

Accepted Solutions
KrisCulin
Frequent Contributor

This is a complicated answer.  We ran into the same issue when developing our configuration.  It took a lot of effort to figure out the right combination of flags and event handlers to make it work.

Here is a basic summary of what we did.

In the constructor

  • IsSketchTool = true
  • SketchType = Rectangle
  • SketchOutputMode = Screen
  • CompleteSketchMouseUp = true
  • ContextMenuID = set it to the appropriate name you are using (should match that in the Config.daml file)

In the OnSketchCompleteAsync method:

  • Before using the QueuedTask, determine if the shift or CTRL key is depressed.  We have a library method that determines this.
    • If shift is depressed, then flag the selection mode as add.
    • If control is depressed, then flag the selection mode is remove.
  • Cast the geometry parameter to Polygon and check if Area is 0.  If this value is 0, then there was a single point click and not a drag to create a rectangle.
  • If the Area is not 0, then use the appropriate calls to get the features within the geometry area.  We have a library method we wrote that does this (it is used in a lot of places) but it is specific to our API so it can't be shared.  But it does use the standard AGP SDK API.  There are plenty of examples of how to do this.
    • Based on the selection mode, add or remove the features that intersect with the geometry to/from the current selection.

I hope that helps.

Kris

View solution in original post

by Anonymous User
Not applicable

You can define a launcher button for your group in the daml that replicates the launcher on the selection group.

SeanJones_1-1623371341465.png

SeanJones_2-1623371456940.png

 

View solution in original post

7 Replies
KrisCulin
Frequent Contributor

This is a complicated answer.  We ran into the same issue when developing our configuration.  It took a lot of effort to figure out the right combination of flags and event handlers to make it work.

Here is a basic summary of what we did.

In the constructor

  • IsSketchTool = true
  • SketchType = Rectangle
  • SketchOutputMode = Screen
  • CompleteSketchMouseUp = true
  • ContextMenuID = set it to the appropriate name you are using (should match that in the Config.daml file)

In the OnSketchCompleteAsync method:

  • Before using the QueuedTask, determine if the shift or CTRL key is depressed.  We have a library method that determines this.
    • If shift is depressed, then flag the selection mode as add.
    • If control is depressed, then flag the selection mode is remove.
  • Cast the geometry parameter to Polygon and check if Area is 0.  If this value is 0, then there was a single point click and not a drag to create a rectangle.
  • If the Area is not 0, then use the appropriate calls to get the features within the geometry area.  We have a library method we wrote that does this (it is used in a lot of places) but it is specific to our API so it can't be shared.  But it does use the standard AGP SDK API.  There are plenty of examples of how to do this.
    • Based on the selection mode, add or remove the features that intersect with the geometry to/from the current selection.

I hope that helps.

Kris

VidmasKondratas
Esri Contributor

I marked this as the solution because it answered my question and it works. Thanks, it was very helpful. However, the implementation is complicated. To keep it more standard, the customer agreed to a combination of the Pro SDK Tool select behavior in combination with the standard Pro Select tool as Wolf mentioned (with programmatically turning off selectable layers in conjunction with the OnMapSelectionChanged(MapSelectionChangedEventArgs args) event). This also satisfies my customers requirements. Thanks again.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can also reuse the existing ArcGIS Pro tools (and commands) in your add-in without having to re-create the code.  You can find information on reusing Pro commands here:

ProGuide Reusing Pro Commands Esri/arcgis-pro-sdk Wiki (github.com)

And the following video from the last dev summit demonstrates how to re-use Pro commands in your dockpane. (446) ArcGIS Pro SDK for .NET: Practical Dockpane Design and Implementation - YouTube  You have to advance the video to 35:30 for the relevant information.

VidmasKondratas
Esri Contributor

I reuse tools that I can but I need a customized implementation of select to meet my customers requirements.

0 Kudos
VidmasKondratas
Esri Contributor

So I have a tab group with my custom selection tools and an "Advanced Selection" group with the default Esri selection tools (which are actually working with a highly customized Pro Window). This combination is acceptable to the customer. One question however with the "Selection Options" button. Is there a way in the DAML where I can get the graphic used in the out-of-the-box button instead of the "Select Options" text on my button?

 

<group id="Esri_Selection_Group" caption="Advanced Selection" keytip="Z0">
  <toolPalette refID="esri_mapping_selectToolPalette"/>
  <tool refID="esri_editing_ShowAttributes" size="middle" />
  <tool refID="esri_mapping_clearSelectionButton" size="middle" />
  <button refID="esri_mapping_openSelectionOptionsButton" size="middle" />
</group>

 

 

<button refID="esri_mapping_openSelectionOptionsButton" size="middle" />

 

My "Selection Options" button:

VidmasKondratas_1-1623365346048.png

Out-of-the-Box "Selection Options" button:

VidmasKondratas_2-1623365561855.png

I don't want to use this group because I don't need "Select By Location" or "Select By Attribute" and cannot change the name of the group (to my knowledge):

 

<group refID="esri_mapping_selectionGroup"></group>

 

 

 

0 Kudos
by Anonymous User
Not applicable

You can define a launcher button for your group in the daml that replicates the launcher on the selection group.

SeanJones_1-1623371341465.png

SeanJones_2-1623371456940.png

 

VidmasKondratas
Esri Contributor

Thanks!

<group id="Esri_Selection_Group" caption="Advanced Selection" keytip="Z0" launcherButtonID="esri_mapping_openSelectionOptionsButton">
  <toolPalette refID="esri_mapping_selectToolPalette"/>
  <tool refID="esri_editing_ShowAttributes" size="middle" />
  <tool refID="esri_mapping_clearSelectionButton" size="middle" />
</group>

VidmasKondratas_0-1623374884320.png

 

0 Kudos