UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4 kB
import{_ as t}from"../../../../chunks/tslib.es6.js";import{clamp as e}from"../../../../core/mathUtils.js";import{removeMaybe as r,destroyMaybe as s,isSome as i}from"../../../../core/maybe.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as a}from"../../../../core/accessorSupport/decorators/subclass.js";import{c,i as n,g as u,a as l,k as d,p}from"../../../../chunks/vec3.js";import{c as h}from"../../../../chunks/vec3f64.js";import{getReferenceEllipsoid as f}from"../../../../geometry/ellipsoidUtils.js";import m from"../../../../geometry/Point.js";import{projectBoundingRect as _}from"../../../../geometry/projection.js";import{create as S}from"../../../../geometry/support/aaBoundingRect.js";import y from"../debugFlags.js";import{PropertiesPool as g}from"../PropertiesPool.js";import{PointOfInterest as A}from"./PointOfInterest.js";import{Task as j}from"../../../support/Scheduler.js";const L=Array;let k=class extends A{constructor(t){super(t),this._propertiesPool=new g({location:m,renderLocation:L},this),this._currentSurfaceAltitude=0,this._latestSurfaceAltitude=0,this.distance=0,this.renderLocation=h(),this.updating=!1}initialize(){this._frameWorker=this.scheduler.registerTask(this.task,this),this.runTask()}destroy(){this._frameWorker=r(this._frameWorker),this._propertiesPool=s(this._propertiesPool)}get _camera(){return this.state.contentCamera}get location(){const t=this._propertiesPool.get("location");return this.renderCoordsHelper.fromRenderCoords(this.renderLocation,t,this.state.spatialReference),t}updateRenderLocation(){this.updating=!0,this._updateRenderLocation()}get estimatedSurfaceAltitude(){return this._latestSurfaceAltitude}get running(){return this.updating}runTask(){return this._latestSurfaceAltitude=this.estimateSurfaceAltitudeAtCenter(),this._updateRenderLocation(),this.updating=!1,j.YIELD}_updateRenderLocation(){const t=C;let e=this._calculateSurfaceIntersection(this._currentSurfaceAltitude,t);const r=this._currentSurfaceAltitude!==this._latestSurfaceAltitude;!e&&r&&(e=this._calculateSurfaceIntersection(this._latestSurfaceAltitude,t),e&&(this._currentSurfaceAltitude=this._latestSurfaceAltitude));const s=I;e&&this._latestSurfaceAltitudeChangesDistanceSignificantly(t,s)&&(c(t,s),this._currentSurfaceAltitude=this._latestSurfaceAltitude),e?this.distance=n(this._camera.eye,t):(u(t,this._camera.viewForward,this._get("distance")),l(t,t,this._camera.eye)),d(this._get("renderLocation"),t)||this._set("renderLocation",c(this._propertiesPool.get("renderLocation"),t))}_calculateSurfaceIntersection(t,r){const s=this._camera;if(!this.renderCoordsHelper.intersectManifold(s.ray,t,r))return!1;if(this.state.isGlobal){const e=f(this.renderCoordsHelper.spatialReference).radius,i=e+t,o=p(s.eye),a=o<i*i,c=n(s.eye,r);if(a&&c>e/4){const t=i-Math.sqrt(o);return u(r,s.viewForward,t),l(r,r,s.eye),!0}}else{const t=this.surface?.ready?this.surface.extent:null;i(t)&&_(t,this.surface?.spatialReference,P,this.renderCoordsHelper.spatialReference)&&(r[0]=e(r[0],P[0],P[2]),r[1]=e(r[1],P[1],P[3]))}return!0}_latestSurfaceAltitudeChangesDistanceSignificantly(t,e){if(this._latestSurfaceAltitude===this._currentSurfaceAltitude||null==t)return!1;if(this._calculateSurfaceIntersection(this._latestSurfaceAltitude,e)){if(y.TESTS_DISABLE_OPTIMIZATIONS)return!0;const r=this._camera.eye,s=n(r,t),i=n(r,e);if(Math.abs(i-s)/s>v)return!0}return!1}};t([o({constructOnly:!0})],k.prototype,"scheduler",void 0),t([o({constructOnly:!0})],k.prototype,"task",void 0),t([o()],k.prototype,"distance",void 0),t([o({constructOnly:!0})],k.prototype,"estimateSurfaceAltitudeAtCenter",void 0),t([o({readOnly:!0})],k.prototype,"location",null),t([o({readOnly:!0})],k.prototype,"renderLocation",void 0),t([o()],k.prototype,"updating",void 0),k=t([a("esri.views.3d.support.CenterOnSurface")],k);const v=.05,C=h(),I=h(),P=S();export{k as CenterOnSurface};