UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.84 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import r from"../../../core/Evented.js";import{destroyMaybe as s,isNone as i,isSome as o}from"../../../core/maybe.js";import{createResolver as n,isAbortError as a}from"../../../core/promiseUtils.js";import{property as l}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{equals as h}from"../../../geometry/support/spatialReferenceUtils.js";import{ElevationQuery as u}from"../layers/graphics/ElevationQuery.js";let p=class extends(r.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._handles=new Map,this.lastElevationQuery=null,this.elevationCacheEnabled=!1}destroy(){this._elevationQueryCached=s(this._elevationQueryCached)}get _elevationQuery(){return i(this._elevationQueryCached)&&(this._elevationQueryCached=new u(this.view.resourceController.scheduler,this.view.spatialReference,(()=>this.view.map&&this.view.map.ground),{maximumAutoTileRequests:4})),this._elevationQueryCached}enableElevationCache(e){e||(this.lastElevationQuery=null),this.elevationCacheEnabled=e}getElevation(e,t,r,s,o){if(this.elevationCacheEnabled&&null!=this.lastElevationQuery){const i=this.lastElevationQuery;if(e===i.x&&t===i.y&&r===i.z&&h(s,i.spatialReference)&&o===i.queryContext)return i.result}let n=null;return n=v(n,this._im,e,t,r,s,o),i(n)&&(n=v(n,this._ground,e,t,r,s,o)),"scene"===o&&(n=v(n,this._scene,e,t,r,s,o)),this.elevationCacheEnabled&&(this.lastElevationQuery={x:e,y:t,z:r,spatialReference:s,queryContext:o,result:n}),n}queryElevation(e,t,r,s,i,o=null,l=0){const c=n();return this._elevationQuery.queryElevation(e,t,o,l).then((o=>{"scene"===i&&(o=v(o,this._scene,e,t,r,s,i)),c.resolve(o)})).catch((o=>{a(o)?c.reject(o):c.resolve(this.getElevation(e,t,r,s,i))})),c.promise}register(e,t){this._handles.set(t,t.on("elevation-change",(e=>this.emit("elevation-change",e)))),this._providersFromContext(e).push(t)}unregister(e){this._handles.has(e)&&(this._handles.get(e)?.remove(),this._handles.delete(e));for(const t of[this._im,this._ground,this._scene]){const r=t.indexOf(e);r>-1&&t.splice(r,1)}}_providersFromContext(e){switch(e){case"ground":return this._ground;case"im":return this._im;case"scene":return this._scene}}};function v(e,t,r,s,i,n,a){for(const l of t){const t=l.getElevation(r,s,i,n,a);o(t)&&(e=o(e)?Math.max(t,e):t)}return e}e([l({constructOnly:!0})],p.prototype,"view",void 0),e([l()],p.prototype,"spatialReference",null),p=e([c("esri.views.3d.support.CombinedElevationProvider")],p);export{p as CombinedElevationProvider};