gpt4 book ai didi

javascript - 如何使用 arcgis javascript 顶点 undoManager

转载 作者:行者123 更新时间:2023-11-27 22:56:35 25 4
gpt4 key购买 nike

我尝试使用 undomanager 撤消/重做编辑顶点。

图形对象经过测试。但我不知道该怎么做编辑顶点撤消/重做。

顶点是否可以撤消/重做?

我找了很多例子都没有找到答案。

我是韩国初学者程序员。帮帮我吧~ T.T

   function initEditing(evt) {
console.log("initEditing", evt);
var currentLayer = null;
var layers = arrayUtils.map(evt.layers, function(result) {
return result.layer;
console.log("result ==== "+result);
});
console.log("layers", layers);

editToolbar = new Edit(map);
editToolbar.on("deactivate", function(evt) {
console.log("deactivate !!!! ");
currentLayer.applyEdits(null, [evt.graphic], null);
});

arrayUtils.forEach(layers, function(layer) {
var editingEnabled = false;
layer.on("dbl-click", function(evt) {
event.stop(evt);
if (editingEnabled === false) {
editingEnabled = true;
editToolbar.activate(Edit.EDIT_VERTICES , evt.graphic);
pre_evt = evt.graphic;
editToolbar.on("vertex-move-stop", function(evt){
console.log("vertex-move-stop~");
g_evt = evt;
console.log("evt.transform ===== " +evt.transform);
var operation = new esri.dijit.editing.Update({
featureLayer : landusePointLayer,
preUpdatedGraphics:pre_evt,
postUpdatedGraphics: evt.graphic
})
var operation = new CustomOperation.Add({
graphicsLayer: pre_evt._graphicsLayer,
addedGraphic: evt.graphic
});
undoManager.add(operation);
console.log("operation ======== ",operation);
});

console.log("dbl-click & eidt true");
} else {
currentLayer = this;
editToolbar.deactivate();
editingEnabled = false;
console.log("dbl-click & eidt false ");
}
});

最佳答案

您所引用的示例只是让您了解如何使用 UndoManager。如果需要对顶点进行撤消/重做,则需要创建自己的操作。下面我为 AddVertex 提供了一个。您需要为其他操作创建自己的。

define(["dojo/_base/declare",  
"esri/OperationBase"],
function(declare,
OperationBase) {

var customOp = {};

customOp.AddVertex = declare(OperationBase, {
label: "Add Vertex",
_editedGraphic: null,
_vertexInfo: null,
_vertex: null,
_editTool: null,

constructor: function (params) {
params = params || {};

if (!params.editTool) {
console.error("no edit toolbar provided");
return;
}
this._editTool = params.editTool;

if (!params.editedGraphic) {
console.error("no graphics provided");
return;
}
this._editedGraphic = params.editedGraphic;

if (!params.vertexinfo) {
console.error("no vertexinfo provided");
return;
}
this._vertexInfo = params.vertexinfo;

var geometry = this._editedGraphic.geometry;
if(geometry.type === "multipoint") {
this._vertex = geometry.getPoint(this._vertexInfo.pointIndex);
} else if(geometry.type === "polyline" || geometry.type === "polygon") {
this._vertex = geometry.getPoint(this._vertexInfo.segmentIndex, this._vertexInfo.pointIndex);
} else {
console.error("Not valid geometry type.");
}
},


performUndo: function () {
var geometry = this._editedGraphic.geometry;
if(geometry.type === "multipoint"){
geometry.removePoint(this._vertexInfo.pointIndex);
} else if(geometry.type === "polyline" || geometry.type === "polygon") {
geometry.removePoint(this._vertexInfo.segmentIndex, this._vertexInfo.pointIndex);
}
this._editedGraphic.draw();
this._editTool.refresh();
},

performRedo: function () {
var geometry = this._editedGraphic.geometry;
if(geometry.type === "multipoint"){
geometry.removePoint(this._vertexInfo.pointIndex, this._vertex);
} else if(geometry.type === "polyline" || geometry.type === "polygon") {
geometry.insertPoint(this._vertexInfo.segmentIndex, this._vertexInfo.pointIndex, this._vertex);
}
this._editedGraphic.draw();
this._editTool.refresh();
}
});

return customOp;
});

确保在停用编辑工具栏时清除 UndoManager。否则,操作将保留。不要将添加图形操作与顶点操作结合起来。它不会工作,因为他们使用不同的工具栏,并且一旦您停用它,编辑工具栏状态就会丢失。

还要注意的一点是,当您使用 UndoManager 时,图形 isModified 状态将始终为 true,因为我们在撤消/重做期间添加和删除顶点,即使撤消所有更改也是如此。因此,请确保您需要通过检查是否有任何待处理的撤消(几何图形确实已修改)来应用编辑。

希望这对您有所帮助。

关于javascript - 如何使用 arcgis javascript 顶点 undoManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37559439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com