// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../chunks/tslib.es6 ../../core/Evented ../../core/lang ../../core/maybe ../../core/promiseUtils ../../core/screenUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/Logger ../../core/accessorSupport/decorators/subclass ../../layers/GraphicsLayer ../../layers/graphics/dehydratedPoint ../ViewingMode ../2d/interactive/SnappingVisualizer2D ../interactive/coordinateHelper ../interactive/editGeometry/EditGeometry ../interactive/editGeometry/EditGeometryOperations ../interactive/snapping/SnappingContext ../interactive/snapping/SnappingOperation".split(" "), function(d,c,m,n,p,h,e,C,D,q,r,t,k,u,v,l,w,x,y){var g;c=g=class extends c.EventedAccessor{constructor(a){super(a);this._lastVertexUnsnapped=this._stagedVertexUnsnapped=this._activePointerId=this._cursorScreenPoint=this._hasZ=null;this.interactiveUndoDisabled=!1;this.history=[];this.redoHistory=[];this.snapToScene=!1;this.elevationInfo=this.view=null;this.defaultZ=0;this._coordinateHelper=v.createCoordinateHelper(!!a.hasZ,!1,a.view.spatialReference);this._snappingManager=a.snappingManager;this._editGeometryOperations= new w.EditGeometryOperations(new l.EditGeometry(a.editGeometryType??"polygon",this._coordinateHelper),k.ViewingMode.Local);this._snappingGraphicsLayer=new r({id:g.SNAPPING_GRAPHICS_LAYER_ID,listMode:"hide",internal:!0});this._snappingContext=new x.SnappingContext({editGeometryOperations:this._editGeometryOperations,elevationInfo:{mode:"on-the-ground",offset:0},pointer:"mouse",visualizer:new u.SnappingVisualizer2D(this._snappingGraphicsLayer)});this._activeComponent=new l.Component(a.view.spatialReference, k.ViewingMode.Local);this._editGeometryOperations.data.components.push(this._activeComponent)}normalizeCtorArgs(a){a={...a};delete a.editGeometryType;delete a.snappingManager;return a}initialize(){this._snappingOperation=new y.SnappingOperation({view:this.view});"2d"===this.view.type&&this.view.map.layers.add(this._snappingGraphicsLayer)}destroy(){this.view.map.layers.remove(this._snappingGraphicsLayer);this._snappingGraphicsLayer.destroy();null!=this._snappingManager&&this._snappingManager.doneSnapping(); this._snappingOperation=n.destroyMaybe(this._snappingOperation);this._editGeometryOperations.destroy()}get _committedVertices(){return this._editGeometryOperations.data.components[0].vertices.map(a=>a.pos)}get vertices(){return null!=this._stagedVertex?[...this._committedVertices,this._coordinateHelper.pointToArray(this._stagedVertex)]:this._committedVertices}get hasZ(){return null!=this._hasZ?this._hasZ:"3d"===this.view.type}set hasZ(a){this._hasZ=a;this.notifyChange("hasZ")}get _stagedVertex(){return this._snappingOperation.stagedPoint}set _stagedVertex(a){this._snappingOperation.stagedPoint= m.clone(a)}canUndo(){return this._editGeometryOperations.canUndo}canRedo(){return this._editGeometryOperations.canRedo}undo(){this.canUndo&&this._editGeometryOperations.undo()}redo(){this.canRedo&&this._editGeometryOperations.redo()}getCoordsFromScreenPoint(a){a=a&&this.screenToMap(a);return null==a?null:a.hasZ?[a.x,a.y,a.z]:[a.x,a.y]}getCoordsAndPointFromScreenPoint(a){a=this.screenToMap(a);return null==a?null:a.hasZ?{vertex:[a.x,a.y,a.z],mapPoint:a}:{vertex:[a.x,a.y],mapPoint:a}}screenToMap(a){var b= null;"3d"===this.view.type?this.hasZ?(b=this.elevationInfo??z,b=this.view.sceneIntersectionHelper.intersectElevationFromScreen(h.createScreenPointArray(a.x,a.y),b,this._getGeometryZValue())):(b=this.elevationInfo??A,b=this.view.sceneIntersectionHelper.intersectElevationFromScreen(h.createScreenPointArray(a.x,a.y),b,0),null!=b&&(b.z=void 0)):(b=this.view.toMap(a),null!=b&&(b.z=this.hasZ?this._getGeometryZValue():void 0));return b}_pushCursorVertex(a,b){this._stagedVertexUnsnapped=a=t.makeDehydratedPoint(a[0], a[1],void 0,this.view.spatialReference);const f=this._snappingManager;null==f?(this._stagedVertex=a,b()):p.ignoreAbortErrors(this._snappingOperation.snap({point:a},f,this._snappingContext)).then(()=>{b()})}_popCursorVertex(){this._stagedVertex=this._stagedVertexUnsnapped=null}_getGeometryZValue(){return this.defaultZ}_abortSnapping(){this._snappingOperation.abort()}_isDuplicateOfLastVertex(a){const b=this._editGeometryOperations.data.components[0].getLastVertex()?.pos;if(b&&a[0]===b[0]&&a[1]===b[1])return!0; const {x:f,y:B}=this._coordinateHelper.vectorToDehydratedPoint(a);return null!=this._lastVertexUnsnapped&&f===this._lastVertexUnsnapped.x&&B===this._lastVertexUnsnapped.y?!0:!1}_shouldHandlePointerEvent(a){return("mouse"!==a.pointerType||0===a.button)&&(null==this._activePointerId||this._activePointerId===a.pointerId)}_vertexAddHandler(a){const b=null!=this._stagedVertex?this._coordinateHelper.pointToArray(this._stagedVertex):this.getCoordsFromScreenPoint(this._cursorScreenPoint);null!=b&&this._addVertex(b, a.native)}_drawCompleteHandler(a){this._completeDrawing(a.native)}};c.SNAPPING_GRAPHICS_LAYER_ID="DrawAction-snapping-graphics-layer";d.__decorate([e.property({readOnly:!0})],c.prototype,"vertices",null);d.__decorate([e.property({type:Boolean,nonNullable:!0})],c.prototype,"interactiveUndoDisabled",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"history",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"redoHistory",void 0);d.__decorate([e.property()],c.prototype,"snapToScene", void 0);d.__decorate([e.property()],c.prototype,"view",void 0);d.__decorate([e.property()],c.prototype,"elevationInfo",void 0);d.__decorate([e.property({nonNullable:!0})],c.prototype,"defaultZ",void 0);d.__decorate([e.property()],c.prototype,"hasZ",null);d.__decorate([e.property()],c.prototype,"_snappingOperation",void 0);d.__decorate([e.property()],c.prototype,"_stagedVertex",null);c=g=d.__decorate([q.subclass("esri.views.draw.DrawAction")],c);const z={mode:"absolute-height",offset:0},A={mode:"on-the-ground", offset:0};return c});