Select to view content in your preferred language

Handle discard for map tool

662
4
08-10-2023 08:17 AM
CarlosK
Emerging Contributor

Hi,

In my map tool, there is another map tool inside it for selecting different features just like in many custom tools in Pro for map selection. And then it also contains other controls for my map tool. By default when my tool is opened this map selection tool is made active therefore when my tool is opened map selection tool will always be active. After my actual tool executed its work data is in edit and also same data is reflected in my tool’s UI. But what if user instead of save ,will discard the changes.  So I can subscribe to EditCompletedEvent and check if operation type is discard then I will come to know discard button is pressed. Now what I want is to update the UI again as per the map selection at that time and those new edited changes should be removed from the UI.

I thought that I will check  if the active tool is my tool on discard and then process the load of my tool once again based on the map selection and it will update the UI by removing the edit changes. But the problem is when my tool is opened it can never be the active tool since map selection tool inside my tool will be active tool always.

Can someone guide me how to handle discard in this scenario so that UI should be updated?

@Wolf @GKmieliauskas @UmaHarano  @CharlesMacleod 

Tags (1)
0 Kudos
4 Replies
CarlosK
Emerging Contributor

any suggestion @Wolf @CharlesMacleod 

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

Your tool pattern seems to be too complex. I suggest you to write your own tool for map selection using MapTool or EmbeddableControl.

Take a look to that thread

0 Kudos
CarlosK
Emerging Contributor

@GKmieliauskas The selection tool which I am using inside my map tool is also created by me only. But the challenge is how to catch discard happened while my tool was being used. I cant use active tool to check which tool is in use because  whenever my custom map tool is being used Active tool will always be my custom map selection tool used inside my custom map tool.

0 Kudos
GKmieliauskas
Esri Regular Contributor

If you are using EditOperation set your EditOperation EventToken for further checking in EditCompletedEvent EventToken.

  // in your MapTool class
  SubscriptionToken _yourOperationEventToken = null;




  // in subscribe to EditCompletedEvent place
  _yourOperationEventToken =   EditCompletedEvent.Subscribe(onEditCompleted);




  // in create EditOperation place
  EditOperation op = new EditOperation();
  op.EventToken = _yourOperationEventToken;

 

private Task OnEditCompleted(EditCompletedEventArgs args)
        {
            switch (args.CompletedType)
            {
            case EditCompletedType.Save:
                break;

            case EditCompletedType.Discard:
                if(args.EventToken == _yourOperationEventToken) {
                    // your tool operation discarded
                }
                break;

            case EditCompletedType.Operation:
                break;

            case EditCompletedType.Undo:
            case EditCompletedType.Redo:
                break;

            case EditCompletedType.Reconcile:
                break;

            case EditCompletedType.Post:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }

 

 

 

0 Kudos