无法为使用 ArcGIS 的移动/缩放/旋转添加正确的撤消/重做操作



我有以下代码,当图形被移动时,我正在读取(缩放和旋转使用类似的代码)。

//Obtaining the graphic before it is moved
moveToolbar.on("graphic-move-start", function (evt) {
oldGraphicMove = evt.graphic;
});
//Updating the graphic on move end
moveToolbar.on("graphic-move-stop", function (evt) {
  //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: [evt.graphic] //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);

});

由于

某种原因,之前的旧图形始终与之后的新图形保持相等,因此在添加操作时,由于图形在前后标记为相等,因此无需撤消/重做。

我不知道我可能做错了什么,对此有什么线索吗?

显然,编辑开始时的 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);
                                                    });
撤消/重做

移动仍然存在一些问题,但是此方法适用于撤消/重做缩放和旋转。

最新更新