12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import{isSome as t,destroyMaybe as i}from"../../core/maybe.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import r from"./DrawAction.js";import{defaultDrawingMode as n,drawingModes as a}from"./DrawingMode.js";import{DrawTool as d}from"./DrawTool.js";import{VertexRemoveEvent as h,VertexAddEvent as p,CursorUpdateEvent as l,DrawCompleteEvent as _}from"./input/DrawEvents.js";import{ViewEventPriorities as c}from"../input/InputManager.js";import{SKETCH_KEYS as v}from"../interactive/keybindings.js";import{createScreenPointFromEvent as m}from"../support/screenUtils.js";import u from"../../geometry/Point.js";let w=class extends r{constructor(e){super(e),this._panEnabled=!1,this._popVertexOnPointerMove=!1,this._addVertexOnPointerUp=!1,this.mode=n}initialize(){"2d"===this.view.type?(this._addViewHandles(),this._addUndoRedoHandles()):this._addDrawTool()}destroy(){"2d"===this.view.type?(this._removeViewHandles(),this._removeUndoRedoHandles()):this._removeDrawTool(),this.emit("destroy")}get _dragEnabled(){return"freehand"===this.mode||"hybrid"===this.mode}get _clickEnabled(){return"click"===this.mode||"hybrid"===this.mode}undo(){super.undo(),this.notifyChange("vertices")}redo(){super.redo(),this.notifyChange("vertices")}complete(){"2d"===this.view.type?this._completeDrawing():this._drawTool.completeCreateOperation()}_getGeometryZValue(){return this.hasZ&&this.vertices.length>0?this.vertices[0][2]:this.defaultZ}_addViewHandles(){this._removeViewHandles(),this._handles.add([this.view.on("click",(e=>{e.stopPropagation()}),c.TOOL),this.view.on("pointer-down",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._activePointerId=e.pointerId,this._addVertexOnPointerUp=!0,this._cursorScreenPoint=m(e),"touch"===e.pointerType&&this._updateCursor(e.native))}),c.TOOL),this.view.on("pointer-move",(e=>{this._abortSnapping(),this._popVertexOnPointerMove&&(this.undo(),this._popVertexOnPointerMove=!1),this._cursorScreenPoint=m(e),"touch"!==e.pointerType&&this._updateCursor(e.native)}),c.TOOL),this.view.on("pointer-drag",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._cursorScreenPoint=m(e),this._dragEnabled&&!this._panEnabled?this._vertexAddHandler(e):this._addVertexOnPointerUp=!1)}),c.TOOL),this.view.on("pointer-up",(e=>{if(this._shouldHandlePointerEvent(e))if(this._abortSnapping(),this._activePointerId=null,this._addVertexOnPointerUp){if(!this._clickEnabled)return 1===this.vertices.length&&this.vertices.pop(),void this._drawCompleteHandler(e);this._vertexAddHandler(e)}else{const t="touch"===e.pointerType;this._updateCursor(e.native,t)}}),c.TOOL),this.view.on("drag",(e=>{this._dragEnabled&&t(this._activePointerId)&&!this._panEnabled&&e.stopPropagation()}),c.TOOL),this.view.on("drag",["Shift"],(e=>{e.stopPropagation()}),c.TOOL),this.view.on("double-click",(e=>{e.stopPropagation(),this._drawCompleteHandler(e)}),c.TOOL),this.view.on("double-click",["Control"],(e=>{e.stopPropagation(),this._drawCompleteHandler(e)}),c.TOOL),this.view.on("key-down",(e=>{const{key:t,repeat:i}=e;t===v.vertexAdd&&!i&&this._cursorScreenPoint?(e.stopPropagation(),this._abortSnapping(),this._vertexAddHandler(e)):t!==v.complete||i?t!==v.undo||this.interactiveUndoDisabled||i?t!==v.redo||this.interactiveUndoDisabled||i?t!==v.pan||i||(e.stopPropagation(),this._panEnabled=!0):(e.stopPropagation(),this.redo()):(e.stopPropagation(),this.undo()):(e.stopPropagation(),this._drawCompleteHandler(e))}),c.TOOL),this.view.on("key-up",(e=>{e.key===v.pan&&(e.stopPropagation(),this._panEnabled=!1)}),c.TOOL)],this._viewHandlesKey)}_addUndoRedoHandles(){this._removeUndoRedoHandles(),this._handles.add([this._editGeometryOperations.on("vertex-remove",(e=>{if(this.notifyChange("vertices"),"undo"===e.operation){const i=this._nativeEventHistory.undoStack.pop();this._nativeEventHistory.redoStack.push(i);const o=[...this._committedVertices];t(this._stagedVertex)&&o.push(this._coordinateHelper.pointToArray(this._stagedVertex)),this.emit("undo",new h(this.view,i,e.vertices[0].index,o))}})),this._editGeometryOperations.on("vertex-add",(e=>{if(this.notifyChange("vertices"),"apply"===e.operation){const e=this._nativeEventHistory.undoStack[this._nativeEventHistory.undoStack.length],t=this._committedVertices.length-1,i=new p(this.view,e,t,this.vertices);this.emit("vertex-add",i),i.defaultPrevented&&(this._popVertexOnPointerMove=!0)}else if("redo"===e.operation){const i=this._nativeEventHistory.redoStack.pop();this._nativeEventHistory.undoStack.push(i);const o=[...this._committedVertices];t(this._stagedVertex)&&o.push(this._coordinateHelper.pointToArray(this._stagedVertex)),this.emit("redo",new p(this.view,i,e.vertices[0].index,o))}}))],this._undoRedoHandlesKey)}_removeViewHandles(){this._handles.remove(this._viewHandlesKey)}_removeUndoRedoHandles(){this._handles.remove(this._undoRedoHandlesKey)}_addDrawTool(){this._drawTool=new d({view:this.view,elevationInfo:this.elevationInfo,hasZ:this.hasZ,geometryType:"polygon",mode:this.mode}),this.view.addAndActivateTool(this._drawTool),this._drawTool.on("vertex-add",(e=>{1===e.vertices.length&&this.emit("vertex-add",new p(this.view,null,e.vertices[0].vertexIndex,this._drawTool.getVertexCoords()))})),this._drawTool.on("cursor-update",(e=>{1===e.vertices.length&&this.emit("cursor-update",new l(this.view,null,e.vertices[0].vertexIndex,this._drawTool.getVertexCoords()))})),this._drawTool.on("complete",(e=>{this.emit("draw-complete",new _(null,this._drawTool.getVertexCoords())),this._removeDrawTool()}))}_removeDrawTool(){this._handles.remove(this._drawToolHandlesKey),this.view.tools.remove(this._drawTool),this._drawTool=i(this._drawTool)}_addVertex(e,t){const i=this._coordinateHelper.arrayToVector(e);if(this._isDuplicateOfLastVertex(i))return;this._lastVertexUnsnapped=this._stagedVertexUnsnapped,this._popCursorVertex(),this._editGeometryOperations.appendVertex(i);const o=t||new Event("placeholder");this._nativeEventHistory.undoStack.push(o)}_updateCursor(e,i=!1){if(this._popCursorVertex(),!this._cursorScreenPoint)return;const o=this.getCoordsAndPointFromScreenPoint(this._cursorScreenPoint);t(o)&&!i&&this._pushCursorVertex(o.vertex,(()=>this.emit("cursor-update",new l(this.view,e,this._activeComponent.vertices.length,this.vertices,t(this._stagedVertex)?new u(this._stagedVertex):null))))}_completeDrawing(e){if(this._activePointerId=null,this._popCursorVertex(),this._committedVertices.length<3)return;this._abortSnapping(),t(this._snappingManager)&&this._snappingManager.doneSnapping();const i=new _(e,this.vertices);this.emit("draw-complete",i),i.defaultPrevented||this._removeViewHandles()}};e([o()],w.prototype,"_dragEnabled",null),e([o()],w.prototype,"_clickEnabled",null),e([o({type:a})],w.prototype,"mode",void 0),w=e([s("esri.views.draw.PolygonDrawAction")],w);export{w as PolygonDrawAction};
|