@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.46 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../../../core/Accessor.js";import{multiplyOpacityToUnitRGBA as i,getContrast as s,colorVectorEquals as o,colorVectorToColorAndOpacity as n}from"../../../../../core/colorUtils.js";import"../../../../../core/has.js";import{destroyMaybe as a}from"../../../../../core/maybe.js";import{watch as r,initial as l}from"../../../../../core/reactiveUtils.js";import{property as h,subclass as d}from"../../../../../core/accessorSupport/decorators.js";import{create as c}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromPoints as p}from"../../../../../geometry/support/lineSegment.js";import{Manipulator3D as u}from"../../Manipulator3D.js";import{createManipulatorMaterial as g}from"../../manipulatorUtils.js";import{RenderObject as m}from"../../RenderObject.js";import{LaserlineVisualElement as _}from"../../visualElements/LaserlineVisualElement.js";import{createSphereGeometry as y}from"../../../webgl-engine/lib/GeometryUtil.js";let v=class extends e{constructor(t){super(t),this.cursorPoint=null,this._visible=!1,this._laserLine=null,this.laserLineEnabled=!0,this._lastDraggedHandle=null}initialize(){this._laserLine=new _({view:this.view,attached:!0,isDecoration:!0}),this._updateVisibility(this._visible),this._connectToAnalysisView(),this.addHandles(r(()=>this._params,({laserLineGlowColor:t,laserLineInnerColor:e,laserLineGlobalAlpha:i})=>{const s=this._laserLine,o=s.style;s.style={...o,innerColor:e,glowColor:t,globalAlpha:i}}))}destroy(){this._laserLine=a(this._laserLine)}get _params(){const{accentColor:t}=this.view.effectiveTheme;return{laserLineGlowColor:t.toUnitRGB(),laserLineGlowWidth:8,laserLineGlowFalloff:8,laserLineInnerColor:s(t).toUnitRGB(),laserLineInnerWidth:.75,laserLineGlobalAlpha:.75*t.a,handleColor:i(t,.5),handleRadius:5}}get visible(){return this._visible}set visible(t){t?this.show():this.hide()}get testData(){}get _cursorPosition(){const t=c(),e=this.cursorPoint;return e&&this.view.renderCoordsHelper.toRenderCoords(e,t),t}get _startPosition(){const t=c(),e=this.analysis.startPoint;return e&&this.view.renderCoordsHelper.toRenderCoords(e,t),t}get _endPosition(){const t=c(),e=this.analysis.endPoint;return e&&this.view.renderCoordsHelper.toRenderCoords(e,t),t}get _laserLineParams(){const t=this._focusPosition,{active:e,lineState:i}=this.toolState,s=this.analysisViewData,o=this.laserLineEnabled&&!!t&&"measured"!==i&&e;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&&2===s.viewMode;return{heightManifoldTarget:"euclidean"===n?t:null,pointDistanceLine:a?this._pointDistanceLine:null,lineVerticalPlaneSegment:r?p(this._startPosition,this._endPosition):null}}get _focusPosition(){const{lineState:t}=this.toolState,e=this.analysisViewData,i=null!=e&&!e.destroyed&&1===e.measurementMode&&1===e.viewMode;switch(t){case"drawing":return i?this._startPosition:this.analysis.endPoint?this._endPosition:this._startPosition;case"editing":return i?"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 t=this._params,{view:e}=this,i=()=>{const i=g(t.handleColor),s=[new m(y(i,1,32,32))],o=new u({view:e,renderObjects:s});return o.available=!1,o.radius=t.handleRadius,[o,i]},[s,a]=i(),[l,h]=i(),d=new u({view:this.view,available:!1,interactive:!1});null!=this.analysis.startPoint&&(s.location=this.analysis.startPoint,s.available=!0),null!=this.analysis.endPoint&&(l.location=this.analysis.endPoint,l.available=!0);const c=()=>{let t=this._lastDraggedHandle;s.grabbing&&!l.grabbing&&(t="start"),l.grabbing&&!s.grabbing&&(t="end"),s.grabbing||l.grabbing||(t=null),this._lastDraggedHandle=t},p=s.events.on("grab-changed",c),_=l.events.on("grab-changed",c);return this.addHandles([p,_,r(()=>n(this._params.handleColor),t=>{a.setParameters({color:t}),h.setParameters({color:t})},{equals:o})],"manipulators"),{start:s,end:l,cursor:d}}show(){this.destroyed||this._visible||this._updateVisibility(!0)}hide(){!this.destroyed&&this._visible&&this._updateVisibility(!1)}_connectToAnalysisView(){this.removeHandles("analysis-view"),this.addHandles([r(()=>this.analysisViewData?.destroyed,t=>{t&&this.removeHandles("analysis-view")},l),r(()=>["measured"===this.toolState.lineState,this.analysisViewData],([t,e])=>{null==e||e.destroyed||(e.allowVisualElementsOrientationChange=!t)},l),r(()=>this._laserLineParams,t=>{const e=this._laserLine;e.heightManifoldTarget=t.heightManifoldTarget,e.pointDistanceLine=t.pointDistanceLine,e.lineVerticalPlaneSegment=t.lineVerticalPlaneSegment},l)],"analysis-view")}_updateVisibility(t){this.initialized&&(this._visible=t,t&&(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._laserLine.visible=t)}};t([h({constructOnly:!0})],v.prototype,"view",void 0),t([h()],v.prototype,"_params",null),t([h({constructOnly:!0})],v.prototype,"analysis",void 0),t([h({constructOnly:!0})],v.prototype,"analysisViewData",void 0),t([h()],v.prototype,"cursorPoint",void 0),t([h()],v.prototype,"toolState",void 0),t([h()],v.prototype,"visible",null),t([h()],v.prototype,"testData",null),t([h()],v.prototype,"_visible",void 0),t([h()],v.prototype,"_laserLine",void 0),t([h({constructOnly:!0})],v.prototype,"laserLineEnabled",void 0),t([h()],v.prototype,"_cursorPosition",null),t([h()],v.prototype,"_startPosition",null),t([h()],v.prototype,"_endPosition",null),t([h()],v.prototype,"_lastDraggedHandle",void 0),t([h()],v.prototype,"_laserLineParams",null),t([h()],v.prototype,"_focusPosition",null),t([h()],v.prototype,"_pointDistanceLine",null),v=t([d("esri.views.3d.interactive.measurementTools.directLineMeasurement3D.DirectLineMeasurement3DView")],v);export{v as DirectLineMeasurement3DView};