/*
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{open as t}from"../../../core/workers.js";import{property as o,subclass as r}from"../../../core/accessorSupport/decorators.js";import{create as n}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as a}from"../ray.js";import{intersectRay as i}from"../triangle.js";import s from"./ElevationSamplerWorker.js";import l from"../../../layers/support/ElevationSampler.js";async function c(e,t){const o=await p(),r=await x.createIndex(e,o);u(o);const n=e.spatialReference,a=e.extent.clone();return new m({spatialReference:n,extent:a,noDataValue:t?.noDataValue||0,rindex:r})}let m=class extends l{constructor(e){super(e),this.demResolution={min:0,max:0}}elevationAt(e,t){let o=Number.NEGATIVE_INFINITY;return a([e,t,0],[0,0,-1],N),this.rindex.search({minX:e,maxX:e,minY:t,maxY:t},e=>{i(e,N,j)&&j[2]>o&&(o=j[2])}),o===Number.NEGATIVE_INFINITY?this.noDataValue:o}};function p(){return++y,f(),d||(d=t("ElevationSamplerWorker").catch(()=>null),d)}function u(e){--y,null!=e&&0===y&&(v=setTimeout(()=>{e.close(),d=null,v=0},I))}function f(){v&&(clearTimeout(v),v=0)}e([o({constructOnly:!0})],m.prototype,"spatialReference",void 0),e([o({constructOnly:!0})],m.prototype,"extent",void 0),e([o({constructOnly:!0})],m.prototype,"noDataValue",void 0),e([o({constructOnly:!0})],m.prototype,"rindex",void 0),m=e([r("esri.geometry.support.meshUtils.elevationSampler")],m);const x=new s;let y=0,d=null,v=0;const I=1e4,N=a([0,0,0],[0,0,-1]),j=n();export{c as create};
