User drawn rectangle doesn't persist on map after mouse-up

166
3
Jump to solution
2 weeks ago
TyroneLigon1
New Contributor III

I apologize in advance - the code is running on an intranet, and I can't copy/paste.

I have a dockpane with a button mapped to a rectangle tool. The user uses the tool to drag a rectangle on the map. When the user completes the rectangle via mouse-up, the rectangle disappears from the map.

Do I need to create a graphic from the geometry created by the tool and add it to the map's graphic layer?

In my map rectangle tool class, I initialize with:

  • IsSketchTool = true;
  • CompleteSketchOnMouseUp = true;
  • SketchType = SketchGeometryType.Rectangle;
  • sketchOutputMode = SketchOutputMode.Map;

The rectangle extent parameters are then used to open a web page via another button on the dockpane.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

EDIT: lol - well, after just finishing writing this reply it struck me that maybe it is _not_ the "show selection graphic behavior" that you are after! Somewhat presumptive on my part, apologies - that said, just in case, and/or if someone else _is_ (who reads this post) I will leave my reply...and we will still add this to the SelectionEnvironment at 3.4.

 

it looks like this was never exposed in the selection environment public api - https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14140.html

What you are looking for is the equivalent to the "Display the interactive selection graphic" checkbox on the Application selection settings UI.

I will pass this on to the dev team for 3.4.

In the meanwhile, this will work (but requires use of an internal namespace) - maybe do this in the tool activate and set it back to the previous setting when your tool is deactivated - your call.

 

 

//fyi
using ArcGIS.Desktop.Internal.Mapping;
...

internal class MySelectionTool : .... {
 ...

  public void SetShowInteractiveSelectionGraphic(bool showGraphic) {
    var map_module_internal =
        FrameworkApplication.FindModule("esri_mapping") as 
              IInternalMappingModule;
    //Must be called on the QueuedTask! or will throw 
    //CalledOnWrongThreadException
    map_module_internal.SelectionSettings.
       SetShowInteractiveSelectionGraphic(showGraphic);
  }

  public bool GetShowInteractiveSelectionGraphic()
  {
    var map_module_internal =
        FrameworkApplication.FindModule("esri_mapping") as 
             IInternalMappingModule;
    //should be fine being called from the UI thread
    return map_module_internal.SelectionSettings.
                      ShowInteractiveSelectionGraphic;
  }
  ...


   //usage
   internal bool _keepShowSelectionGraphicSetting = false;

   //somewhere - perhaps tool activation
   QueuedTask.Run(() => {
      _keepShowSelectionGraphicSetting = 
              this.GetShowInteractiveSelectionGraphic();
      if (!_keepShowSelectionGraphicSetting)
         this.SetShowInteractiveSelectionGraphic(true);
      ...
   });

   //somewhere - perhaps tool deactivation
   QueuedTask.Run(() => {
      if (_keepShowSelectionGraphicSetting != 
              this.GetShowInteractiveSelectionGraphic())
         this.SetShowInteractiveSelectionGraphic(
                         _keepShowSelectionGraphicSetting);
      ...
   });

 

 

 

 

 

 

 

View solution in original post

0 Kudos
3 Replies
CharlesMacleod
Esri Regular Contributor

EDIT: lol - well, after just finishing writing this reply it struck me that maybe it is _not_ the "show selection graphic behavior" that you are after! Somewhat presumptive on my part, apologies - that said, just in case, and/or if someone else _is_ (who reads this post) I will leave my reply...and we will still add this to the SelectionEnvironment at 3.4.

 

it looks like this was never exposed in the selection environment public api - https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14140.html

What you are looking for is the equivalent to the "Display the interactive selection graphic" checkbox on the Application selection settings UI.

I will pass this on to the dev team for 3.4.

In the meanwhile, this will work (but requires use of an internal namespace) - maybe do this in the tool activate and set it back to the previous setting when your tool is deactivated - your call.

 

 

//fyi
using ArcGIS.Desktop.Internal.Mapping;
...

internal class MySelectionTool : .... {
 ...

  public void SetShowInteractiveSelectionGraphic(bool showGraphic) {
    var map_module_internal =
        FrameworkApplication.FindModule("esri_mapping") as 
              IInternalMappingModule;
    //Must be called on the QueuedTask! or will throw 
    //CalledOnWrongThreadException
    map_module_internal.SelectionSettings.
       SetShowInteractiveSelectionGraphic(showGraphic);
  }

  public bool GetShowInteractiveSelectionGraphic()
  {
    var map_module_internal =
        FrameworkApplication.FindModule("esri_mapping") as 
             IInternalMappingModule;
    //should be fine being called from the UI thread
    return map_module_internal.SelectionSettings.
                      ShowInteractiveSelectionGraphic;
  }
  ...


   //usage
   internal bool _keepShowSelectionGraphicSetting = false;

   //somewhere - perhaps tool activation
   QueuedTask.Run(() => {
      _keepShowSelectionGraphicSetting = 
              this.GetShowInteractiveSelectionGraphic();
      if (!_keepShowSelectionGraphicSetting)
         this.SetShowInteractiveSelectionGraphic(true);
      ...
   });

   //somewhere - perhaps tool deactivation
   QueuedTask.Run(() => {
      if (_keepShowSelectionGraphicSetting != 
              this.GetShowInteractiveSelectionGraphic())
         this.SetShowInteractiveSelectionGraphic(
                         _keepShowSelectionGraphicSetting);
      ...
   });

 

 

 

 

 

 

 

0 Kudos
TyroneLigon1
New Contributor III

I am getting the result I was expecting - the user drags a rectangle on the map, and the rectangle remains after the user finishes the drag operation. I now have to extract the rectangle's extent, and provide an option to remove the rectangle from the map, which I will address in another post. Thanks!

0 Kudos
CharlesMacleod
Esri Regular Contributor

Tyrone, I stand corrected - i did a bit of digging  and this is in the public api:

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14160.html 

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14152.html

So, u shld be able to do SelectionEnvironment.SetShowSelectionGraphic(true | false). SelectionEnvironment.ShowSelectionGraphic will give u the current "show graphic" value. "SetShowSelectionGraphic" must be called on the MCT via QueuedTask.Run.

 

SelectionEnvironment is a static class within ArcGIS.Desktop.Mapping

0 Kudos