@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.01 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import e from"../../../core/Logger.js";import{getMetersPerUnitForSR as t}from"../../../core/units.js";import o from"../../Mesh.js";import n from"../../Point.js";import{project as r}from"../../projectionUtils.js";import i from"../MeshComponent.js";import a from"../MeshVertexAttributes.js";import{isGround as s}from"../../../support/groundInstanceUtils.js";const l=()=>e.getLogger("esri.geometry.support.meshUtils.elevation");async function m(e,t,n){let r;if(p(e)||s(e)){const o=await u(e);return r=await o.createElevationSampler(t,{demResolution:n?.demResolution??"finest-contiguous"}),c(r,t,{material:n?.material})}return"string"==typeof n?.demResolution?(l().error("create()","demResolution must be a number when used directly with a sampler"),new o):c(e,t,{material:n?.material,demResolution:n?.demResolution})}function c(e,n,s){const l=t(n.spatialReference),m=(s?.demResolution??e.demResolution.min)/l,c=Math.round(n.width/m),u=Math.round(n.height/m),p=c+1,d=u+1,h=new Float64Array(p*d*3),w=new Float32Array(p*d*2);let R=0,y=0;const g=new Uint32Array(c*u*2*3);let j=0,v=0;const A=!e.spatialReference.equals(n.spatialReference);f.spatialReference=n.spatialReference;const{xmin:x,ymin:b,height:M,width:U}=n;for(let t=0;t<d;t++){const o=b+M*(t/u);for(let n=0;n<p;n++){const i=x+U*(n/c);if(h[R++]=i,h[R++]=o,A){f.x=i,f.y=o;const t=r(f,e.spatialReference);h[R++]=e.elevationAt(t.x,t.y)??0}else h[R++]=e.elevationAt(i,o)??0;const a=n/c,s=t/u;w[y++]=a,w[y++]=s,t!==u&&n!==c&&(g[v++]=j+1,g[v++]=j+p+1,g[v++]=j+p,g[v++]=j,g[v++]=j+1,g[v++]=j+p),j++}}return new o({vertexAttributes:new a({position:h,uv:w}),components:[new i({faces:g,shading:"smooth",material:s?.material??null})],spatialReference:n.spatialReference})}async function u(e){return p(e)?e.load():(await e.load(),await Promise.allSettled(e.layers.items.map(e=>e.load())),e)}function p(e){return"type"in e&&("elevation"===e.type||"base-elevation"===e.type)}const f=new n;export{m as create};