@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 8.52 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as t}from"../../../../../chunks/tslib.es6.js";import"../../../../../core/has.js";import{destroyMaybe as e}from"../../../../../core/maybe.js";import{memoize as i}from"../../../../../core/memoize.js";import{watch as n,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import{property as s}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as r}from"../../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as o}from"../../../../../core/support/UpdatingHandles.js";import l from"../../../../../geometry/Point.js";import{clonePoint as u}from"../../../../../layers/graphics/hydratedFeatures.js";import{isPrimaryPointerAction as p}from"../../../analysis/support/measurementUtils.js";import{SnappingVisualizer3D as c}from"../../SnappingVisualizer3D.js";import{SurfaceType as d,screenToMap3D as h,hideManipulatorWhileDragging as m}from"../../editingTools/dragEventPipeline3D.js";import{DirectLineMeasurement3DView as g}from"./DirectLineMeasurement3DView.js";import{getElevationAtPoint as v}from"../../../support/ElevationProvider.js";import{AnalysisToolBase as y}from"../../../../interactive/AnalysisToolBase.js";import{createCoordinateHelper as P}from"../../../../interactive/coordinateHelper.js";import{createManipulatorDragEventPipeline as f,resetProperties as w}from"../../../../interactive/dragEventPipeline.js";import{EditGeometry as _}from"../../../../interactive/editGeometry/EditGeometry.js";import{EditGeometryOperations as S}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import{SnappingContext as M}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as D}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{acquire as j}from"../../../../interactive/snapping/SnappingManagerPool.js";import{setupSnappingToggleHandles as b}from"../../../../interactive/snapping/snappingUtils.js";import{createScreenPointFromEvent as L}from"../../../../support/screenUtils.js";let x=class extends y{constructor(t){super(t),this._updatingHandles=new o,this._emulatedDrag=null,this.lineState="initial",this.startPointSurfaceLocation=null,this.endPointSurfaceLocation=null,this.cursorPointSurfaceLocation=null,this.startManipulator=null,this.endManipulator=null,this.cursorManipulator=null,this._getSnappingContext=i((t=>new M({elevationInfo:{mode:"absolute-height",offset:0},pointer:t,editGeometryOperations:new S(new _("point",P(!0,!1,this.view.spatialReference)),this.view.state.viewingMode),visualizer:new c})))}initialize(){const{view:t,analysis:e,analysisViewData:i,visible:s}=this;this.measurementView=new g({toolState:this,view:t,analysis:e,analysisViewData:i,visible:s});const r=j(t);this._snappingManagerResult=r,this.addHandles(r);const{start:o,end:p,cursor:c}=this.measurementView.createManipulators(),d=(t,e,i)=>f(t,((t,n,a,s)=>{const r=m(t),o=this._snappingManager,p=this._getSnappingContext(s),c=this._updatingHandles,{lineState:d}=this;a=a.next(r).next(w(this,[i,e])).next((i=>{if("cursorPoint"!==e){const i=this.analysis[e];null!=i&&(t.location=i)}return i}));const g=h(this.view),v=t=>{const n=g(t);return n||"drawing"!==this.lineState&&"initial"!==this.lineState||(this[e]=null,this[i]=null),n};let y=n.next(r).next(v);if("touch"!==s||"editing"===d){const{snappingStep:t,cancelSnapping:e}=D({snappingManager:o,snappingContext:p,updatingHandles:c});a=a.next(e),y=y.next(...t)}y.next((t=>"start"!==t.action?t:null)).next((n=>{const a=u(n.mapEnd,new l);this[e]=a,t.location=a,this[i]=this._surfaceLocation(a,n.surfaceType)}))})),v=t=>t.events.on("grab-changed",(()=>{const t=o.grabbing||p.grabbing;this.lineState=t?"editing":"measured"}));this.addHandles([d(o,"startPoint","startPointSurfaceLocation"),d(p,"endPoint","endPointSurfaceLocation"),d(c,"cursorPoint","cursorPointSurfaceLocation"),v(o),v(p)]),this.manipulators.add(o),this.manipulators.add(p),this.manipulators.add(c),this.startManipulator=o,this.endManipulator=p,this.cursorManipulator=c,this.addHandles(n((()=>this.state),(t=>{"measured"===t&&this.finishToolCreation()}),a)),b(this)}destroy(){this._updatingHandles=e(this._updatingHandles),this.measurementView=e(this.measurementView)}get _snappingManager(){return this._snappingManagerResult.snappingManager}get state(){const{analysis:t}=this;if(null==t.startPoint&&null==t.endPoint)return"ready";const{lineState:e}=this;return this.validMeasurement&&"editing"!==e&&"drawing"!==e?"measured":"measuring"}get cursor(){return"ready"===this.state||"drawing"===this.lineState?"crosshair":null}get startPoint(){return this.analysis.startPoint}set startPoint(t){this.analysis.startPoint=t}get endPoint(){return this.analysis.endPoint}set endPoint(t){this.analysis.endPoint=t}get cursorPoint(){return this.measurementView.cursorPoint}set cursorPoint(t){this.measurementView.cursorPoint=t}get snappingOptions(){return this._snappingManager.options}get validMeasurement(){return null!=this.analysis.startPoint&&null!=this.analysis.endPoint}get updating(){return this._updatingHandles.updating||this._snappingManager.updating}onShow(){this.measurementView.show(),this._updateManipulatorAvailability()}onHide(){this.measurementView.hide()}onDeactivate(){this._emulatedDrag?.cancel(),this._emulatedDrag=null}onInputEvent(t){switch(t.type){case"immediate-click":this._handleImmediateClick(t);break;case"pointer-move":this._handlePointerMove(t)}this._updateManipulatorAvailability()}_handlePointerMove(t){if(!this.active||this.view.navigating)return;const{pointerType:e}=t;if("mouse"!==e)return;const i=L(t),{lineState:n,cursorManipulator:a,endManipulator:s}=this;let r=!1;null==this.cursorPoint&&(this._emulatedDrag?.cancel(),this._emulatedDrag=V(a,e,i),r=!0),"initial"===n&&(this._emulatedDrag?.update(i),r=!0),"drawing"===n&&(s.events.emit("drag",{action:"update",start:i,screenPoint:i}),r=!0),r&&t.stopPropagation()}_handleImmediateClick(t){if(!this.active)return;if(!p(t))return;const e=L(t),{pointerType:i}=t,{cursorManipulator:n,startManipulator:a,endManipulator:s,lineState:r}=this;let o=!1;switch(null==this.cursorPoint&&(this._emulatedDrag?.cancel(),this._emulatedDrag=V(n,i,e)),r){case"initial":if(this._emulatedDrag?.update(e),null!=this.cursorPoint){this._emulatedDrag?.end(e),this._emulatedDrag=null;const{cursorPoint:t}=this;this.startPoint=t,this.startPointSurfaceLocation=this.cursorPointSurfaceLocation,a.location=t,a.interactive=!1,s.interactive=!1,this.lineState="drawing",this._emulatedDrag=V(s,i,e),o=!0}break;case"drawing":this._emulatedDrag?.update(e),null!=this.endPoint&&(this._emulatedDrag?.end(e),this._emulatedDrag=null,a.interactive=!0,s.interactive=!0,this.lineState="measured",o=!0)}o&&t.stopPropagation()}_surfaceLocation(t,e){return e===d.GROUND?"on-the-surface":(t.z??0)>=this._getElevation(t)?"above-the-surface":"below-the-surface"}_updateManipulatorAvailability(){this.startManipulator.available=null!=this.analysis.startPoint,this.endManipulator.available=null!=this.analysis.endPoint}_getElevation(t){return this.view.basemapTerrain.ready?v(this.view.elevationProvider,t)??0:0}get test(){}};function V(t,e,i){return t.events.emit("drag",{action:"start",pointerType:e,start:i,screenPoint:i}),{update:e=>t.events.emit("drag",{action:"update",start:e,screenPoint:e}),end:e=>t.events.emit("drag",{action:"end",start:e,screenPoint:e}),cancel:()=>t.events.emit("drag",{action:"cancel"})}}t([s({readOnly:!0})],x.prototype,"state",null),t([s()],x.prototype,"lineState",void 0),t([s({readOnly:!0})],x.prototype,"cursor",null),t([s()],x.prototype,"startPoint",null),t([s()],x.prototype,"endPoint",null),t([s()],x.prototype,"cursorPoint",null),t([s({constructOnly:!0})],x.prototype,"analysis",void 0),t([s({constructOnly:!0})],x.prototype,"analysisViewData",void 0),t([s()],x.prototype,"measurementView",void 0),t([s({constructOnly:!0})],x.prototype,"view",void 0),t([s({readOnly:!0})],x.prototype,"validMeasurement",null),t([s({value:null})],x.prototype,"startPointSurfaceLocation",void 0),t([s({value:null})],x.prototype,"endPointSurfaceLocation",void 0),t([s({value:null})],x.prototype,"cursorPointSurfaceLocation",void 0),t([s()],x.prototype,"updating",null),x=t([r("esri.views.3d.interactive.measurementTools.directLineMeasurement3D.DirectLineMeasurement3DTool")],x);const H=x;export{H as default};