// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../chunks/tslib.es6 ../../core/Accessor ../../core/Evented ../../core/lang ../../core/maybe ../../core/memoize ../../core/promiseUtils ../../core/ReactiveSet ../../core/reactiveUtils ../../core/screenUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/Logger ../../core/accessorSupport/decorators/subclass ../../core/accessorSupport/diffUtils ../../core/support/UpdatingHandles ../../layers/graphics/dehydratedFeatureComparison ../../support/elevationInfoUtils ../ViewingMode ./DrawingMode ./DrawManipulator ../interactive/coordinateHelper ../interactive/dragEventPipeline ../interactive/editGeometry/EditGeometry ../interactive/editGeometry/EditGeometryOperations ../interactive/sketch/constraints ../interactive/sketch/constraintUtils ../interactive/sketch/SketchLabelOptions ../interactive/snapping/SnappingContext ../interactive/snapping/SnappingDragPipelineStep ../interactive/snapping/SnappingOperation ../interactive/snapping/snappingUtils".split(" "), function(e,g,H,I,y,u,z,A,J,q,K,h,X,Y,L,M,N,t,O,P,B,Q,R,v,C,S,T,w,D,E,U,V,W){const F=Symbol(),G=Symbol();e.DrawOperation=class extends I.EventedMixin(H){constructor(a){super(a);this._hideDefaultCursor=this._createOperationCompleted=!1;this._pointerDownStates=new J;this._stagedPointerType=this._stagedScreenPoint=null;this._updatingHandles=new N.UpdatingHandles;this._stagedPointerId=null;this.constraintsEnabled=!1;this.constraints=void 0;this._getPointConstraint=z.memoize(w.getPointConstraint);this._getPolylineOrPolygonConstraint= z.memoize(w.getPolylineOrPolygonConstraint);this.defaultZ=this.constraintZ=null;this.isDraped=!0;this.labelOptions=new D;this.cursor=null;this.loading=!1;this.secondToLastVertex=this.lastVertex=this.firstVertex=this.snapToSceneEnabled=null;null==a.elevationInfo&&(this.elevationInfo=O.getEffectiveElevationInfo(!!a.hasZ))}initialize(){const {geometryType:a,view:b}=this,d=b.spatialReference,c="viewingMode"in b.state?b.state.viewingMode:P.ViewingMode.Local,l="segment"===a||"multipoint"===a?"polyline": a;this.coordinateHelper=R.createCoordinateHelper(this.hasZ,this.hasM,d);this._editGeometryOperations=new S.EditGeometryOperations(new C.EditGeometry(l,this.coordinateHelper),c);this._snappingOperation=new V.SnappingOperation({view:b});this.addHandles([q.watch(()=>({stagedPoint:this._snappingOperation.stagedPoint,constraint:this._constraint}),({stagedPoint:f,constraint:k},r)=>{const {snappingOptions:n}=this;n&&(n.forceDisabled=null!=k&&T.isPoint(k));if(null!=r&&f===r.stagedPoint&&k!==r.constraint)return this._onKeyboardBasedChange(); this._processCursor(f??this._screenToMap(this._stagedScreenPoint))},{equals:(f,k)=>f.stagedPoint===k.stagedPoint&&u.equalsMaybe(f.constraint,k.constraint)}),q.watch(()=>this.view.viewpoint,(f,k)=>{f&&k&&M.diff(f,k)&&this._onKeyboardBasedChange()})]);this._activeComponent=new C.Component(d,c);this._editGeometryOperations.data.components.push(this._activeComponent);const m=this.segmentLabels;null!=m&&(m.context={view:b,editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo, labelOptions:this.labelOptions},this.addHandles(q.watch(()=>this.labelOptions.enabled,f=>{m.visible=f},q.syncAndInitial)));this.addHandles(this._editGeometryOperations.on(["vertex-add","vertex-update","vertex-remove"],f=>{const k=f.vertices.map(x=>({componentIndex:0,vertexIndex:x.index,coordinates:this.coordinateHelper.vectorToArray(x.pos)})),r=k.map(x=>x.coordinates);var n=this.coordinateHelper.vectorToDehydratedPoint(this._activeComponent.getFirstVertex()?.pos)??null;t.pointEquals(n,this.firstVertex)|| (this.firstVertex=n);n=this.coordinateHelper.vectorToDehydratedPoint(this._activeComponent.getLastVertex()?.pos)??null;t.pointEquals(n,this.lastVertex)||(this.lastVertex=n);n=this.coordinateHelper.vectorToDehydratedPoint(this._activeComponent.edges.at(-1)?.leftVertex?.pos)??null;t.pointEquals(n,this.secondToLastVertex)||(this.secondToLastVertex=n);this._processCursor(this.cursorVertex);switch(f.type){case "vertex-add":this.emit(f.type,{...f,added:r,vertices:k});break;case "vertex-update":this.emit(f.type, {...f,updated:r,vertices:k});break;case "vertex-remove":this.emit(f.type,{...f,removed:r,vertices:k})}}));const p=this._manipulator=new Q.DrawManipulator({consumesClicks:!1,grabbableForEvent:f=>"click"!==this.drawingMode?!0:"touch"===f.pointerType&&this._snappingEnabled&&1===this._pointerDownStates.size});this.manipulators.add(p);p.grabbable="point"!==a;this.addHandles([p.events.on("immediate-click",f=>this._onImmediateClick(f)),p.events.on("immediate-double-click",f=>this._onImmediateDoubleClick(f)), q.watch(()=>this.drawingMode,()=>{this.removeHandles(F);this.addHandles(this._createManipulatorDragPipeline(p),F)},q.syncAndInitial),q.watch(()=>({effectiveCursor:this.effectiveCursor}),({effectiveCursor:f})=>{p.cursor=f},q.syncAndInitial)]);W.setupSnappingToggleHandles(this,()=>{var f=this._getSnappingContext(this.view.inputManager.latestPointerType??"mouse");null!=this.snappingManager&&(f=this._snappingOperation.snapAgainNearPreviousMapPoint(this.snappingManager,f),this._updatingHandles.addPromise(A.ignoreAbortErrors(f)))})}destroy(){u.destroyMaybe(this.segmentLabels); u.destroyMaybe(this._snappingOperation);this._editGeometryOperations=u.destroyMaybe(this._editGeometryOperations);this._updatingHandles.destroy()}get _isDragging(){const {_stagedPointerId:a,_manipulator:b}=this;return null!=a&&this._pointerDownStates.has(a)||b.grabbing||!b.interactive}get _snappingEnabled(){return null!=this.snappingManager&&this.snappingManager.options.effectiveEnabled}get _requiresScenePoint(){const a=this._updateAndGetEffectiveDrawSurface();return"3d"===this.view.type&&this.drawSurface!== a}get canRedo(){return this._editGeometryOperations.canRedo}get canUndo(){return this._editGeometryOperations.canUndo}get committedVertices(){return this._activeComponent.vertices.map(a=>this.coordinateHelper.vectorToArray(a.pos))}get _constraint(){const {constraints:a,constraintsEnabled:b}=this;if(a&&b)switch(this.geometryType){case "point":return this._getPointConstraint(a);case "polygon":case "polyline":return this._getPolylineOrPolygonConstraint(this.lastVertex,this.secondToLastVertex,a)}}set drawingMode(a){this._set("drawingMode", a??B.defaultDrawingMode)}get effectiveCursor(){return this.loading?"progress":this._hideDefaultCursor?null:this.cursor||"crosshair"}get interactive(){return this._manipulator.interactive}set interactive(a){this._manipulator.interactive=a}get isCompleted(){return this._createOperationCompleted}get numCommittedVertices(){return this._activeComponent.vertices.length}get snappingOptions(){return null!=this.snappingManager?this.snappingManager.options:null}get cursorVertex(){return this._get("cursorVertex")}get visualizationCursorVertex(){return"mouse"=== this._stagedPointerType?this.cursorVertex:null}get committableVertex(){const {cursorVertex:a,lastVertex:b,firstVertex:d,geometryType:c}=this;return"polygon"===c&&t.pointNear(a,d)||t.pointNear(a,b)?null:a}get updating(){return this._updatingHandles.updating}get geometryIncludingUncommittedVertices(){const {committedVertices:a,committableVertex:b,coordinateHelper:d}=this,c=a.slice();null!=b&&c.push(d.pointToArray(b));return c}cancel(){this.complete({aborted:!0})}commitStagedVertex(){this._snappingOperation.abort(); const {committableVertex:a}=this;null!=a&&this._editGeometryOperations.appendVertex(this.coordinateHelper.pointToVector(a))}complete(a){a=a?.aborted||!1;this._snappingOperation.abort();this.snappingManager?.doneSnapping();const {geometryType:b,numCommittedVertices:d}=this,c="multipoint"===b&&0===d||"polyline"===b&&2>d||"polygon"===b&&3>d;"segment"!==b&&"point"!==b||this.commitStagedVertex();this._createOperationCompleted=!c;if(this.isCompleted||a)this._stagedPointerType=this._stagedPointerId=this._stagedScreenPoint= null,this._processCursor(null),this.emit("complete",{vertices:this.committedVertices.map((l,m)=>({componentIndex:0,vertexIndex:m,coordinates:l})),aborted:a,type:"complete"})}onInputEvent(a){switch(a.type){case "pointer-down":this._pointerDownStates.add(a.pointerId);break;case "pointer-up":this._pointerDownStates.delete(a.pointerId)}switch(a.type){case "pointer-move":return this._onPointerMove(a);case "hold":return this._onHold(a)}}redo(){this._editGeometryOperations.redo()}undo(){null!=this.snappingManager&& this.snappingManager.doneSnapping();this._editGeometryOperations.undo()}_processCursor(a){const b=y.clone(this.cursorVertex);a=(a=y.clone(a))&&(this._updateAndGetEffectiveDrawSurface()?.constrainZ(a)??a);a=this._snapToClosingVertex(a);a=this._applyConstraints(a);t.pointNear(b,a)||(this._set("cursorVertex",a),this.segmentLabels?.set("stagedVertex",null!=a?this.coordinateHelper.pointToVector(a):null),null==a||"mouse"!==this._stagedPointerType?this.emit("cursor-remove"):this.emit("cursor-update",{updated:null, vertices:[{componentIndex:0,vertexIndex:this._activeComponent.vertices.length,coordinates:this.coordinateHelper.pointToArray(a)}],operation:"apply",type:"vertex-update"}))}_snapToClosingVertex(a){if(null==a||this._isDragging||"polygon"!==this.geometryType||2>=this.numCommittedVertices)return a;const b=this._mapToScreen(a);if(!b)return a;const d=this._activeComponent;return this._vertexWithinPointerDistance(d.vertices[0].pos,b)?this.firstVertex:this._vertexWithinPointerDistance(d.vertices.at(-1).pos, b)?this.lastVertex:a}_createManipulatorDragPipeline(a){switch(this.drawingMode){case "click":return this._createManipulatorDragPipelineClick(a);case "freehand":return this._createManipulatorDragPipelineFreehand(a);case "hybrid":return this._createManipulatorDragPipelineHybrid(a)}}_createManipulatorDragPipelineClick(a){return v.createManipulatorDragEventPipeline(a,(b,d,c,l)=>{const m="touch"===l&&this._snappingEnabled;if(!this.isCompleted&&m){var {snappingStep:p,cancelSnapping:f}=U.createSnapDragEventPipelineStep({predicate:()=> m,snappingManager:this.snappingManager,snappingContext:new E.SnappingContext({editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo,feature:this.graphic,pointer:l,visualizer:this.snappingVisualizer,drawConstraints:this.constraints}),updatingHandles:this._updatingHandles,useZ:!this._requiresScenePoint});c=c.next(k=>{m&&null!=this.snappingManager&&this.snappingManager.doneSnapping();return k}).next(f);d.next(this._screenToMapDragEventStep()).next(k=>{"start"===k.action&& (this._processCursor(k.mapStart),("segment"===this.geometryType||m&&!this.numCommittedVertices)&&this.commitStagedVertex());return k}).next(v.sceneSnappingAtLocation(this.view,this.elevationInfo)).next(...p).next(k=>{m&&(this._processCursor(k.mapEnd),"end"===k.action&&this.commitStagedVertex());return k}).next(k=>{"end"===k.action&&("mouse"!==this._stagedPointerType&&this._snappingOperation.abort(),"segment"!==this.geometryType&&"point"!==this.geometryType||this.complete());return k})}})}_createManipulatorDragPipelineFreehand(a){return v.createManipulatorDragEventPipeline(a, (b,d)=>{this.isCompleted||d.next(this._screenToMapDragEventStep()).next(c=>{"start"===c.action&&(this._snappingOperation.abort(),null==this.committableVertex&&this._processCursor(c.mapStart),"segment"===this.geometryType&&this.commitStagedVertex());return c}).next(c=>{switch(c.action){case "start":case "update":this._processCursor(c.mapEnd);"polygon"!==this.geometryType&&"polyline"!==this.geometryType||this.commitStagedVertex();break;case "end":this.complete()}return c})})}_createManipulatorDragPipelineHybrid(a){return v.createManipulatorDragEventPipeline(a, (b,d)=>{this.isCompleted||d.next(this._screenToMapDragEventStep()).next(c=>{"start"===c.action&&(this._snappingOperation.abort(),this.addHandles(this._editGeometryOperations.createUndoGroup(),G),this._processCursor(c.mapStart),this.commitStagedVertex());return c}).next(c=>{switch(c.action){case "start":case "update":this._processCursor(c.mapEnd);"polygon"!==this.geometryType&&"polyline"!==this.geometryType||this.commitStagedVertex();break;case "end":"mouse"!==this._stagedPointerType&&this._snappingOperation.abort(), this.removeHandles(G),"segment"!==this.geometryType&&"point"!==this.geometryType||this.complete()}return c})})}get _drawAtFixedElevation(){const {constraintsEnabled:a,constraintZ:b,geometryType:d,numCommittedVertices:c}=this;return a?null!=b||"segment"===d&&0{"start"===b.action&&(a=this._screenToMap(b.screenStart));if(null==a)return null;const d=this._screenToMap(b.screenEnd);return null!=d?{...b,mapStart:a,mapEnd:d}:null}}_vertexWithinPointerDistance(a,b){const d=this._mapToScreen(this.coordinateHelper.vectorToDehydratedPoint(a)); null!=d?(a=d.x-b.x,b=d.y-b.y,b=25>=a*a+b*b):b=!1;return b}_getSnappingContext(a){const b=this._drawAtFixedElevation?this.elevationDrawSurface?.defaultZ:null;return new E.SnappingContext({editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo,pointer:a,feature:this.graphic,visualizer:this.snappingVisualizer,selfSnappingZ:null!=b?{value:b,elevationInfo:this.elevationInfo}:null,drawConstraints:this.constraints})}};g.__decorate([h.property()],e.DrawOperation.prototype,"_hideDefaultCursor", void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"_stagedPointerId",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"_isDragging",null);g.__decorate([h.property()],e.DrawOperation.prototype,"_snappingOperation",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"_snappingEnabled",null);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"graphic",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"constraintsEnabled",void 0);g.__decorate([h.property()], e.DrawOperation.prototype,"constraints",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"_constraint",null);g.__decorate([h.property()],e.DrawOperation.prototype,"constraintZ",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"defaultZ",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"isDraped",void 0);g.__decorate([h.property({value:B.defaultDrawingMode})],e.DrawOperation.prototype,"drawingMode",null);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype, "elevationDrawSurface",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"elevationInfo",void 0);g.__decorate([h.property({constructOnly:!0,type:D})],e.DrawOperation.prototype,"labelOptions",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"geometryType",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"hasM",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"hasZ",void 0);g.__decorate([h.property()], e.DrawOperation.prototype,"cursor",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"effectiveCursor",null);g.__decorate([h.property()],e.DrawOperation.prototype,"loading",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"manipulators",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"drawSurface",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"segmentLabels",void 0);g.__decorate([h.property({constructOnly:!0})], e.DrawOperation.prototype,"snappingManager",void 0);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"snappingVisualizer",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"snapToSceneEnabled",void 0);g.__decorate([h.property({readOnly:!0})],e.DrawOperation.prototype,"cursorVertex",null);g.__decorate([h.property({readOnly:!0})],e.DrawOperation.prototype,"visualizationCursorVertex",null);g.__decorate([h.property()],e.DrawOperation.prototype,"committableVertex",null); g.__decorate([h.property()],e.DrawOperation.prototype,"firstVertex",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"lastVertex",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"secondToLastVertex",void 0);g.__decorate([h.property()],e.DrawOperation.prototype,"updating",null);g.__decorate([h.property({constructOnly:!0})],e.DrawOperation.prototype,"view",void 0);e.DrawOperation=g.__decorate([L.subclass("esri.views.draw.DrawOperation")],e.DrawOperation);e.defaultCursor="crosshair"; e.defaultLoadingCursor="progress";Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});