@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.56 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import"../../core/has.js";import{makeHandle as e}from"../../core/handleUtils.js";import t from"../../core/Logger.js";import{getMetersPerUnitForSR as n}from"../../core/unitUtils.js";import s from"../../geometry/Point.js";import{toExtent as i,create as o,containsXY as a}from"../../geometry/support/aaBoundingRect.js";import{project as r}from"../../geometry/support/webMercatorUtils.js";const l=()=>t.getLogger("esri.layers.support.ElevationSampler");class c{queryElevation(e){return p(e.clone(),this)}on(){return e()}projectIfRequired(e,t){return h(e,t)}}class m extends c{get spatialReference(){return this.extent.spatialReference}constructor(e,t,s){super(),this.tile=e,this.noDataValue=s;const o=e.tile.extent;this.extent=i(o,t.spatialReference),this.extent.zmin=e.zmin,this.extent.zmax=e.zmax,this._aaExtent=o;const a=n(t.spatialReference),r=t.lodAt(e.tile.level).resolution*a;this.demResolution={min:r,max:r}}contains(e){const t=this.projectIfRequired(e,this.spatialReference);return null!=t&&this.containsAt(t.x,t.y)}containsAt(e,t){return a(this._aaExtent,e,t)}elevationAt(e,t){if(!this.containsAt(e,t)){const n=this.extent,s=`${n.xmin}, ${n.ymin}, ${n.xmax}, ${n.ymax}`;return l().warn("#elevationAt()",`Point used to sample elevation (${e}, ${t}) is outside of the sampler extent (${s})`),this.noDataValue}return this.tile.sample(e,t)??this.noDataValue}}class u extends c{get spatialReference(){return this.extent.spatialReference}constructor(e,t,n){let s;super(),"number"==typeof t?(this.noDataValue=t,s=null):(s=t,this.noDataValue=n),this.samplers=s?e.map((e=>new m(e,s,this.noDataValue))):e;const a=this.samplers[0];if(a){this.extent=a.extent.clone();const{min:e,max:t}=a.demResolution;this.demResolution={min:e,max:t};for(let n=1;n<this.samplers.length;n++){const e=this.samplers[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 this.extent=i(o(),s.spatialReference),this.demResolution={min:0,max:0}}elevationAt(e,t){let n,s=!1;for(const i of this.samplers)if(i.containsAt(e,t)&&(s=!0,n=i.elevationAt(e,t),n!==i.noDataValue))return n;return null!=n?n:(s||l().warn("#elevationAt()",`Point used to sample elevation (${e}, ${t}) is outside of the sampler`),this.noDataValue)}}function p(e,t){const n=h(e,t.spatialReference);if(!n)return null;switch(e.type){case"point":f(e,n,t);break;case"polyline":x(e,n,t);break;case"multipoint":R(e,n,t)}return e}function h(e,t){if(null==e)return null;const n=e.spatialReference;if(n.equals(t))return e;const s=r(e,t);return s||l().error(`Cannot project geometry spatial reference (wkid:${n.wkid}) to elevation sampler spatial reference (wkid:${t.wkid})`),s}function f(e,t,n){e.z=n.elevationAt(t.x,t.y)}function x(e,t,n){d.spatialReference=t.spatialReference;const s=e.hasM&&!e.hasZ;for(let i=0;i<e.paths.length;i++){const o=e.paths[i],a=t.paths[i];for(let e=0;e<o.length;e++){const t=o[e],i=a[e];d.x=i[0],d.y=i[1],s&&(t[3]=t[2]),t[2]=n.elevationAt(d.x,d.y)}}e.hasZ=!0}function R(e,t,n){d.spatialReference=t.spatialReference;const s=e.hasM&&!e.hasZ;for(let i=0;i<e.points.length;i++){const o=e.points[i],a=t.points[i];d.x=a[0],d.y=a[1],s&&(o[3]=o[2]),o[2]=n.elevationAt(d.x,d.y)}e.hasZ=!0}const d=new s;export{c as ElevationSamplerBase,u as MultiTileElevationSampler,m as TileElevationSampler,p as updateGeometryElevation};