/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{dedupeResult as t}from"../../../core/dedupeResult.js";import{equalsShallow as r}from"../../../core/lang.js";import{watch as o}from"../../../core/reactiveUtils.js";import{getMetersPerVerticalUnitForSR as i}from"../../../core/units.js";import{property as n,subclass as s}from"../../../core/accessorSupport/decorators.js";import{ElevationProfileLineComputation as l}from"./ElevationProfileLineComputation.js";import{getGroundMinDemResolution as a}from"./elevationProfileQuerySourceUtils.js";let u=class extends l{constructor(){super(...arguments),this.type="ground",this.numSamplesForPreview=50,this.numSamplesPerChunk=1e3,this._getStableQueryElevationDependencies=t(()=>({ground:this._ground,groundLayers:this._getStableGroundLayers()}),r),this._getStableGroundLayers=t(()=>this._ground?.layers?.toArray(),r)}get minDemResolution(){return a(this._ground)}get available(){return!0===this._ground?.layers.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,t){const r=this._queryElevationDependencies;if(null==r)throw new Error(`${this.declaredClass}: no dependencies`);const{ground:o}=r;if(null==o)throw new Error("No ground configured in the view");const n=await o.queryElevation(e,t),s=i(e.spatialReference),l=i(o.layers.at(0).spatialReference);if(s!==l){const e=n.geometry;e.points=e.points.map(([e,r,o])=>[e,r,o===t.noDataValue?o:o*l/s])}return n}get _queryElevationDependencies(){return this._getStableQueryElevationDependencies()}get _ground(){return this.controller.view?.map?.ground}};e([n()],u.prototype,"minDemResolution",null),e([n()],u.prototype,"available",null),e([n()],u.prototype,"_queryElevationDependencies",null),e([n()],u.prototype,"_ground",null),u=e([s("esri.views.analysis.ElevationProfile.ElevationProfileLineGroundComputation")],u);export{u as ElevationProfileLineGroundComputation};
