2016-06-01 3 views
1

나는 undomanager를 사용하여 편집 정점을 실행 취소/다시 시도합니다.arcgis javascript vertex undoManager

그래픽 개체가 테스트되었습니다. 하지만 나는 무엇을 해야할지 모르겠다. 편집 편집 취소/다시하기.

정점 실행 취소/다시 실행이 가능합니까?

많은 예제에서 답을 찾지 못했습니다.

i`m korean beginner 프로그래머. 도와주세요 ~ 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 "); 
      } 
     }); 

답변

1

참조 할 샘플은 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를 지워야합니다. 그렇지 않으면 작업이 그대로 유지됩니다. Vertex Operations에 그래픽 추가 작업을 결합하지 마십시오. 사용자가 다른 툴바를 사용하고 편집 툴바 상태가 비활성화되면 즉시 작동하지 않으므로 작동하지 않습니다.

UndoManager를 사용할 때, 모든 변경 사항을 실행 취소해도 실행 취소/다시 실행 중에 정점을 추가 및 삭제하므로 그래픽 isModified 상태가 항상 true입니다. 따라서 보류중인 실행 취소 (지오메트리가 실제로 수정 됨)가 있는지 확인하여 수정해야합니다.

희망이있었습니다.

+0

답변 해 주셔서 감사합니다 ~ !!! – BingBingPa

+0

도와 줘서 기쁩니다. 문제가 해결되면 답을 표시하십시오. –

관련 문제