/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Logger.js";import{getMetersPerUnitForSR as o}from"../../core/units.js";import{property as n,subclass as i}from"../../core/accessorSupport/decorators.js";import s from"../../geometry/SpatialReference.js";import{toExtent as l,create as a,containsXY as r}from"../../geometry/support/aaBoundingRect.js";import m from"./ElevationSampler.js";let p=class extends m{get spatialReference(){return this.extent.spatialReference}constructor(e){const t=e.noDataValue,o="tiles"in e?e.tiles.map(o=>new u({tile:o,tileInfo:e.tileInfo,noDataValue:t})):e.samplers;super({noDataValue:t,samplers:o});const n=o[0];if(n){this.extent=n.extent.clone();const{min:e,max:t}=n.demResolution;this.demResolution={min:e,max:t};for(let n=1;n<o.length;n++){const e=o[n];this.extent.union(e.extent),this.demResolution.min=Math.min(this.demResolution.min,e.demResolution.min),this.demResolution.max=Math.max(this.demResolution.max,e.demResolution.max)}}else{const t="tileInfo"in e?e.tileInfo:null;this.extent=l(a(),t?.spatialReference??s.WGS84),this.demResolution={min:0,max:0}}}elevationAt(e,o){let n;for(const t of this.samplers)if(t.containsAt(e,o)&&(n=t.elevationAt(e,o),n!==t.noDataValue))return n;return null!=n?n:(t.getLogger(this).warn("#elevationAt()",`Point used to sample elevation (${e}, ${o}) is outside of the sampler`),this.noDataValue)}};e([n({constructOnly:!0})],p.prototype,"noDataValue",void 0),e([n({constructOnly:!0})],p.prototype,"samplers",void 0),p=e([i("esri.layers.support.TileElevationSampler")],p);let u=class extends m{get spatialReference(){return this.extent.spatialReference}constructor(e){super(e);const t=e.tile.key.extent;this.extent=l(t,e.tileInfo.spatialReference),this.extent.zmin=e.tile.zmin,this.extent.zmax=e.tile.zmax;const n=o(e.tileInfo.spatialReference),i=e.tileInfo.lodAt(e.tile.key.level).resolution*n;this.demResolution={min:i,max:i}}contains(e){const t=this.projectIfRequired(e,this.spatialReference);return null!=t&&this.containsAt(t.x,t.y)}containsAt(e,t){return r(this.tile.key.extent,e,t)}elevationAt(e,t){return this.containsAt(e,t)?this.tile.sample(e,t)??this.noDataValue:this.noDataValue}};e([n({constructOnly:!0})],u.prototype,"tile",void 0),e([n({constructOnly:!0})],u.prototype,"noDataValue",void 0),e([n({constructOnly:!0})],u.prototype,"tileInfo",void 0),u=e([i("esri.layers.support.TileElevationSampler.SingleTileElevationSampler")],u);export{p as TileElevationSampler};
