UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 7.12 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../../../chunks/tslib.es6.js";import i from"../../../../../Color.js";import t from"../../../../../core/Accessor.js";import{multiplyOpacityToUnitRGBA as s,getContrast as o,colorVectorEquals as n,colorVectorToColorAndOpacity as a}from"../../../../../core/colorUtils.js";import"../../../../../core/has.js";import{destroyMaybe as r}from"../../../../../core/maybe.js";import{watch as l,initial as d}from"../../../../../core/reactiveUtils.js";import{property as h}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as c}from"../../../../../core/accessorSupport/decorators/subclass.js";import{create as p}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromPoints as u}from"../../../../../geometry/support/lineSegment.js";import{MeasurementMode as m}from"../../../analysis/interfaces.js";import{ViewMode as g}from"../../../analysis/DirectLineMeasurement/interfaces.js";import{Manipulator3D as _}from"../../Manipulator3D.js";import{createManipulatorMaterial as y}from"../../manipulatorUtils.js";import{RenderObject as v}from"../../RenderObject.js";import{LaserlineVisualElement as w}from"../../visualElements/LaserlineVisualElement.js";import{createSphereGeometry as b}from"../../../webgl-engine/lib/GeometryUtil.js";var L;!function(e){e.Manipulators="manipulators",e.AnalysisViewDestroyed="analysis-view-destroyed",e.AnalysisView="analysis-view"}(L||(L={}));let P=class extends t{constructor(e){super(e),this.cursorPoint=null,this._visible=!1,this._laserLine=null,this.laserLineEnabled=!0,this._lastDraggedHandle=null}initialize(){this._laserLine=new w({view:this.view,attached:!0,isDecoration:!0}),this._updateVisibility(this._visible),this._connectToAnalysisView(),this.addHandles(l((()=>this._params),(({laserLineGlowColor:e,laserLineInnerColor:i,laserLineGlobalAlpha:t})=>{const s=this._laserLine,o=s.style;s.style={...o,innerColor:i,glowColor:e,globalAlpha:t}})))}destroy(){this._laserLine=r(this._laserLine)}get _params(){const{accentColor:e}=this.view.effectiveTheme;return{laserLineGlowColor:i.toUnitRGB(e),laserLineGlowWidth:8,laserLineGlowFalloff:8,laserLineInnerColor:i.toUnitRGB(o(e)),laserLineInnerWidth:.75,laserLineGlobalAlpha:.75*e.a,handleColor:s(e,.5),handleRadius:5}}get visible(){return this._visible}set visible(e){e?this.show():this.hide()}get testData(){}get _cursorPosition(){const e=p(),i=this.cursorPoint;return i&&this.view.renderCoordsHelper.toRenderCoords(i,e),e}get _startPosition(){const e=p(),i=this.analysis.startPoint;return i&&this.view.renderCoordsHelper.toRenderCoords(i,e),e}get _endPosition(){const e=p(),i=this.analysis.endPoint;return i&&this.view.renderCoordsHelper.toRenderCoords(i,e),e}get _laserLineParams(){const e=this._focusPosition,{active:i,lineState:t}=this.toolState,s=this.analysisViewData,o=this.laserLineEnabled&&!!e&&"measured"!==t&&i;if(!o||!this.visible||null==s||s.destroyed)return{heightManifoldTarget:null,pointDistanceLine:null,lineVerticalPlaneSegment:null};const n=s.actualVisualizedMeasurement,a="local"!==this.view.viewingMode&&o&&!!this.analysis.startPoint&&"geodesic"===n,r=o&&s.viewMode===g.Triangle;return{heightManifoldTarget:"euclidean"===n?e:null,pointDistanceLine:a?this._pointDistanceLine:null,lineVerticalPlaneSegment:r?u(this._startPosition,this._endPosition):null}}get _focusPosition(){const{lineState:e}=this.toolState,i=this.analysisViewData,t=null!=i&&!i.destroyed&&i.measurementMode===m.Euclidean&&i.viewMode===g.Direct;switch(e){case"drawing":return t?this._startPosition:this.analysis.endPoint?this._endPosition:this._startPosition;case"editing":return t?"start"===this._lastDraggedHandle?this._endPosition:this._startPosition:"start"===this._lastDraggedHandle?this._startPosition:this._endPosition;default:return null!=this.cursorPoint?this._cursorPosition:null}}get _pointDistanceLine(){return{origin:"drawing"===this.toolState.lineState||"end"===this._lastDraggedHandle?this._startPosition:this._endPosition,target:this._focusPosition}}createManipulators(){const e=this._params,{view:i}=this,t=()=>{const t=y(e.handleColor),s=[new v(b(t,1,32,32))],o=new _({view:i,renderObjects:s});return o.available=!1,o.radius=e.handleRadius,[o,t]},[s,o]=t(),[r,d]=t(),h=new _({view:this.view,available:!1,interactive:!1});null!=this.analysis.startPoint&&(s.location=this.analysis.startPoint,s.available=!0),null!=this.analysis.endPoint&&(r.location=this.analysis.endPoint,r.available=!0);const c=()=>{let e=this._lastDraggedHandle;s.grabbing&&!r.grabbing&&(e="start"),r.grabbing&&!s.grabbing&&(e="end"),s.grabbing||r.grabbing||(e=null),this._lastDraggedHandle=e},p=s.events.on("grab-changed",c),u=r.events.on("grab-changed",c);return this.addHandles([p,u,l((()=>a(this._params.handleColor)),(e=>{o.setParameters({color:e}),d.setParameters({color:e})}),{equals:n})],L.Manipulators),{start:s,end:r,cursor:h}}show(){this.destroyed||this._visible||this._updateVisibility(!0)}hide(){!this.destroyed&&this._visible&&this._updateVisibility(!1)}_connectToAnalysisView(){this.removeHandles(L.AnalysisView),this.addHandles([l((()=>this.analysisViewData?.destroyed),(e=>{e&&this.removeHandles(L.AnalysisView)}),d),l((()=>["measured"===this.toolState.lineState,this.analysisViewData]),(([e,i])=>{null==i||i.destroyed||(i.allowVisualElementsOrientationChange=!e)}),d),l((()=>this._laserLineParams),(e=>{const i=this._laserLine;i.heightManifoldTarget=e.heightManifoldTarget,i.pointDistanceLine=e.pointDistanceLine,i.lineVerticalPlaneSegment=e.lineVerticalPlaneSegment}),d)],L.AnalysisView)}_updateVisibility(e){this.initialized&&(this._visible=e,e?this._laserLine.style={innerColor:this._params.laserLineInnerColor,innerWidth:this._params.laserLineInnerWidth,glowColor:this._params.laserLineGlowColor,glowWidth:this._params.laserLineGlowWidth,glowFalloff:this._params.laserLineGlowFalloff,globalAlpha:this._params.laserLineGlobalAlpha}:this.view.cursor=null,this._laserLine.visible=e)}};e([h({constructOnly:!0})],P.prototype,"view",void 0),e([h()],P.prototype,"_params",null),e([h({constructOnly:!0})],P.prototype,"analysis",void 0),e([h({constructOnly:!0})],P.prototype,"analysisViewData",void 0),e([h()],P.prototype,"cursorPoint",void 0),e([h()],P.prototype,"toolState",void 0),e([h()],P.prototype,"visible",null),e([h()],P.prototype,"testData",null),e([h()],P.prototype,"_visible",void 0),e([h()],P.prototype,"_laserLine",void 0),e([h({constructOnly:!0})],P.prototype,"laserLineEnabled",void 0),e([h()],P.prototype,"_cursorPosition",null),e([h()],P.prototype,"_startPosition",null),e([h()],P.prototype,"_endPosition",null),e([h()],P.prototype,"_lastDraggedHandle",void 0),e([h()],P.prototype,"_laserLineParams",null),e([h()],P.prototype,"_focusPosition",null),e([h()],P.prototype,"_pointDistanceLine",null),P=e([c("esri.views.3d.interactive.measurementTools.directLineMeasurement3D.DirectLineMeasurement3DView")],P);export{P as DirectLineMeasurement3DView};