无法使用 arcgis 为 move/scale/rotate 添加正确的 undo/redo 操作
Unable to add a correct undo/redo operation for move/scale/rotate using 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);
});
出于某种原因,之前的旧图形始终与之后的新图形保持相等,因此当添加操作时,undo/redo 没有任何内容,因为图形被标记为前后相等。
我不知道我做错了什么,有什么线索吗?
显然,编辑开始时的 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);
});
undoing/redoing 移动仍然存在一些问题,但是此方法适用于 undoing/redoing 缩放和旋转。
我有以下代码,在移动图形时我正在阅读这些代码(缩放和旋转使用类似的代码)。
//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);
});
出于某种原因,之前的旧图形始终与之后的新图形保持相等,因此当添加操作时,undo/redo 没有任何内容,因为图形被标记为前后相等。
我不知道我做错了什么,有什么线索吗?
显然,编辑开始时的 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);
});
undoing/redoing 移动仍然存在一些问题,但是此方法适用于 undoing/redoing 缩放和旋转。