Draw widget - graphics in undo stack?

509
3
Jump to solution
03-15-2019 09:49 AM
by Anonymous User
Not applicable

Question: How do I clear the undo stack from the Draw widget from a widget other than Draw itself?

I have 2 widgets, the OTB Draw widget and another widget that re-loads graphics (Save Session)

When loading a new session via my Save Session widget, it will first remove all graphics from the map, then reload the graphics from the session file. I have to clear the graphics, if I remove the layers outright, it puts Draw into a bad state. This all works fine and good. 

I run into problems when I try to reload session/graphics and go back and use the Draw widget. If I had already used Draw, made some graphics, loaded the new session, I end up in a state with the graphics from the session file on my screen (so far, working as expected). When I go back and use Draw and add a new graphic, I lose everything from my loaded session and the graphics that were previously created (but had been removed) show up again. I've verified that I've cleaned out all the graphics layers, the geometry is GONE. The only place they can be coming from is the undo/redo stack of the Draw widget. As I can walk through the Undo of all the graphics I created before I had loaded the session and "cleared" the graphics.

So I believe I need to clear the Draw's Undo stack or  completely re-load the Draw widget (assuming that would clear the stack).

Any ideas?

thanks

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Kevin,

   The Draw widget has a private property called _undoManager. so get the reference to the Draw widget then

DrawWidget._undoManager.clearUndo();
DrawWidget._undoManager.clearRedo();

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Kevin,

   The Draw widget has a private property called _undoManager. so get the reference to the Draw widget then

DrawWidget._undoManager.clearUndo();
DrawWidget._undoManager.clearRedo();
by Anonymous User
Not applicable

Thanks, Robert. This was helpful.

I really dont understand why, but the act of calling clearUndo would cause the graphics that Draw was hanging onto to be placed on the map.

I had to go to extreme lengths to clean out Draw:

        var DW = WidgetManager.getInstance().getWidgetsByName("Draw")[0];
        DW._graphicsLayer.graphics = [];
        DW._undoManager._historyStack = [];
        DW._undoManager.clearUndo();
        DW._undoManager.clearRedo();
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Strange. Glad you got it figured out though.

0 Kudos