I’m having a problem handling leaving the Editor Widget when a feature is selected. I’ve built an API that allows users to switch to ‘edit mode’. When this happens the selected Feature Layer is added to the map and the Editor Widget (already added) automatically detects the new Feature Layer and presents the user with all the Widget tools. This works great.
The problem is that users can choose to move away from the Editor Widget at any point, effectively giving up on what they were doing and returning to use the API for some other purpose, in other words exiting editing mode. I’ve got most of this handled successfully using myEditor.cancelWorkflow() . If they decide to discard their editing when drawing a new feature for example, then cancelWorkflow() works perfectly. I’m detecting what the user was currently doing with myEditor.viewModel.state. For example, when they are drawing a new feature, the state is “creating-features”, and I can then use cancelWorkflow() to discard what they were doing and follow that up with removing the Feature Layer that had been added to the map - works great. However, the problem occurs when they select an existing feature for editing its shape or attributes, in this instance the viewModel state is “editing-attributes”, and when I try to do cancelWorkflow() I get the error “view:no-layerview-for-layer”.
I’ve tried to do my best to understand the API reference for a solution, but to no avail. Interestingly, the cancelling of the edit session using cancelWorkflow() appears to work when the state is “editing-attributes” in that the selected feature is de-selected and the sketching graphics are removed (e.g. the points highlighting the vertices), but the error mentioned above is thrown and I’d like to do things properly and not get this error message.
I hope that’s clear? Can anyone please suggest a solution, or the correct way to cancel the current editing process the user is doing? I don’t want to destroy the Editor Widget completely, I want it to remain because the user might want to do more editing, I just need to end their current workflow without it throwing the error I see for the “editing-attributes” state.
Thank you.