UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 13.7 kB
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../Color.js";import i from"../../../../analysis/LineOfSightAnalysisObserver.js";import a from"../../../../analysis/LineOfSightAnalysisTarget.js";import r from"../../../../core/Handles.js";import n from"../../../../core/Logger.js";import{destroyMaybe as s,isSome as o,isNone as l,applySome as c}from"../../../../core/maybe.js";import{watch as u,syncAndInitial as h,initial as p}from"../../../../core/reactiveUtils.js";import{property as d}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as g}from"../../../../core/accessorSupport/decorators/subclass.js";import{WatchUpdatingTracking as _}from"../../../../core/support/WatchUpdatingTracking.js";import{create as m,fromPoints as v}from"../../../../geometry/support/lineSegment.js";import{getGraphicEffectiveElevationInfo as b,getConvertedElevation as y}from"../../../../support/elevationInfoUtils.js";import f from"../../../../symbols/support/ElevationInfo.js";import{LineOfSightRayIntersector as T}from"./LineOfSightRayIntersector.js";import{LineOfSightToolConfiguration as C}from"./LineOfSightToolConfiguration.js";import{createSphereManipulator as w,createSphereManipulatorRenderObjects as M}from"./lineOfSightToolUtils.js";import{LaserlineVisualElement as L}from"../../interactive/visualElements/LaserlineVisualElement.js";import{IntersectorType as k}from"../../webgl-engine/lib/IntersectorInterfaces.js";import"../../../input/ViewEvents.js";import{AnalysisToolBase as V}from"../../../interactive/AnalysisToolBase.js";import{createManipulatorDragEventPipeline as O}from"../../../interactive/dragEventPipeline.js";import{ManipulatorStateCustomFlags as S}from"../../../interactive/interfaces.js";import{createScreenPointFromEvent as D}from"../../../support/screenUtils.js";import{MouseButton as E}from"../../../input/IViewEvents.js";var I;!function(e){e.Ready="ready",e.Creating="creating",e.Created="created"}(I||(I={}));let P=class extends V{constructor(e){super(e),this.removeIncompleteOnCancel=!1,this.configuration=new C,this.analysisViewData=null,this._latestPointerMovePointerType=null,this._laserlineVisualElement=null,this._grabbedManipulator=null,this._analysisHandles=new r,this._handles=new r,this._updatingHandles=new _,this._manipulatorHandles=new r,this._targetTrackerManipulator=null}initialize(){this._intersector=new T({view:this.view}),this._handles.add(u((()=>this.state),(e=>{e===I.Created&&this.finishToolCreation()}),h)),this._observerManipulator=this._createObserverManipulator(),this._handles.add([this._updatingHandles.add((()=>({...this.configuration.observer})),(()=>this._updateObserverManipulatorStyle())),this._updatingHandles.add((()=>this.analysisViewData?.elevationAlignedObserver),(e=>this._onObserverLocationChange(e)),p),this._updatingHandles.add((()=>({...this.configuration.laserLine})),(()=>this._createVisualElements()),p),this._updatingHandles.add((()=>this._laserLineRendererDependencies()),(e=>this._updateLaserLineRenderer(e))),this._connectComputations(),this._updatingHandles.addWhen((()=>!this._shouldRenderTracker),(()=>this._clearCursorTracker()),p)])}destroy(){this._updatingHandles=s(this._updatingHandles),this._handles=s(this._handles),this._manipulatorHandles=s(this._manipulatorHandles),this._analysisHandles=s(this._analysisHandles),this._observerManipulator=null,this._clearCursorTracker(),this._removeVisualElements(),this._intersector=null,this._set("analysis",null)}get state(){return this.active?this.hasGrabbedManipulators?I.Created:I.Creating:o(this.analysis.observer)&&o(this.analysis.observer.position)?I.Created:I.Ready}get cursor(){return this.active&&this._showTracker?"crosshair":null}get updating(){return o(this.analysisViewData)&&this.analysisViewData.updating||this._updatingHandles.updating}get _showTracker(){return this.active&&"mouse"===this._latestPointerMovePointerType}get _shouldRenderTracker(){return this._showTracker&&o(this.analysis.observer)&&o(this.analysis.observer.position)&&!this.hasGrabbedManipulators}continue(){this.view.activeTool=this}stop(){this.view.activeTool=null}onEditableChange(){this.analysisViewData.editable=this.internallyEditable}onInputEvent(e){switch(e.type){case"immediate-double-click":this._doubleClickHandler(e);break;case"key-down":this._keyDownHandler(e);break;case"pointer-move":this._pointerMoveHandler(e)}}onInputEventAfter(e){if("immediate-click"===e.type)this._clickHandler(e)}onShow(){}onHide(){}onDeactivate(){this._clearCursorTracker()}_connectComputations(){return this._updatingHandles.addOnCollectionChange((()=>this.analysisViewData.computations),(e=>this._onComputationsCollectionChange(e)),{initial:!0,final:!0})}_onComputationsCollectionChange({added:e,removed:t}){for(const i of t)this._disconnectComputation(i);for(const i of e)this._connectComputation(i)}_connectComputation(e){if(this.destroyed)return void n.getLogger(this.declaredClass).warn("Attempting to connect an analysis to a destroyed LineOfSight tool. Ignoring.");const t=this._analysisHandles;if(t.has(e))return;const i=this._createTargetManipulator(e.target);l(this._targetTrackerManipulator)&&i.metadata.target===this.analysisViewData.cursorTarget&&(this._targetTrackerManipulator=i,this._targetTrackerManipulator.available=!1,this._targetTrackerManipulator.interactive=!1,this._updateLaserLineRenderer()),t.add([this._updatingHandles.add((()=>this._getLineOfSightManipulatorStateDependencies(e)),(()=>this._updateManipulatorState(i,e)),p),this._updatingHandles.add((()=>e.elevationAlignedTargetLocation),(e=>this._onTargetLocationChange(e,i)),p)],e)}_disconnectComputation(e){if(this.destroyed)return void n.getLogger(this.declaredClass).warn("Attempting to disconnect an analysis from a destroyed LineOfSight tool. Ignoring.");this._analysisHandles.remove(e);const t=this._getTargetManipulator(e.target);o(t)&&(this.manipulators.remove(t),this._manipulatorHandles.remove(t),o(this._targetTrackerManipulator)&&this._targetTrackerManipulator===t&&(this._targetTrackerManipulator=null))}_clearCursorTracker(){this.analysisViewData.cursorTarget=s(this.analysisViewData.cursorTarget)}_createManipulator(e,t,i){const a=w(this.view,e);return a.metadata=i,this._manipulatorHandles.add([t(a),a.events.on("grab-changed",(e=>this._manipulatorGrabChanged(a,e))),a.events.on("immediate-click",(e=>this._manipulatorClick(a,e)))],a),this.manipulators.add(a),a}_createTargetManipulator(e){const t=this.configuration,i={size:t.target.size,customColor1:t.target.visibleColor,customColor2:t.target.occludedColor,customColor3:t.target.undefinedColor,visible:!0},a={target:e,type:"target"},r=this._createManipulator(i,(e=>this._createTargetManipulatorDragPipeline(e)),a);return o(e.position)?r.elevationAlignedLocation=e.position:r.available=!1,r}_getTargetManipulator(e){let t=null;return this.manipulators.forEach((i=>{const a=i.manipulator;l(t)&&"target"===a.metadata.type&&a.metadata.target===e&&(t=a)})),t}_createObserverManipulator(){const e=this.configuration,t={size:e.observer.size,color:e.observer.color,visible:!0};return this._createManipulator(t,(e=>this._createObserverManipulatorDragPipeline(e)),{type:"observer",intersection:null})}_updateObserverManipulatorStyle(){const e=this._observerManipulator,t=this.configuration.observer,i={size:t.size,color:t.color,visible:e.available};e.renderObjects=M(i)}_screenToIntersection(){return e=>{const t=this._intersector.getScreenPointIntersection(e.screenEnd);return l(t)?null:{...e,intersection:t}}}_createTargetManipulatorDragPipeline(e){return O(e,((t,i,a)=>{i.next(this._screenToIntersection()).next(this._updateTargetDragStep(e)).next((()=>this._updateLaserLineRenderer())),a.next(this._cancelTargetDragStep(e.metadata.target)).next((()=>this._updateLaserLineRenderer()))}))}_createObserverManipulatorDragPipeline(e){return O(e,((e,t,i)=>{t.next(this._screenToIntersection()).next(this._updateObserverDragStep()).next((()=>this._updateLaserLineRenderer())),i.next(this._cancelObserverDragStep()).next((()=>this._updateLaserLineRenderer()))}))}_updateObserverDragStep(){return e=>(o(e.intersection.mapPoint)?(l(this.analysis.observer)&&(this.analysis.observer=new i),this._updateFromIntersection(this.analysis.observer,e.intersection)):this.analysis.observer=null,e)}_cancelObserverDragStep(){const e=o(this.analysis.observer)&&o(this.analysis.observer.position)?this.analysis.observer.clone():null;return t=>(this.analysis.observer=e,t)}_updateTargetDragStep(e){return t=>{this._updateFromIntersection(e.metadata.target,t.intersection);const i=t.intersection.mapPoint;return o(i)&&(e.elevationAlignedLocation=i),t}}_cancelTargetDragStep(e){const t=c(e.position,(e=>e.clone()));return i=>(e.position=t,i)}_manipulatorGrabChanged(e,t){switch(t.action){case"start":this._grabbedManipulator=e;break;case"end":this._grabbedManipulator===e&&(this._grabbedManipulator=null)}}_updateManipulatorState(e,t){const{isValid:i,isTargetVisible:a}=t.computationResult;e.state=i?a?S.Custom1:S.Custom2:S.Custom3}_getLineOfSightManipulatorStateDependencies(e){const{isValid:t,isTargetVisible:i}=e.computationResult;return{isValid:t,isTargetVisible:i}}_laserLineRendererDependencies(){return{laserlineVisualElement:this._laserlineVisualElement,grabbedManipulator:this._grabbedManipulator,shouldRenderTracker:this._shouldRenderTracker,observerPosition:o(this.analysis.observer)?this.analysis.observer.position:null,visible:this.visible}}_updateLaserLineRenderer(e=this._laserLineRendererDependencies()){const{laserlineVisualElement:t,grabbedManipulator:i,shouldRenderTracker:a,observerPosition:r,visible:n}=e;if(l(t))return;const s=o(i)?i:a&&o(r)?this._targetTrackerManipulator:null;this.configuration.laserLine.enabled&&o(s)&&n?(t.visible=!0,t.heightManifoldTarget=s.renderLocation,s!==this._observerManipulator?t.lineVerticalPlaneSegment=v(this._observerManipulator.renderLocation,s.renderLocation,H):t.lineVerticalPlaneSegment=null):(t.visible=!1,t.heightManifoldTarget=null,t.lineVerticalPlaneSegment=null)}_createVisualElements(){const e=this.configuration.laserLine;this._removeVisualElements(),this._laserlineVisualElement=new L({view:this.view,attached:!0,visible:this.visible,style:{glowColor:t.toUnitRGB(e.glowColor),glowWidth:e.glowWidth,innerColor:t.toUnitRGB(e.innerColor),innerWidth:e.innerWidth,globalAlpha:e.globalAlpha}})}_removeVisualElements(){o(this._laserlineVisualElement)&&(this._laserlineVisualElement.destroy(),this._laserlineVisualElement=null)}_onObserverLocationChange(e){l(e)?this._observerManipulator.available=!1:(this._observerManipulator.metadata.intersection=null,this._observerManipulator.available=!0,this._observerManipulator.elevationAlignedLocation=e)}_onTargetLocationChange(e,t){o(e)?(t.elevationAlignedLocation=e,t!==this._targetTrackerManipulator&&(t.available=!0)):t.available=!1}_addPointFromClickEvent(e){const t=this._intersector.getScreenPointIntersection(e);if(!l(t)&&!l(t.mapPoint))if(o(this.analysis.observer)&&o(this.analysis.observer.position)){this._clearCursorTracker();const e=new a;this._updateFromIntersection(e,t),this.analysis.targets.add(e)}else{const e=new i;this._updateFromIntersection(e,t),this.analysis.observer=e}}_clickHandler(e){this.active&&e.button!==E.Right&&(this._addPointFromClickEvent(D(e)),e.stopPropagation())}_doubleClickHandler(e){this.active&&e.button!==E.Right&&(this.stop(),e.stopPropagation())}_keyDownHandler(e){this.active&&"Escape"===e.key&&(this.stop(),e.stopPropagation())}_pointerMoveHandler(e){if(this.hasGrabbedManipulators)return;if(this._latestPointerMovePointerType=e.pointerType,this._updateLaserLineRenderer(),!this._showTracker||l(this.analysis.observer)||l(this.analysis.observer.position))return;const t=D(e),i=this._intersector.getScreenPointIntersection(t);o(i)&&o(i.mapPoint)&&(l(this.analysisViewData.cursorTarget)&&(this.analysisViewData.cursorTarget=new a),this._updateFromIntersection(this.analysisViewData.cursorTarget,i),this._updateLaserLineRenderer())}_updateFromIntersection(e,t){if(l(t.mapPoint))return e.position=null,e.elevationInfo=null,void(e.feature=null);switch(t.type){case k.OBJECT:if(o(t.graphic)){const i=t.graphic,a=b(i);"on-the-ground"===a.mode&&(a.mode="relative-to-ground",a.offset=0),e.elevationInfo=new f(a),e.feature=i}else e.elevationInfo=null,e.feature=null;break;case k.TERRAIN:case k.I3S:e.elevationInfo=new f({mode:"on-the-ground"}),e.feature=null;break;default:e.elevationInfo=null,e.feature=null}const i=t.mapPoint.clone();i.z=y(this.view,i,{mode:"absolute-height",offset:0},e.elevationInfo),e.position=i}_manipulatorClick(e,t){if("observer"===e.metadata.type||e.grabbing||e.dragging||t.button!==E.Right||this.analysis.targets.length<=1)return;const{target:i}=e.metadata;this.analysis.targets.remove(i),t.stopPropagation()}get testInfo(){return{laserLineVisualElement:this._laserlineVisualElement}}};e([d({constructOnly:!0})],P.prototype,"view",void 0),e([d({constructOnly:!0})],P.prototype,"analysis",void 0),e([d({readOnly:!0})],P.prototype,"state",null),e([d({readOnly:!0})],P.prototype,"cursor",null),e([d()],P.prototype,"removeIncompleteOnCancel",void 0),e([d({readOnly:!0})],P.prototype,"updating",null),e([d({type:C})],P.prototype,"configuration",void 0),e([d({constructOnly:!0})],P.prototype,"analysisViewData",void 0),e([d({readOnly:!0})],P.prototype,"_showTracker",null),e([d()],P.prototype,"_latestPointerMovePointerType",void 0),e([d()],P.prototype,"_shouldRenderTracker",null),e([d()],P.prototype,"_laserlineVisualElement",void 0),e([d()],P.prototype,"_grabbedManipulator",void 0),P=e([g("esri.views.3d.interactive.analysisTools.lineOfSight.LineOfSightTool")],P);const H=m();export{P as LineOfSightTool};