/*
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","../../geometry","../../core/has","../../core/Logger","../../core/maybe","../../core/unitUtils","../../geometry/support/aaBoundingRect","../../geometry/support/webMercatorUtils","../../geometry/Point"],(function(e,t,n,o,i,a,r,s,l,u){"use strict";const c=i.getLogger("esri.layers.support.ElevationSampler");let p=function(){function e(){}var t=e.prototype;return t.queryElevation=function(e){return h(e.clone(),this)},t.on=function(){return g},t.projectIfRequired=function(e,t){return x(e,t)},e}(),m=function(e){function n(t,n,o){var i;(i=e.call(this)||this).tile=t,i.noDataValue=o,i.extent=s.toExtent(t.tile.extent,n.spatialReference),i.extent.zmin=t.zmin,i.extent.zmax=t.zmax,i.aaExtent=t.tile.extent;const a=r.getMetersPerUnitForSR(n.spatialReference),l=n.lodAt(t.tile.level).resolution*a;return i.demResolution={min:l,max:l},i}t._inheritsLoose(n,e);var o=n.prototype;return o.contains=function(e){const t=this.projectIfRequired(e,this.spatialReference);return!a.isNone(t)&&this.containsAt(t.x,t.y)},o.containsAt=function(e,t){return s.containsXY(this.aaExtent,e,t)},o.elevationAt=function(e,t){if(!this.containsAt(e,t)){const n=this.extent,o=`${n.xmin}, ${n.ymin}, ${n.xmax}, ${n.ymax}`;return c.warn("#elevationAt()",`Point used to sample elevation (${e}, ${t}) is outside of the sampler extent (${o})`),this.noDataValue}return a.unwrapOr(this.tile.sample(e,t),this.noDataValue)},t._createClass(n,[{key:"spatialReference",get:function(){return this.extent.spatialReference}}]),n}(p),f=function(e){function n(t,n,o){var i;let a;i=e.call(this)||this,"number"==typeof n?(i.noDataValue=n,a=null):(a=n,i.noDataValue=o),i.samplers=a?t.map((e=>new m(e,a,i.noDataValue))):t;const r=i.samplers[0];if(r){i.extent=r.extent.clone();const{min:e,max:t}=r.demResolution;i.demResolution={min:e,max:t};for(let n=1;n<i.samplers.length;n++){const e=i.samplers[n];i.extent.union(e.extent),i.demResolution.min=Math.min(i.demResolution.min,e.demResolution.min),i.demResolution.max=Math.max(i.demResolution.max,e.demResolution.max)}}else i.extent=s.toExtent(s.create(),a.spatialReference),i.demResolution={min:0,max:0};return i}return t._inheritsLoose(n,e),n.prototype.elevationAt=function(e,t){for(const n of this.samplers)if(n.containsAt(e,t))return n.elevationAt(e,t);return c.warn("#elevationAt()",`Point used to sample elevation (${e}, ${t}) is outside of the sampler`),this.noDataValue},t._createClass(n,[{key:"spatialReference",get:function(){return this.extent.spatialReference}}]),n}(p);function h(e,t){const n=x(e,t.spatialReference);if(!n)return null;switch(e.type){case"point":R(e,n,t);break;case"polyline":d(e,n,t);break;case"multipoint":y(e,n,t)}return e}function x(e,t){if(a.isNone(e))return null;const n=e.spatialReference;if(n.equals(t))return e;const o=l.project(e,t);return o||c.error(`Cannot project geometry spatial reference (wkid:${n.wkid}) to elevation sampler spatial reference (wkid:${t.wkid})`),o}function R(e,t,n){e.z=n.elevationAt(t.x,t.y)}function d(e,t,n){v.spatialReference=t.spatialReference;const o=e.hasM&&!e.hasZ;for(let i=0;i<e.paths.length;i++){const a=e.paths[i],r=t.paths[i];for(let e=0;e<a.length;e++){const t=a[e],i=r[e];v.x=i[0],v.y=i[1],o&&(t[3]=t[2]),t[2]=n.elevationAt(v.x,v.y)}}e.hasZ=!0}function y(e,t,n){v.spatialReference=t.spatialReference;const o=e.hasM&&!e.hasZ;for(let i=0;i<e.points.length;i++){const a=e.points[i],r=t.points[i];v.x=r[0],v.y=r[1],o&&(a[3]=a[2]),a[2]=n.elevationAt(v.x,v.y)}e.hasZ=!0}const v=new u,g={remove(){}};e.ElevationSamplerBase=p,e.MultiTileElevationSampler=f,e.TileElevationSampler=m,e.updateGeometryElevation=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
