我有以下代码,当我移动图形时我正在阅读(缩放和旋转使用类似的代码)。
//在移动之前获取图形moveToolbar.on(“graphic-move-start”,…
显然,编辑开始时的oldGraphicMove变量被编辑结束的evt.graphic覆盖。这是通过在编辑图形之前创建具有图形规范的新图形而不是将图形直接分配给变量来解决的:
//Obtaining the graphic before it is scaled moveToolbar.on("scale-first-move", function (evt) { oldGraphicScale = new esri.Graphic(evt.graphic.geometry,evt.graphic.symbol,evt.graphic.attributes); }); //Updating the graphic on scale end moveToolbar.on("scale-stop", function (evt) { newGraphicScale = new esri.Graphic(evt.graphic.geometry, evt.graphic.symbol, evt.graphic.attributes); //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: [oldGraphicScale], //The graphic before the changes are created postUpdatedGraphics: [newGraphicScale] //The graphic after the changes are made }); //Adding the undo/redo operation undoManager.add(operation); //Updating the graphic evt.graphic._graphicsLayer.applyEdits(null, [evt.graphic], null); });
撤消/重做移动仍然存在一些问题,但此方法适用于撤消/重做缩放和旋转。