UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 6.28 kB
import t from"../../../../../Color.js";import{getAccentColor as e,getContrastColor as i}from"../../../../../core/analysisThemeUtils.js";import s from"../../../../../core/Handles.js";import{clone as a}from"../../../../../core/lang.js";import{destroyMaybe as n,isSome as l,isNone as r,unwrap as o}from"../../../../../core/maybe.js";import{watch as h,sync as d}from"../../../../../core/reactiveUtils.js";import{screenPointObjectToArray as _}from"../../../../../core/screenUtils.js";import{c as u}from"../../../../../chunks/vec3f64.js";import{createSphereManipulator as p}from"../../manipulatorUtils.js";import{PickResult as c}from"../support/PickRequest.js";import{LaserlineVisualElement as g}from"../../visualElements/LaserlineVisualElement.js";import{newIntersector as m}from"../../../webgl-engine/lib/Intersector.js";import{StoreResults as w}from"../../../webgl-engine/lib/IntersectorInterfaces.js";import{ManipulatorCollection as y}from"../../../../interactive/ManipulatorCollection.js";class f{constructor(s){this.vertexManipulators=[],this._destroyed=!1,this._isManipulatorsOwner=!0,this._visible=!0,this._laserLine=null,this._cursorManipulator=null,this._listenerHandles=null,this._tempHandlePosition=u(),this._defaultStyle={laserLineGlowColor:t.toUnitRGB(e()),laserLineGlowWidth:8,laserLineGlowFalloff:8,laserLineInnerColor:t.toUnitRGB(i()),laserLineInnerWidth:1,laserLineGlobalAlpha:.75,laserLineEnabled:!0,handleColor:t.toUnitRGB(e()),handleOpacity:.5,handleRadius:5,handleRadiusHovered:10,handleRadiusMouse:10,handleRadiusTouch:25};const{analysisViewData:n,manipulators:l,toolState:r,view:o,visible:h}=s;this._analysisViewData=n,this._toolState=r,null!=l?(this._manipulators=l,this._isManipulatorsOwner=!1):this._manipulators=new y,this._view=o;const d=this._style={...this._defaultStyle,...a(s.style)};this._intersector=m(o.state.viewingMode),this._intersector.options.store=w.MIN;const _=p(o,d.handleColor,d.handleOpacity);_.available=!1,_.radius=d.handleRadius,_.interactive=!1,this._manipulators.add(_),this._cursorManipulator=_,this._laserLine=new g({view:o,attached:!0,style:{glowColor:d.laserLineGlowColor,glowWidth:d.laserLineGlowWidth,glowFalloff:d.laserLineGlowFalloff,innerColor:d.laserLineInnerColor,innerWidth:d.laserLineInnerWidth,globalAlpha:d.laserLineGlobalAlpha}}),this._updateVisibility(h||!0)}destroy(){this._listenerHandles=n(this._listenerHandles),this._isManipulatorsOwner?this._manipulators=n(this._manipulators):this._manipulators=null,this._laserLine=n(this._laserLine),this._destroyed=!0}get destroyed(){return this._destroyed}get visible(){return this._visible}set visible(t){t?this.show():this.hide()}get testData(){const t=this._laserLine.testData;return{laserLineRenderer:l(t)?{heightManifoldEnabled:t.heightManifoldEnabled,heightManifoldTarget:t.heightManifoldTarget,pointDistanceEnabled:t.pointDistanceEnabled,pointDistanceOrigin:t.pointDistanceOrigin,pointDistanceTarget:t.pointDistanceTarget,lineVerticalPlaneEnabled:t.lineVerticalPlaneEnabled}:{heightManifoldEnabled:!1,heightManifoldTarget:null,pointDistanceEnabled:!1,pointDistanceOrigin:null,pointDistanceTarget:null,lineVerticalPlaneEnabled:!1}}}show(){this._setVisibility(!0)}hide(){this._setVisibility(!1)}_setVisibility(t){this._destroyed||this._visible===t||this._updateVisibility(t)}_updateVisibility(t){this._visible=t,this._laserLine.visible=t,t?(this._initializeListeners(),this._updateAll()):(this._destroyListeners(),this.vertexManipulators.forEach((t=>this._removeVertexManipulator(t))),this.vertexManipulators=[],this._view.cursor=null)}vertexHandleAt(t,e){const i=this._manipulators.intersect(t,e);return l(i)?i.metadata:null}pick(t){const e=this._view.spatialReference,i=_(t.screenPoint);this._view.sceneIntersectionHelper.intersectToolIntersectorScreen(i,this._intersector);const s=this._intersector.results.min,a=u();if(!s.getIntersectionPoint(a))return null;const n=this._view.renderCoordsHelper.fromRenderCoords(a,e);return r(n)?null:new c(a,n)}_updateAll(){this._visible&&(this._updateVertexManipulators(),this._updateLaserLine())}_createVertexManipulator(){const t=p(this._view,this._style.handleColor,this._style.handleOpacity);return t.radius=this._style.handleRadius,this._manipulators.add(t),t}_removeVertexManipulator(t){this._manipulators.remove(t)}_updateVertexManipulators(){const{viewData:t}=this._analysisViewData,e=this._analysisViewData.path?this._analysisViewData.path.vertices:[],i=this.vertexManipulators;v(i,e.length,(()=>this._createVertexManipulator()),(t=>this._removeVertexManipulator(t))),i.forEach(((i,s)=>{i.metadata=e[s],i.renderLocation=t.positionsRenderCoords[s],i.cursor=0===s&&"drawing"===this._toolState.polygonState?"crosshair":null})),"drawing"===this._toolState.polygonState&&l(this._analysisViewData.cursorPoint)?(this._cursorManipulator.available=!0,this._cursorManipulator.location=this._analysisViewData.cursorPoint):this._cursorManipulator.available=!1}_getFocusPoint(){const{lastDraggedVertex:t}=this._analysisViewData;switch(this._toolState.polygonState){case"drawing":return l(this._analysisViewData.cursorPoint)?this._analysisViewData.cursorPoint:l(t)?this._analysisViewData.path.getVertexPositionAsPoint(t):o(this._analysisViewData.path.lastPoint);case"editing":return l(t)?this._analysisViewData.path.getVertexPositionAsPoint(t):null;default:return this._analysisViewData.cursorPoint}}_updateLaserLine(){const t=this._style.laserLineEnabled&&"measured"!==this._toolState.polygonState&&this._toolState.active,e=this._getFocusPoint();if(t&&l(e)){const t=this._tempHandlePosition;this._view.renderCoordsHelper.toRenderCoords(e,t),this._laserLine.heightManifoldTarget=t}else this._laserLine.heightManifoldTarget=null}_initializeListeners(){this._listenerHandles=new s,this._listenerHandles.add([h((()=>this._toolState.polygonState),(()=>this._updateLaserLine())),h((()=>this._analysisViewData.viewData),(()=>this._updateAll()),d),h((()=>({lastDraggedVertex:this._analysisViewData.lastDraggedVertex,cursorPoint:this._analysisViewData.cursorPoint})),(()=>this._updateLaserLine())),h((()=>this._toolState.active),(()=>this._updateAll()))])}_destroyListeners(){this._listenerHandles=n(this._listenerHandles)}}function v(t,e,i,s){for(;t.length<e;)t.push(i());if(s)for(;t.length>e;){s(t.pop())}else t.length=e}export{f as default};