UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.28 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import e from"../../../core/Logger.js";import{getMetersPerUnitForSR as t}from"../../../core/unitUtils.js";import o from"../../Mesh.js";import n from"../../Point.js";import{project as r}from"../../projection.js";import i from"../MeshComponent.js";import{MeshVertexAttributes as s}from"../MeshVertexAttributes.js";import{isGround as a}from"../../../support/groundInstanceUtils.js";const l=()=>e.getLogger("esri.geometry.support.meshUtils.elevation");async function m(e,t,n){let r;if(p(e)||a(e)){const o=await c(e);return r=await o.createElevationSampler(t,{demResolution:n?.demResolution??"finest-contiguous"}),u(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):u(e,t,{material:n?.material,demResolution:n?.demResolution})}function u(e,n,a){if(e.demResolution.min<=0&&!a?.demResolution)return l().error("create()","demResolution must be specified when used with groundView.elevationSampler"),new o;const m=t(n.spatialReference),u=(a?.demResolution??e.demResolution.min)/m,c=Math.round(n.width/u),p=Math.round(n.height/u),d=c+1,w=p+1,R=new Float64Array(d*w*3),h=new Float32Array(d*w*2);let y=0,g=0;const j=new Uint32Array(c*p*2*3);let v=0,A=0;const b=!e.spatialReference.equals(n.spatialReference);f.spatialReference=n.spatialReference;const{xmin:x,ymin:M,height:U,width:S}=n;for(let t=0;t<w;t++){const o=M+U*(t/p);for(let n=0;n<d;n++){const i=x+S*(n/c);if(R[y++]=i,R[y++]=o,b){f.x=i,f.y=o;const t=r(f,e.spatialReference);R[y++]=e.elevationAt(t.x,t.y)??0}else R[y++]=e.elevationAt(i,o)??0;const s=n/c,a=t/p;h[g++]=s,h[g++]=a,t!==p&&n!==c&&(j[A++]=v+1,j[A++]=v+d+1,j[A++]=v+d,j[A++]=v,j[A++]=v+1,j[A++]=v+d),v++}}return new o({vertexAttributes:new s({position:R,uv:h}),components:[new i({faces:j,shading:"smooth",material:a?.material??null})],spatialReference:n.spatialReference})}async function c(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};