AnsweredAssumed Answered

MapTool Detect Clear Selection Click

Question asked by mjk5000 on Jul 24, 2018
Latest reply on Aug 2, 2018 by wkaiser-esristaff

I have a MapTool that will only be activated (OnToolActivateAsync) when one, and only one feature is selected.  Then when the user finishes their sketch, the one and only selected item will have some work done to it (OnSketchCompleteAsync).

 

The problem that I find, is that after you activate the tool, if you click on the Clear Selection button, my map tool doesn't deactivate, so the validation of a selected item is no longer valid.  i would either like my tool to deactivate when the Clear button is pressed, or have a way to catch the button being clicked from my maptool, and have the validation rerun.  I have tried OnSelectionChangedAsync but that doesn't seem to catch the clear selection, as my tool is a sketch tool. 

 

Here is my Activate Function that has the line to CheckForValidSelection.  But after the tool is activated, I have no way of catching the selection clear button.

 

protected async override Task OnToolActivateAsync(bool hasMapViewChanged)
        {
            try
            {
                //this checks the map for only one feature selected and warns user if failed
                bool validCheck = await CheckForValidSelection();

                //Exist if one thing and one thing only is not selected
                if (!validCheck) return;

                //Setup the line symbol/snapping/tracing
                if (_lineSymbol == null)
                {
                    _lineSymbol = await CreateLineSymbolAsync();
                }

                SketchSymbol = _lineSymbol.MakeSymbolReference();

                //General Snapping
                Snapping.IsEnabled = true;
                Snapping.SetSnapMode(SnapMode.Edge, true);
                Snapping.SetSnapMode(SnapMode.End, true);
                Snapping.SetSnapMode(SnapMode.Intersection, true);

                //Set the command to Trace, possible bug as we have to set it then set it again
                ICommand _trace = FrameworkApplication.GetPlugInWrapper("esri_editing_TraceConstructor") as ICommand;
                _trace.Execute(null);
                _trace = FrameworkApplication.GetPlugInWrapper("esri_editing_LineConstructor") as ICommand;
                _trace.Execute(null);
                _trace = FrameworkApplication.GetPlugInWrapper("esri_editing_TraceConstructor") as ICommand;
                _trace.Execute(null);
            }
            catch (Exception e)
            {
                LogError("OnToolActivateAsync", e);
            }
        }

Outcomes