/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{dedupeResult as r}from"../../../core/dedupeResult.js";import{equalsShallow as t}from"../../../core/lang.js";import{watch as o}from"../../../core/reactiveUtils.js";import{getMetersPerVerticalUnitForSR as n}from"../../../core/units.js";import{property as i,subclass as s}from"../../../core/accessorSupport/decorators.js";import{ElevationProfileLineComputation as a}from"./ElevationProfileLineComputation.js";import{getGroundMinDemResolution as l}from"./elevationProfileQuerySourceUtils.js";let u=class extends a{constructor(){super(...arguments),this.type="ground",this.numSamplesForPreview=50,this.numSamplesPerChunk=1e3,this._getStableQueryElevationDependencies=r(()=>({ground:this._ground,groundLayers:this._getStableGroundLayers()}),t),this._getStableGroundLayers=r(()=>this._ground?.layers?.toArray(),t)}get minDemResolution(){return l(this._ground)}get available(){return!0===this._ground?.layers.some(e=>e.visible)||!0===this._groundLayers?.some(e=>e.visible)}initialize(){this.addHandles([o(()=>this._queryElevationDependencies,()=>this.onInvalidate(this)),o(()=>this._ground,e=>{e&&!e.loaded&&e.load()},{initial:!0})])}async queryElevation(e,r){const t=this._queryElevationDependencies;if(null==t)throw new Error(`${this.declaredClass}: no dependencies`);const{ground:o}=t;if(null==o)throw new Error("No ground configured in the view");const i=await o.queryElevation(e,r),s=n(e.spatialReference),a=n(o.allLayers.at(0).spatialReference);if(s!==a){const e=i.geometry;e.points=e.points.map(([e,t,o])=>[e,t,o===r.noDataValue?o:o*a/s])}return i}get _queryElevationDependencies(){return this._getStableQueryElevationDependencies()}get _ground(){return this.controller.view?.map?.ground}get _groundLayers(){return this.controller.view?.map?.basemap?.groundLayers}};e([i()],u.prototype,"minDemResolution",null),e([i()],u.prototype,"available",null),e([i()],u.prototype,"_queryElevationDependencies",null),e([i()],u.prototype,"_ground",null),e([i()],u.prototype,"_groundLayers",null),u=e([s("esri.views.analysis.ElevationProfile.ElevationProfileLineGroundComputation")],u);export{u as ElevationProfileLineGroundComputation};
