首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用arcgis javascript vertex undoManager

如何使用arcgis javascript vertex undoManager
EN

Stack Overflow用户
提问于 2016-06-01 12:28:59
回答 1查看 340关注 0票数 1

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

测试图形对象。但我不知道如何编辑顶点撤消/重做。

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

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

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

代码语言:javascript
复制
   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 ");
          }
        });
EN

回答 1

Stack Overflow用户

发布于 2016-06-02 05:08:38

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

代码语言:javascript
复制
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状态将始终为真,因为我们在撤消/重做期间添加和删除顶点,即使撤消所有更改也是如此。因此,确保你需要通过检查是否有任何挂起的撤销(几何图形确实被修改)来应用编辑。

希望这能对你有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37559439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档