1

The following code is what I am using to get the graphics to be added to the update operation:

 //Obtaining the graphic before it is moved
 moveToolbar.on("graphic-move-start", function (evt) {
 //Storing the original geometry in a json string - else it keeps changing
 json1 = JSON.stringify(evt.graphic.geometry);
 });

 //Updating the graphic on move end
 moveToolbar.on("graphic-move-stop", function (evt) {

//Getting the old geometry and converting it back into an object
var obj = JSON.parse(json1);

//Creating the previously created graphic. All the below are needed else the Update operation does not accept it
 oldGraphicMove = new esri.Graphic();
 oldGraphicMove.geometry = JSON.parse(JSON.stringify(evt.graphic.geometry));
 oldGraphicMove.symbol = undefined;
 oldGraphicMove.attributes =JSON.parse(JSON.stringify(evt.graphic.attributes));
 oldGraphicMove._count = JSON.parse(JSON.stringify(evt.graphic._count));
 oldGraphicMove._extent = JSON.parse(JSON.stringify(evt.graphic._extent));
 oldGraphicMove._graphicsLayer = evt.graphic._graphicsLayer;
 oldGraphicMove._layer = evt.graphic._layer;
 oldGraphicMove._offsets = evt.graphic._offsets;
 oldGraphicMove._shape = evt.graphic._shape;

 //Changing the value of the oldGraphicMove object to the values of the graphic before it was moved
 for (var z = 0; z < obj.rings[0].length; z++)
 {
  oldGraphicMove.geometry.rings[0][z] = obj.rings[0][z];
 }
 newGraphicMove = evt.graphic;

 //Creating the operation to add to the undomanager
  var operation = new Update({
        featureLayer: evt.graphic._graphicsLayer, //The layer that will contain the modified graphic
        preUpdatedGraphics: [oldGraphicMove], //The graphic before the changes are created
        postUpdatedGraphics: [newGraphicMove] //The graphic after the changes are made
       });

 //Adding the undo/redo operation
undoManager.add(operation);

 json1 = {};
 json2 = {};

 //Updating the graphic

 evt.graphic._graphicsLayer.applyEdits(null, [evt.graphic], null);
});

However on the part of var operation = new update the following error is thrown:

Uncaught TypeError: a.preUpdatedGraphics[b].geometry.toJson is not a function
at Object.constructor (Update.js:4)
at new <anonymous> (init.js:108)
at Object.<anonymous> (eGISEditing.js:1141)
at Object.<anonymous> (init.js:1191)
at Object.h [as onGraphicMoveStop] (init.js:244)
at Object._moveStopHandler (_GraphicMover.js:9)
at Object.<anonymous> (init.js:177)
at Object.h [as onMoveStop] (init.js:244)
at Object.destroy (Mover.js:3)
at HTMLDocument.<anonymous> (init.js:177)

I have been through both passed graphics and all geometry is present within them, and as a result I am unable to determine how to resolve this issue.

1

I managed to find a solution after weeks of experimenting, hopefully this will help someone else.

This first part of the code stored the original graphic

//Obtaining the graphic before it is moved
moveToolbar.on("graphic-move-start", function (evt) {
//Storing the original geometry in a json string - else it keeps changing
json1 = JSON.stringify(evt.graphic.geometry);
});

This consists of the new graphic and the process to add to the undo manager

//Updating the graphic on move end
moveToolbar.on("graphic-move-stop", function (evt) {

//Getting the old geometry and converting it back into an object
 var obj = JSON.parse(json1);

//Creating the previously created graphic. All the below are needed else the Update operation does not accept it
//Basically you are taking the individual attributes from the json string and applying them to the oldgraphicMove object in order to create a new identical graphic

oldGraphicMove = new esri.Graphic();
oldGraphicMove.geometry = JSON.parse(JSON.stringify(evt.graphic.geometry));
oldGraphicMove.symbol = undefined;
oldGraphicMove.attributes=JSON.parse(JSON.stringify(evt.graphic.attributes));                                    
oldGraphicMove._count = JSON.parse(JSON.stringify(evt.graphic._count));                                 
oldGraphicMove._extent = JSON.parse(JSON.stringify(evt.graphic._extent));                            
oldGraphicMove._graphicsLayer = evt.graphic._graphicsLayer;
oldGraphicMove._layer = evt.graphic._layer;
oldGraphicMove._offsets = evt.graphic._offsets;
oldGraphicMove._shape = evt.graphic._shape;

if (obj.rings != undefined) {
//Changing the value of the oldGraphicMove object to the values of the graphic before it was moved
for (var z = 0; z < obj.rings[0].length; z++) {

oldGraphicMove.geometry.rings[0][z] = obj.rings[0][z];
}
}
else
if (obj.paths != undefined)
{
 //Changing the value of the oldGraphicMove object to the values of the graphic before it was moved
for (var z = 0; z < obj.paths[0].length; z++) {

  oldGraphicMove.geometry.paths[0][z] = obj.paths[0][z];
  }
  }                                                     
oldGraphicMove.geometry.__proto__ = evt.graphic.geometry.__proto__;

oldGraphicMove.geometry.spatialReference = 
evt.graphic.geometry.spatialReference;

newGraphicMove = evt.graphic;

 //Creating the operation to add to the undomanager
var operation = new Update({
featureLayer: evt.graphic._graphicsLayer, //The layer that will contain the modified graphic
preUpdatedGraphics: [oldGraphicMove], //The graphic before the changes are created
postUpdatedGraphics: [newGraphicMove] //The graphic after the changes are made
});

//Adding the undo/redo operation
undoManager.add(operation);

json1 = {};
json2 = {};

//Updating the graphic

evt.graphic._graphicsLayer.applyEdits(null, [evt.graphic], null);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.