Undo edits of existing graphics using UndoManager

2968
5
01-21-2016 12:31 PM
VygintasCesnauskas
New Contributor III

Hi,

I am looking for a way to undo edits such as move, scale and rotate of existing graphics on the map. So far I've tried to undo it in the same way as we currently undo 'draw' operations:

            var editToolbar = new Edit(map);
            editToolbar.on("scale-stop, vertex-move-stop", function (evt) {
                var operation = new CustomOperation.Add({
                    graphicsLayer: selectedGraphicsLayer,
                    addedGraphic: evt.graphic
                });


                undoManager.add(operation);
            });

However this undoes the action that happened directly previous to the 'edit', which in our case was 'draw' and removes the graphic from the map. Am I missing something or should I be using a different method altogether?

I'm using following classes:

Edit - Edit | API Reference | ArcGIS API for JavaScript

UndoManager - UndoManager | API Reference | ArcGIS API for JavaScript 

0 Kudos
5 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Vygintas, Have you tried to look up this sample? https://developers.arcgis.com/javascript/jssamples/graphics_undoredo.html

0 Kudos
VygintasCesnauskas
New Contributor III

Hi Yue,

Unfortunately the example you're referring to performs undo on a draw of a new graphic. I am looking to undo an edit to an existing graphic.

0 Kudos
TimWitt2
MVP Alum

I have a feeling this can't be done with the undo manager.

Maybe what you can do is, save the current graphic, once it has been edited and you don't like the current graphic, delete it and add the saved graphic?

VygintasCesnauskas
New Contributor III

Hi Tim,

That's a good idea, if undo manager for sure cannot be used in this case, I will go ahead with your suggestion. Perhaps Yue or someone else from ESRI staff could confirm this?

0 Kudos
TracySchloss
Frequent Contributor

I just have points, and it works to undo a move.  There'd be no scale or rotate with those, though.  I was disappointed to see that undo/redo didn't include attribute changes.