@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.57 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import s from"../../../core/Evented.js";import{destroyMaybe as r}from"../../../core/maybe.js";import{throwIfAbortError as n}from"../../../core/promiseUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";import a from"../../../geometry/SpatialReference.js";import{equals as l}from"../../../geometry/support/spatialReferenceUtils.js";import{ElevationQuery as c}from"../layers/graphics/ElevationQuery.js";import{ElevationRange as u}from"./ElevationRange.js";let h=class extends(s.EventedMixin(t)){get spatialReference(){return this.view?.basemapTerrain?.spatialReference}constructor(e){super(e),this._im=new Array,this._ground=new Array,this._scene=new Array,this.lastElevationQuery=null,this._cacheEnabled=!1}destroy(){this._cachedQuery=r(this._cachedQuery)}enableCache(e){e||(this.lastElevationQuery=null),this._cacheEnabled=e}getElevation(e,t,s,r,n){if(this._cacheEnabled&&null!=this.lastElevationQuery){const o=this.lastElevationQuery;if(e===o.x&&t===o.y&&s===o.z&&l(r,o.spatialReference)&&n===o.queryContext)return o.result}let o=null;return o=p(o,this._im,e,t,s,r,n),null==o&&(o=p(o,this._ground,e,t,s,r,n)),"scene"===n&&(o=p(o,this._scene,e,t,s,r,n)),this._cacheEnabled&&(this.lastElevationQuery={x:e,y:t,z:s,spatialReference:r,queryContext:n,result:o}),o}getSphereElevationBounds(e,t,s){const r=new u;function n(n){for(const o of n)if(o.getSphereElevationBounds){const n=o.getSphereElevationBounds(e,t,s);null!=n&&r.expandElevationRangeValues(n.elevationRangeMin,n.elevationRangeMax)}}return n(this._ground),n(this._im),"scene"===s&&n(this._scene),r}getRootElevationBounds(){const e=new u;for(const t of[this._im,this._ground,this._scene])t.forEach((t=>{if(t.getRootElevationBounds){const s=t.getRootElevationBounds();null!=s&&e.expandElevationRangeValues(s.elevationRangeMin,s.elevationRangeMax)}}));return e}async queryElevation(e,t,s,r,o,i=null,a=0){const l=this._getElevationQuery(r);try{const n=await l.queryElevation(e,t,i,a);return"scene"===o?p(n,this._scene,e,t,s,r,o):n}catch(c){return n(c),this.getElevation(e,t,s,r,o)}}register(e,t){this.addHandles(t.on("elevation-change",(e=>this.emit("elevation-change",e))),t),this._providersFromContext(e).push(t)}unregister(e){this.removeHandles(e);for(const t of[this._im,this._ground,this._scene]){const s=t.indexOf(e);s>-1&&t.splice(s,1)}}_providersFromContext(e){switch(e){case"ground":return this._ground;case"im":return this._im;case"scene":return this._scene}}_getElevationQuery(e=this.view.spatialReference){const t=this._cachedQuery;if(null!=t&&l(e,t.spatialReference))return t;t?.destroy({completeTasks:!0});const{wkid:s,wkt:r,wkt2:n,latestWkid:o}=e,i=new c(this.view.resourceController.scheduler,new a({wkid:s,wkt:r,wkt2:n,latestWkid:o}),(()=>this.view.map?.ground),{maximumAutoTileRequests:4});return this._cachedQuery=i,i}};function p(e,t,s,r,n,o,i){for(const a of t){const t=a.getElevation(s,r,n,o,i);null!=t&&(e=null!=e?Math.max(t,e):t)}return e}e([o({constructOnly:!0})],h.prototype,"view",void 0),e([o()],h.prototype,"spatialReference",null),h=e([i("esri.views.3d.support.CombinedElevationProvider")],h);export{h as CombinedElevationProvider};