@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.79 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{multiplyOpacityToUnitRGBA as t,colorEquals as e,getContrast as i}from"../../../../../core/colorUtils.js";import s from"../../../../../core/Handles.js";import"../../../../../core/has.js";import{destroyMaybe as a}from"../../../../../core/maybe.js";import{watch as r,sync as o}from"../../../../../core/reactiveUtils.js";import{screenPointObjectToArray as n}from"../../../../../core/screenUtils.js";import{create as l}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import h from"../../../../../geometry/Point.js";import{Manipulator3D as _}from"../../Manipulator3D.js";import{createManipulatorMaterial as u}from"../../manipulatorUtils.js";import{RenderObject as p}from"../../RenderObject.js";import{PickResult as d}from"../support/PickRequest.js";import{LaserlineVisualElement as c}from"../../visualElements/LaserlineVisualElement.js";import{createSphereGeometry as m}from"../../../webgl-engine/lib/GeometryUtil.js";import{ManipulatorCollection as w}from"../../../../interactive/ManipulatorCollection.js";import{newToolIntersector as v}from"../../../../interactive/ToolIntersector.js";class g{constructor(t){this.vertexManipulators=[],this._destroyed=!1,this._isManipulatorsOwner=!0,this._visible=!0,this._listenerHandles=null,this._tempHandlePosition=l();const{analysisViewData:e,manipulators:i,toolState:s,view:a,visible:r}=t;this._analysisViewData=e,this._toolState=s,null!=i?(this._manipulators=i,this._isManipulatorsOwner=!1):this._manipulators=new w,this._view=a,this._intersector=v(a.state.viewingMode);const o=u(this._handleColor);o.setParameters({testsTransparentRenderOrder:4});const n=[new p(m(o,1,32,32))],h=new _({view:a,renderObjects:n});h.available=!1,h.radius=D,h.interactive=!1,this._manipulators.add(h),this._cursorManipulator=h,this._manipulatorMaterial=o,this._laserLine=new c({view:a,attached:!0,style:{glowWidth:f,glowFalloff:V,innerWidth:b},isDecoration:!0}),this._updateVisibility(r??!0)}destroy(){this._listenerHandles=a(this._listenerHandles),this._isManipulatorsOwner?this._manipulators=a(this._manipulators):this._manipulators=null,this._laserLine=a(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(){}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=[])}vertexHandleAt(t,e){const i=this._manipulators.intersect(t,e);return i?.metadata}pick(t){const e=this._view.spatialReference,i=n(t.screenPoint);this._view.sceneIntersectionHelper.intersectToolIntersectorScreen(i,this._intersector);const s=this._intersector.results.min,a=l();if(!s.getIntersectionPoint(a))return null;const r=this._view.renderCoordsHelper.fromRenderCoords(a,new h({spatialReference:e}));return null==r?null:new d(a,r)}_updateAll(){this._visible&&(this._updateVertexManipulators(),this._updateLaserLine())}_createVertexManipulator(){const t=[new p(m(this._manipulatorMaterial,1,32,32))],e=new _({view:this._view,renderObjects:t});return e.radius=D,this._manipulators.add(e),e}_removeVertexManipulator(t){this._manipulators.remove(t)}_updateVertexManipulators(){const{viewData:t}=this._analysisViewData,e=this._analysisViewData.path?this._analysisViewData.path.vertices:[],i=this.vertexManipulators;y(i,e.length,()=>this._createVertexManipulator(),t=>this._removeVertexManipulator(t)),i.forEach((i,s)=>{i.metadata=e[s],i.renderLocation=t.vertexData.positionsRender[s],i.cursor=0===s&&"drawing"===this._toolState.polygonState?"crosshair":null}),"drawing"===this._toolState.polygonState&&null!=this._analysisViewData.stagedPoint?(this._cursorManipulator.available=!0,this._cursorManipulator.location=this._analysisViewData.stagedPoint):this._cursorManipulator.available=!1}get _handleColor(){return t(this._view.effectiveTheme.accentColor,.5)}_getFocusPoint(){const{lastDraggedVertex:t}=this._analysisViewData;switch(this._toolState.polygonState){case"drawing":return null!=this._analysisViewData.stagedPoint?this._analysisViewData.stagedPoint:null!=t?this._analysisViewData.path.getVertexPositionAsPoint(t):this._analysisViewData.path.lastPoint;case"editing":return null!=t?this._analysisViewData.path.getVertexPositionAsPoint(t):null;default:return this._analysisViewData.stagedPoint}}_updateLaserLine(){const t="measured"!==this._toolState.polygonState&&this._toolState.active,e=this._getFocusPoint();if(t&&null!=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([r(()=>this._toolState.polygonState,()=>this._updateLaserLine()),r(()=>this._analysisViewData.viewData,()=>this._updateAll(),o),r(()=>({lastDraggedVertex:this._analysisViewData.lastDraggedVertex,cursorPoint:this._analysisViewData.stagedPoint}),()=>this._updateLaserLine()),r(()=>this._toolState.active,()=>this._updateAll()),r(()=>this._view.effectiveTheme.accentColor,e=>{const s=t(e,.5);this._manipulatorMaterial.setParameters({color:s});const a=e.toUnitRGB(),r=i(e).toUnitRGB(),o=.75*e.a,n=this._laserLine,l=n.style;n.style={...l,glowColor:a,innerColor:r,globalAlpha:o}},{initial:!0,equals:e})])}_destroyListeners(){this._listenerHandles=a(this._listenerHandles)}}function y(t,e,i,s){for(;t.length<e;)t.push(i());if(s)for(;t.length>e;){s(t.pop())}else t.length=e}const f=8,V=8,b=1,D=5;export{g as default};