2016-06-01 27 views
1

私は、アンドマジャーを使用して編集頂点を元に戻したりやり直したりしてみます。javascript頂点undoManager

グラフィックオブジェクトがテストされます。しかし、私は何をすべきかわからない。頂点の元に戻す/やり直しを編集する。

頂点の元に戻す/やり直しは可能ですか?

多くの例が答えを見つけていないことがわかりました。

i`m韓国初心者プログラマー。 help me〜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をクリアしてください。さもなければ操作は残る。グラフィックス操作を頂点操作と組み合わせないでください。彼らは異なるツールバーを使用し、編集ツールバーの状態が無効になるとすぐに失われますので、機能しません。

UndoManagerを使用すると、元に戻す/すべてやり直し中に頂点を追加したり削除したりするので、グラフィックスのisModified状態は常に真となります。したがって、保留中の元に戻す(ジオメトリが実際に変更されている)かどうかを確認して、編集を適用する必要があることを確認してください。

希望しました。

+0

お返事ありがとうございます〜!!! – BingBingPa

+0

あなたの問題を解決した場合は、喜んで回答してください。 –

関連する問題