12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Evented.js";import{HandleOwner as i}from"../../core/HandleOwner.js";import{clone as o}from"../../core/lang.js";import{isNone as n,isSome as r,applySome as s,destroyMaybe as a,unwrap as p,unwrapOr as l,equalsMaybe as c}from"../../core/maybe.js";import{ignoreAbortErrors as h}from"../../core/promiseUtils.js";import{createLength as d,createArea as m}from"../../core/quantityUtils.js";import{watch as g,syncAndInitial as u,initial as v}from"../../core/reactiveUtils.js";import{createScreenPoint as y}from"../../core/screenUtils.js";import{getMetersPerVerticalUnitForSR as _}from"../../core/unitUtils.js";import{property as x}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import{pointEquals as T}from"../../layers/graphics/dehydratedFeatureComparison.js";import{getConvertedElevation as O}from"../../support/elevationInfoUtils.js";import{ViewingMode as V}from"../ViewingMode.js";import{defaultDrawingMode as w}from"./DrawingMode.js";import{DrawManipulator as b}from"./DrawManipulator.js";import{createCoordinateHelper as S}from"../interactive/coordinateHelper.js";import{createManipulatorDragEventPipeline as D}from"../interactive/dragEventPipeline.js";import{EditGeometry as M,Component as I}from"../interactive/editGeometry/EditGeometry.js";import{EditGeometryOperations as C}from"../interactive/editGeometry/EditGeometryOperations.js";import E from"../interactive/sketch/SketchLabelOptions.js";import P from"../interactive/sketch/SketchTooltipOptions.js";import{SnappingContext as j}from"../interactive/snapping/SnappingContext.js";import{SnappingPipeline as k}from"../interactive/snapping/SnappingDragPipelineStep.js";import{SnappingOperation as G}from"../interactive/snapping/SnappingOperation.js";import{DrawPolygonTooltipInfo as H,DrawPolylineTooltipInfo as L,DrawPointTooltipInfo as Z}from"../interactive/tooltip/DrawTooltipInfos.js";import{Tooltip as A}from"../interactive/tooltip/Tooltip.js";import{computeAreaWithStagedVertex as U,computeLengthWithStagedVertex as z}from"../interactive/tooltip/support/measurements.js";let F=class extends(e.EventedMixin(i)){constructor(t){super(t),this._createOperationCompleted=!1,this._pointerDownStates=new Set,this._snappingPipeline=new k,this._tooltip=null,this._tooltipContext={calculateElevation:null,calculateTotalLength:null,calculateArea:null},this.isDraped=!0,this.labelOptions=new E,this.tooltipOptions=new P,this.snapToSceneEnabled=null,n(t.elevationInfo)&&(this.elevationInfo={mode:t.hasZ?"absolute-height":"on-the-ground",offset:0})}initialize(){const{geometryType:t,view:e}=this,{spatialReference:i}=e,o="viewingMode"in e.state?e.state.viewingMode:V.Local,p="segment"===t||"multipoint"===t?"polyline":t;this.coordinateHelper=S(this.hasZ,this.hasM,i),this._editGeometryOperations=new C(new M(p,this.coordinateHelper)),this._snappingOperation=new G({view:e}),this.handles.add(g((()=>this.stagedVertex),((t,e)=>{r(this._tooltip)&&(r(e)!==r(t)?this._tooltip.info=this._getTooltipInfo():this._updateTooltipInfo()),n(t)||this.emit("cursor-update",{updated:null,vertices:[{componentIndex:0,vertexIndex:this._activeComponent.vertices.length,coordinates:this.coordinateHelper.pointToArray(t)}],operation:"apply",type:"vertex-update"})}),{sync:!0,equals:(t,e)=>c(t,e,T)})),this._activeComponent=new I(i,o),this._editGeometryOperations.data.components.push(this._activeComponent);const l=this.segmentLabels;r(l)&&(l.context={view:e,editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo,labelOptions:this.labelOptions},this.handles.add([g((()=>this.labelOptions.enabled),(t=>{l.visible=t}),u),this.on("cursor-update",(()=>{const t=this.stagedVertex;l.stagedVertex=r(t)?this.coordinateHelper.pointToVector(t):null}))])),this.handles.add(this._editGeometryOperations.on(["vertex-add","vertex-update","vertex-remove"],(t=>{const e=t.vertices.map((t=>({componentIndex:0,vertexIndex:t.index,coordinates:this.coordinateHelper.vectorToArray(t.pos)}))),i=e.map((t=>t.coordinates));switch(t.type){case"vertex-add":this.emit(t.type,{...t,added:i,vertices:e});break;case"vertex-update":this.emit(t.type,{...t,updated:i,vertices:e});break;case"vertex-remove":this.emit(t.type,{...t,removed:i,vertices:e})}}))),this._manipulator=new b({grabbableForEvent:t=>"click"!==this.drawingMode||"touch"===t.pointerType&&this._snappingEnabled&&1===this._pointerDownStates.size}),this.manipulators.add(this._manipulator),this._manipulator.grabbable="point"!==t,this.handles.add([this._createManipulatorDragPipeline(this._manipulator),this._manipulator.events.on("immediate-click",(t=>this._onImmediateClick(t))),this._manipulator.events.on("immediate-double-click",(t=>this._onImmediateDoubleClick(t))),g((()=>this.tooltipOptions.enabled),(t=>{this._tooltip=t?new A({view:e,info:this._getTooltipInfo()}):a(this._tooltip)}),v),this._editGeometryOperations.on(["vertex-add","vertex-update","vertex-remove"],(()=>s(this._tooltip,(t=>{t.info=this._getTooltipInfo()}))))])}destroy(){a(this.segmentLabels),a(this._snappingOperation),this._tooltip=a(this._tooltip),this._editGeometryOperations=a(this._editGeometryOperations)}get _snappingEnabled(){return r(this.snappingManager)&&this.snappingManager.options.effectiveEnabled}get _defaultElevation(){return d(this.defaultZ,"meters")}get canRedo(){return this._editGeometryOperations.canRedo}get canUndo(){return this._editGeometryOperations.canUndo}get committedVertices(){return this._activeComponent.vertices.map((t=>this.coordinateHelper.vectorToArray(t.pos)))}set drawingMode(t){this._set("drawingMode",t??w)}get interactive(){return this._manipulator.interactive}set interactive(t){this._manipulator.interactive=t}get isCompleted(){return this._createOperationCompleted}get numCommittedVertices(){return this._activeComponent.vertices.length}get numVertices(){return r(this.stagedVertex)?this._activeComponent.vertices.length+1:this._activeComponent.vertices.length}get stagedVertex(){return this._snappingOperation.stagedPoint}set stagedVertex(t){this._snappingOperation.stagedPoint=o(t)}get updating(){return this.updatingHandles.updating}get vertices(){const t=this.committedVertices;return r(this.stagedVertex)&&t.push(this.coordinateHelper.pointToArray(this.stagedVertex)),t}get stagedOrLastVertex(){if(r(this.stagedVertex))return this.stagedVertex;const t=this._activeComponent.getLastVertex();return n(t)?null:this._editGeometryOperations.data.coordinateHelper.vectorToDehydratedPoint(t.pos)}cancel(){this.complete({aborted:!0})}commitStagedVertex(){if(this._snappingOperation.abort(),r(this.stagedVertex)){const{stagedVertex:t}=this;this.stagedVertex=null,this._editGeometryOperations.appendVertex(this.coordinateHelper.pointToVector(t))}}complete(t){const e=t&&t.aborted||!1;this._snappingOperation.abort(),r(this.snappingManager)&&this.snappingManager.doneSnapping(),"segment"===this.geometryType||"point"===this.geometryType?this.commitStagedVertex():this.stagedVertex=null;const i="multipoint"===this.geometryType&&0===this.numVertices||"polyline"===this.geometryType&&this.numVertices<2||"polygon"===this.geometryType&&this.numVertices<3;this._createOperationCompleted=!i,(this.isCompleted||e)&&this.emit("complete",{vertices:this.vertices.map(((t,e)=>({componentIndex:0,vertexIndex:e,coordinates:t}))),aborted:e,type:"complete"})}onInputEvent(t){switch(t.type){case"pointer-down":this._pointerDownStates.add(t.pointerId);break;case"pointer-up":this._pointerDownStates.delete(t.pointerId)}switch(t.type){case"pointer-move":return this._onPointerMove(t);case"hold":return this._onHold(t)}}redo(){this._editGeometryOperations.redo()}undo(){r(this.snappingManager)&&this.snappingManager.doneSnapping(),this._editGeometryOperations.undo()}_closeOnClickVertexIndex(t){const e=this._activeComponent;if("polygon"===this.geometryType&&e.vertices.length>2){if(this._vertexWithinPointerDistance(e.vertices[0].pos,t))return 0;if(this._vertexWithinPointerDistance(e.vertices[e.vertices.length-1].pos,t))return e.vertices.length-1}return null}_createManipulatorDragPipeline(t){switch(p(this.drawingMode)){case"click":return this._createManipulatorDragPipelineClick(t);case"freehand":return this._createManipulatorDragPipelineFreehand(t);case"hybrid":return this._createManipulatorDragPipelineHybrid(t)}}_createManipulatorDragPipelineClick(t){return D(t,((t,e,i,o)=>{const n="touch"===o&&this._snappingEnabled;!this.isCompleted&&n&&(e.next(this._screenToMapDragEventStep()).next((t=>("start"===t.action&&(this.stagedVertex=t.mapStart,("segment"===this.geometryType||n&&0===this.numVertices)&&this.commitStagedVertex()),t))).next(this._snappingPipeline.createSnapDragEventPipelineStep({predicate:()=>n,cancel:i,snappingManager:this.snappingManager,snappingContext:new j({editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo,pointer:o,visualizer:this.snappingVisualizer}),updatingHandles:this.updatingHandles}),this._snappingPipeline.next).next((t=>(n&&(this.stagedVertex=t.mapEnd,"end"===t.action&&this.commitStagedVertex()),t))).next((t=>("end"===t.action&&("segment"!==this.geometryType&&"point"!==this.geometryType||this.complete()),t))),i.next((()=>{n&&r(this.snappingManager)&&this.snappingManager.doneSnapping()})))}))}_createManipulatorDragPipelineFreehand(t){return D(t,((t,e)=>{this.isCompleted||e.next(this._screenToMapDragEventStep()).next((t=>("start"===t.action&&(n(this.stagedVertex)&&(this.stagedVertex=t.mapStart),"segment"===this.geometryType&&this.commitStagedVertex()),t))).next((t=>{switch(t.action){case"start":case"update":this.stagedVertex=t.mapEnd,"polygon"!==this.geometryType&&"polyline"!==this.geometryType||this.commitStagedVertex();break;case"end":this.complete()}return t}))}))}_createManipulatorDragPipelineHybrid(t){return D(t,((t,e)=>{this.isCompleted||e.next(this._screenToMapDragEventStep()).next((t=>("start"===t.action&&(n(this.stagedVertex)&&(this.stagedVertex=t.mapStart),this.commitStagedVertex()),t))).next((t=>{switch(t.action){case"start":case"update":this.stagedVertex=t.mapEnd,"polygon"!==this.geometryType&&"polyline"!==this.geometryType||this.commitStagedVertex();break;case"end":"segment"!==this.geometryType&&"point"!==this.geometryType||this.complete()}return t}))}))}_getDrawSurface(){if(n(this.elevationDrawSurface))return this.drawSurface;if(!this.coordinateHelper.hasZ)return this.elevationDrawSurface.defaultZ=null,this.elevationDrawSurface;let t=this.defaultZ,e=!1;r(this.elevationInfo)&&"absolute-height"===this.elevationInfo.mode&&(e=!0),r(this.snapToSceneEnabled)&&(e=this.snapToSceneEnabled),r(this.elevationInfo)&&"on-the-ground"===this.elevationInfo.mode&&(e=!1);const i=this._activeComponent.vertices.length;return("segment"===this.geometryType||"polygon"===this.geometryType)&&i>0&&(t=this.coordinateHelper.getZ(this._activeComponent.vertices[0].pos),e=!1),e?this.drawSurface:(this.elevationDrawSurface.defaultZ=t,this.elevationDrawSurface)}_mapToScreen(t){return this._getDrawSurface().mapToScreen(t)}_onHold(t){this._snappingOperation.abort(),"click"===this.drawingMode&&"touch"===t.pointerType&&this._snappingEnabled&&(this.stagedVertex=t.mapPoint),t.stopPropagation()}_onImmediateClick(t){if("mouse"===t.pointerType&&2===t.button||this._manipulator.dragging)return;const e=this._activeComponent,i=this._closeOnClickVertexIndex(t.screenPoint);if(r(i))return t.stopPropagation(),void this.complete();const o=this._screenToMap(t.screenPoint);if(r(o))switch(this.drawingMode){case"freehand":"point"===this.geometryType&&(r(this.stagedVertex)?this.commitStagedVertex():this._editGeometryOperations.appendVertex(this.coordinateHelper.pointToVector(o)),this.complete());break;case"click":case"hybrid":this._snappingOperation.abort(),r(this.stagedVertex)?this.commitStagedVertex():this._editGeometryOperations.appendVertex(this.coordinateHelper.pointToVector(o)),("point"===this.geometryType||"segment"===this.geometryType&&2===e.vertices.length||"segment"===this.geometryType&&"hybrid"===this.drawingMode&&1===e.vertices.length)&&this.complete()}t.stopPropagation()}_onImmediateDoubleClick(t){this._manipulator.dragging||"point"===this.geometryType||(this.complete(),t.stopPropagation())}_onPointerMove(t){const e=y(t.x,t.y);if(this._manipulator.dragging||this._pointerDownStates.has(t.pointerId)||this._manipulator.grabbing||!this._manipulator.interactive)return void this._snappingOperation.abort();t.stopPropagation();const i=this._closeOnClickVertexIndex(e);if(r(i))return this._closeOnVertex(i),void this._snappingOperation.abort();const o=this._screenToMap(e);if(this._manipulator.cursor=r(o)?"crosshair":null,n(o))return void this._snappingOperation.abort();if(n(this.snappingManager))return this.stagedVertex=o,void this._snappingOperation.abort();const s=this.snappingManager,a=new j({editGeometryOperations:this._editGeometryOperations,elevationInfo:this.elevationInfo,pointer:t.pointerType,visualizer:this.snappingVisualizer});this.updatingHandles.addPromise(h(this._snappingOperation.snap(o,s,a)))}_closeOnVertex(t){this.stagedVertex=null;const e={componentIndex:0,vertexIndex:t,coordinates:this.coordinateHelper.vectorToArray(this._activeComponent.vertices[t].pos)};this.emit("cursor-update",{updated:null,vertices:[e],operation:"apply",type:"vertex-update"})}_screenToMap(t){return this._getDrawSurface().screenToMap(t)}_screenToMapDragEventStep(){let t=null;return e=>{if("start"===e.action&&(t=this._screenToMap(e.screenStart)),n(t))return null;const i=this._screenToMap(e.screenEnd);return r(i)?{...e,mapStart:t,mapEnd:i}:null}}_vertexWithinPointerDistance(t,e){const i=25,o=this._mapToScreen(this.coordinateHelper.vectorToDehydratedPoint(t));return!!r(o)&&R(o,e,i)}_calculateVertexTooltipElevation(t){const{tooltipOptions:e,view:i}=this;if(n(t)||"2d"===i.type)return this._defaultElevation;const o=this.elevationInfo,r=e.elevation.mode,{spatialReference:s}=t,a=_(s),p=O(i,t,o,{mode:r,offset:0});return d(p*a,"meters")}_getTooltipInfo(){const{tooltipOptions:t,stagedOrLastVertex:e}=this;if(n(e))return null;this._tooltipContext.calculateElevation=t=>this._calculateVertexTooltipElevation(t);const i=this._elevationTooltipDetail(e);switch(this.geometryType){case"point":return new Z({tooltipOptions:t,elevation:i});case"polyline":return this._tooltipContext.calculateTotalLength=z(this._editGeometryOperations.data.geometry,this.isDraped?"on-the-ground":"absolute-height"),new L({tooltipOptions:t,elevation:i,totalLength:this._totalLengthTooltipDetail(e)});case"polygon":return this._tooltipContext.calculateArea=U(this._editGeometryOperations.data.geometry,this.isDraped),new H({tooltipOptions:t,elevation:i,area:this._areaTooltipDetail(e)});default:return null}}_elevationTooltipDetail(t){return{mode:this.elevationInfo.mode,...p(this._tooltipContext.calculateElevation)(t)}}_totalLengthTooltipDetail(t){return{...l(p(this._tooltipContext.calculateTotalLength)(t),d(0,"meters"))}}_areaTooltipDetail(t){return{...l(p(this._tooltipContext.calculateArea)(t),m(0,"square-meters"))}}_updateTooltipInfo(){const t=this._tooltip;if(n(t))return;const{stagedOrLastVertex:e}=this,i=this._elevationTooltipDetail(e);switch(this.geometryType){case"point":t.info.elevation=i;break;case"polyline":{const o=t.info;o.elevation=i,o.totalLength=this._totalLengthTooltipDetail(e);break}case"polygon":{const o=t.info;o.elevation=i,o.area=this._areaTooltipDetail(e);break}}}get test(){return{tooltip:this._tooltip}}};function R(t,e,i){const o=t.x-e.x,n=t.y-e.y;return o*o+n*n<=i}t([x()],F.prototype,"_defaultElevation",null),t([x()],F.prototype,"defaultZ",void 0),t([x()],F.prototype,"isDraped",void 0),t([x({value:w})],F.prototype,"drawingMode",null),t([x({constructOnly:!0})],F.prototype,"elevationDrawSurface",void 0),t([x({constructOnly:!0})],F.prototype,"elevationInfo",void 0),t([x({constructOnly:!0,type:E})],F.prototype,"labelOptions",void 0),t([x({constructOnly:!0,type:P})],F.prototype,"tooltipOptions",void 0),t([x({constructOnly:!0})],F.prototype,"geometryType",void 0),t([x({constructOnly:!0})],F.prototype,"hasM",void 0),t([x({constructOnly:!0})],F.prototype,"hasZ",void 0),t([x({constructOnly:!0})],F.prototype,"manipulators",void 0),t([x({constructOnly:!0})],F.prototype,"drawSurface",void 0),t([x({constructOnly:!0})],F.prototype,"segmentLabels",void 0),t([x({constructOnly:!0})],F.prototype,"snappingManager",void 0),t([x({constructOnly:!0})],F.prototype,"snappingVisualizer",void 0),t([x()],F.prototype,"snapToSceneEnabled",void 0),t([x()],F.prototype,"_snappingOperation",void 0),t([x()],F.prototype,"stagedVertex",null),t([x()],F.prototype,"updating",null),t([x({constructOnly:!0})],F.prototype,"view",void 0),F=t([f("esri.views.draw.DrawOperation")],F);export{F as DrawOperation};
|