@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.18 kB
JavaScript
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Handles.js";import s from"../../../../core/Logger.js";import{destroyMaybe as o,isNone as r,isSome as n}from"../../../../core/maybe.js";import{createQuantity as a}from"../../../../core/quantityUtils.js";import{watch as c,syncAndInitial as l}from"../../../../core/reactiveUtils.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{i as d}from"../../../../chunks/vec3.js";import{c as h}from"../../../../chunks/vec3f64.js";import{geodesicLength as u}from"../../../../geometry/geometryEngine.js";import v from"../../../../geometry/Polyline.js";import{canProjectWithoutEngine as f,projectPointToVector as _,projectPointToWGS84ComparableLonLat as g}from"../../../../geometry/projection.js";import{getSphericalPCPF as j,SphericalECEFSpatialReference as P,WGS84ECEFSpatialReference as y}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{isSupported as D,geodesicLengths as w,InverseGeodeticSolverResult as z,inverseGeodeticSolver as A}from"../../../../geometry/support/geodesicUtils.js";import{MeasurementMode as R}from"../interfaces.js";import{applyProjectionAndElevationAlignment as E,logFailedGeometryProjectionError as b}from"../support/projectionUtils.js";import{UnitNormalizer as S}from"../support/UnitNormalizer.js";const U="esri.views.3d.analysis.DirectLineMeasurement.DirectLineMeasurementController",k=s.getLogger(U),C=1e5;let M=class extends t{constructor(e){super(e),this._unitNormalizer=new S,this._handles=new i,this._tempStartPosition=h(),this._tempEndPosition=h(),this._tempCornerPosition=h()}initialize(){const e=this.view.spatialReference,t=j(e),i=t===P?y:t;this._sphericalPCPF=i;const s=f(e,i);this._unitNormalizer.spatialReference=s?i:e,this._handles.add([c((()=>({viewData:this.viewData,startPoint:this.analysis.startPoint})),(({viewData:e,startPoint:t})=>{e.elevationAlignedStartPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({viewData:this.viewData,endPoint:this.analysis.endPoint})),(({viewData:e,endPoint:t})=>{e.elevationAlignedEndPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({result:this._computedResult,viewData:this.viewData})),(({result:e,viewData:t})=>{t.result=e}),l)])}destroy(){this._handles=o(this._handles)}_applyProjectionAndElevationAlignment(e){if(r(e))return e;const{spatialReference:t,elevationProvider:i}=this.view,s=E(e,t,i);return r(s)?(b(this.analysis,e.spatialReference,k),null):s}get _computedResult(){const{elevationAlignedStartPoint:e,elevationAlignedEndPoint:t,measurementMode:i}=this.viewData;if(r(e)||r(t))return null;const s=this._euclideanDistances(e,t),o=this._geodesicDistance(e,t,s.horizontal.value),n=i===R.Geodesic||i===R.Auto&&s.horizontal.value>C?"geodesic":"euclidean";return{mode:n,distance:"euclidean"===n?s.direct:o,directDistance:s.direct,horizontalDistance:s.horizontal,verticalDistance:s.vertical,geodesicDistance:o}}_euclideanDistances(e,t){const i=e.clone();i.z=t.z;const s=this._tempStartPosition,o=this._tempEndPosition,r=this._tempCornerPosition,n=this.view.spatialReference,c=this._sphericalPCPF,l=f(n,c)?c:n;_(e,s,l),_(t,o,l),_(i,r,l);const m=d(s,o),p=d(r,o),h=Math.abs(t.z-e.z),u=e=>this._unitNormalizer.normalizeDistance(e),v=u(m),g=u(p),j=u(h);return{direct:a(v,"meters"),horizontal:a(g,"meters"),vertical:a(j,"meters")}}_geodesicDistance(e,t,i){const s=e.spatialReference,o=new v({spatialReference:s});o.addPath([e,t]);const r=s.isGeographic&&D(s)?w([o],"meters")[0]:s.isWebMercator?u(o,"meters"):null,c=n(r)?r:this._fallbackGeodesicDistance(e,t,i);return a(c,"meters")}_fallbackGeodesicDistance(e,t,i){if(g(e,G)&&g(t,L)){const e=new z;return A(e,G,L),e.distance}return i}};e([m()],M.prototype,"view",void 0),e([m()],M.prototype,"analysis",void 0),e([m()],M.prototype,"viewData",void 0),e([m()],M.prototype,"_computedResult",null),M=e([p(U)],M);const G=h(),L=h();export{M as DirectLineMeasurementController};