@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.28 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import r from"../../geometry/Point.js";import{ViewingMode as s}from"../ViewingMode.js";import o from"./DrawAction.js";import{VertexAddEvent as n,CursorUpdateEvent as a,DrawCompleteEvent as d}from"./input/DrawEvents.js";import{createViewAlignedCoordinateSystem as h}from"./support/surfaceCoordinateSystems.js";import{ViewEventPriorities as p}from"../input/InputManager.js";import{sketchKeys as l}from"../interactive/keybindings.js";import{EditGeometry as c,Component as _}from"../interactive/editGeometry/EditGeometry.js";import{EditGeometryOperations as m}from"../interactive/editGeometry/EditGeometryOperations.js";import{loadAutomaticLengthMeasurementUtils as g}from"../support/automaticLengthMeasurementUtils.js";import{createScreenPointFromEvent as u}from"../support/screenUtils.js";const v=["freehand","click"];let w=class extends o{constructor(e){super(e),this._isDragging=!1,this._panEnabled=!1,this._addVertexOnPointerUp=!1,this._drawTool=null,this.viewAlignedCoordinateSystem=null,this.mode="freehand"}initialize(){"2d"===this.view.type?this._addViewHandles():this.addResolvingPromise(this._addDrawTool())}destroy(){this._removeDrawTool(),this.emit("destroy")}complete(){this._completeDrawing()}_getGeometryZValue(){return this.hasZ&&this.vertices.length>0?this.vertices[0][2]:this.defaultZ}_addViewHandles(){"click"===this.mode?this.addHandles(this._getClickModeViewHandles()):this.addHandles(this._getDragModeViewHandles())}_getDragModeViewHandles(){return[this.view.on("immediate-click",(e=>{if(e.stopPropagation(),e.mapPoint&&!this._panEnabled){null!=this.getCoordsFromScreenPoint(u(e))&&(this._vertexAddHandler(e),this._drawCompleteHandler(e))}}),p.TOOL),this.view.on("pointer-down",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._panEnabled||(this._resetGeometry(),this._addVertexOnPointerUp=!0,this._cursorScreenPoint=u(e),this._activePointerId=e.pointerId,this._vertexAddHandler(e),this._isDragging=!1,"touch"===e.pointerType&&this._updateCursor()))}),p.TOOL),this.view.on("pointer-move",(e=>{this._abortSnapping(),null==this._activePointerId&&"touch"!==e.pointerType&&(this._cursorScreenPoint=u(e),this._updateCursor())}),p.TOOL),this.view.on("pointer-drag",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._isDragging=!0,this._cursorScreenPoint=u(e),this._updateCursor())}),p.TOOL),this.view.on("pointer-up",(e=>{this._shouldHandlePointerEvent(e)&&this._addVertexOnPointerUp&&(this._abortSnapping(),this._activePointerId=null,this._isDragging&&this._vertexAddHandler(e),2===this._committedVertices.length&&this._drawCompleteHandler(e),this._isDragging=!1)}),p.TOOL),this.view.on("key-down",(e=>{e.key===l.complete&&this._cursorScreenPoint?(this._abortSnapping(),this._vertexAddHandler(e),this._drawCompleteHandler(e)):e.key===l.pan&&(this._panEnabled=!0)}),p.TOOL),this.view.on("key-up",(e=>{e.key===l.pan&&(this._panEnabled=!1)}),p.TOOL),this.view.on("drag",(e=>{null!=this._activePointerId&&e.stopPropagation()}),p.TOOL),this.view.on("drag",["Shift"],(e=>{e.stopPropagation()}),p.TOOL)]}_getClickModeViewHandles(){return[this.view.on("pointer-down",(e=>{this._abortSnapping(),this._cursorScreenPoint=u(e),this._activePointerId=e.pointerId,this._isDragging=!1,"touch"===e.pointerType&&this._updateCursor()}),p.TOOL),this.view.on("pointer-move",(e=>{this._abortSnapping(),this._cursorScreenPoint=u(e),null==this._activePointerId&&"touch"!==e.pointerType&&this._updateCursor()}),p.TOOL),this.view.on("pointer-drag",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._isDragging=!0)}),p.TOOL),this.view.on("pointer-up",(e=>{this._shouldHandlePointerEvent(e)&&(this._abortSnapping(),this._activePointerId=null,e.stopPropagation(),this._isDragging||this._vertexAddHandler(e),2!==this.vertices.length||this._isDragging||this._drawCompleteHandler(e),this._isDragging=!1)}),p.TOOL),this.view.on("key-down",(e=>{e.key===l.vertexAdd&&this._cursorScreenPoint&&(this._vertexAddHandler(e),2===this.vertices.length&&this._drawCompleteHandler(e)),e.key===l.complete&&this._cursorScreenPoint&&2===this.vertices.length&&(this._vertexAddHandler(e),this._drawCompleteHandler(e))}),p.TOOL)]}async _addDrawTool(){const[{DrawTool:e},t]=await Promise.all([import("./DrawTool.js"),g()]),i=new e({view:this.view,elevationInfo:this.elevationInfo,hasZ:this.hasZ,geometryType:"segment",mode:this.mode,automaticLengthMeasurementUtils:t});this.destroyed?i.destroy():(this._drawTool=i,this.view.addAndActivateTool(i),this.addHandles([i.on("vertex-add",(e=>{1===e.vertices.length&&this.emit("vertex-add",new n(this.view,e.vertices[0].vertexIndex,i.getVertexCoords()))})),i.on("cursor-update",(e=>{1===e.vertices.length&&this.emit("cursor-update",new a(this.view,e.vertices[0].vertexIndex,i.getVertexCoords()))})),i.on("complete",(e=>{this.emit("draw-complete",new d(i.getVertexCoords())),this._removeDrawTool()})),this.view.on("key-down",(e=>{e.key!==l.vertexAdd||e.repeat||"click"!==this.mode?e.key!==l.complete||e.repeat||i.completeCreateOperation():i.drawOperation.numCommittedVertices>0?i.completeCreateOperation():i.drawOperation.commitStagedVertex()}),p.TOOL)]))}_removeDrawTool(){this._drawTool&&(this.view.tools.remove(this._drawTool),this._drawTool=null)}_addVertex(e){const t=this._coordinateHelper.arrayToVector(e);if(this._isDuplicateOfLastVertex(t))return;this._lastVertexUnsnapped=this._stagedVertexUnsnapped,this._popCursorVertex(),this._editGeometryOperations.appendVertex(t),1===this._committedVertices.length&&(this.viewAlignedCoordinateSystem=h(this.view,this._committedVertices[0]));const i=this._committedVertices.length-1,r=new n(this.view,i,this.vertices);this.emit("vertex-add",r)}_updateCursor(){if(this._popCursorVertex(),!this._cursorScreenPoint)return;const e=this.getCoordsAndPointFromScreenPoint(this._cursorScreenPoint);null!=e&&this._pushCursorVertex(e.vertex,(()=>this.emit("cursor-update",new a(this.view,this._activeComponent.vertices.length,this.vertices,null!=this._stagedVertex?new r(this._stagedVertex):null))))}_completeDrawing(){if(this._drawTool)return this._drawTool.completeCreateOperation(),void this.removeAllHandles();if(this._activePointerId=null,this._popCursorVertex(),this._cursorScreenPoint=null,this._isDragging=!1,this._abortSnapping(),null!=this._snappingManager&&this._snappingManager.doneSnapping(),this.vertices.length<1)return;const e=new d(this.vertices);this.emit("draw-complete",e),e.defaultPrevented||this.removeAllHandles()}_resetGeometry(){this._editGeometryOperations.destroy(),this._editGeometryOperations=new m(new c("polygon",this._coordinateHelper),s.Local),this._activeComponent=new _(this._coordinateHelper.spatialReference,s.Local),this._editGeometryOperations.data.components.push(this._activeComponent)}};e([t({type:v})],w.prototype,"mode",void 0),w=e([i("esri.views.draw.SegmentDrawAction")],w);const y=w;export{y as default};