AnsweredAssumed Answered

Error adding the move graphic functionality to the undomanager

Question asked by nalydleetlub1 on Jun 6, 2017

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 objectvar 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 operationundoManager.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 functionat 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.

Outcomes