/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Accessor","../../../core/Evented","../../../core/maybe","../../../core/promiseUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../layers/graphics/ElevationQuery"],(function(e,t,r,i,o,n,s,a,l,c,u,v,h){"use strict";function d(e,t,r,i,o,s,a){for(const l of t){const t=l.getElevation(r,i,o,s,a);n.isSome(t)&&(e=n.isSome(e)?Math.max(t,e):t)}return e}e.CombinedElevationProvider=function(e){function r(t){var r;return(r=e.call(this,t)||this).im=new Array,r.ground=new Array,r.scene=new Array,r.handles=new Map,r.lastElevationQuery=null,r.elevationCacheEnabled=!1,r}t._inheritsLoose(r,e);var i=r.prototype;return i.destroy=function(){this._elevationQuery=n.destroyMaybe(this._elevationQuery)},i.enableElevationCache=function(e){e||(this.lastElevationQuery=null),this.elevationCacheEnabled=e},i.getElevation=function(e,t,r,i,o){if(this.elevationCacheEnabled&&null!=this.lastElevationQuery){const n=this.lastElevationQuery;if(e===n.x&&t===n.y&&r===n.z&&i.equals(n.spatialReference)&&o===n.queryContext)return n.result}let s=null;return s=d(s,this.im,e,t,r,i,o),n.isNone(s)&&(s=d(s,this.ground,e,t,r,i,o)),"scene"===o&&(s=d(s,this.scene,e,t,r,i,o)),this.elevationCacheEnabled&&(this.lastElevationQuery={x:e,y:t,z:r,spatialReference:i,queryContext:o,result:s}),s},i.queryElevation=function(e,t,r,i,o,n=null,a=0){const l=s.createResolver();return this.elevationQuery.queryElevation(e,t,n,a).then((n=>{"scene"===o&&(n=d(n,this.scene,e,t,r,i,o)),l.resolve(n)})).catch((n=>{s.isAbortError(n)?l.reject(n):l.resolve(this.getElevation(e,t,r,i,o))})),l.promise},i.register=function(e,t){this.handles.set(t,t.on("elevation-change",(e=>this.emit("elevation-change",e)))),this[e].push(t)},i.unregister=function(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)}},t._createClass(r,[{key:"elevationQuery",get:function(){return n.isNone(this._elevationQuery)&&(this._elevationQuery=new h.ElevationQuery(this.view.resourceController.scheduler,this.view.spatialReference,(()=>this.view.map&&this.view.map.ground),{maximumAutoTileRequests:4})),this._elevationQuery}}]),r}(o.EventedMixin(i)),r.__decorate([a.property({constructOnly:!0})],e.CombinedElevationProvider.prototype,"view",void 0),r.__decorate([a.property({readOnly:!0,aliasOf:"view.basemapTerrain.spatialReference"})],e.CombinedElevationProvider.prototype,"spatialReference",void 0),e.CombinedElevationProvider=r.__decorate([v.subclass("esri.views.3d.support.CombinedElevationProvider")],e.CombinedElevationProvider),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
