UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.66 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{copy as e}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{computeTranslationToOriginAndRotation as o}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectBuffer as r}from"../../../../geometry/projection/projectBuffer.js";import{isDehydratedPoint as i}from"../../../../layers/graphics/dehydratedFeatureUtils.js";import{isSamplePosition as a,getElevationAtPoint as s}from"../../support/ElevationProvider.js";import{VertexAttribute as l}from"../../webgl-engine/lib/VertexAttribute.js";function u(e,t,n,o,i,a,s,l,u,c,f){const m=x[f.mode];let d,g,p=0;if(r(e,t,n,o,u.spatialReference,i,l))return m?.requiresAlignment(f)?(p=m.applyElevationAlignmentBuffer(o,i,a,s,l,u,c,f),d=a,g=s):(d=o,g=i),r(d,u.spatialReference,g,a,c.spatialReference,s,l)?p:void 0}function c(e,t,n,o,r){const l=(i(e)?e.z:a(e)?e.array[e.offset+2]:e[2])||0;switch(n.mode){case"on-the-ground":{const n=s(t,e,"ground")??0;return r.verticalDistanceToGround=0,r.sampledElevation=n,void(r.z=n)}case"relative-to-ground":{const i=s(t,e,"ground")??0,a=n.geometryZWithOffset(l,o);return r.verticalDistanceToGround=a,r.sampledElevation=i,void(r.z=a+i)}case"relative-to-scene":{const i=s(t,e,"scene")??0,a=n.geometryZWithOffset(l,o);return r.verticalDistanceToGround=a,r.sampledElevation=i,void(r.z=a+i)}case"absolute-height":{const i=n.geometryZWithOffset(l,o),a=s(t,e,"ground")??0;return r.verticalDistanceToGround=i-a,r.sampledElevation=a,void(r.z=i)}default:return void(r.z=0)}}function f(e,t,n,o){return c(e,t,n,o,D),D.z}function m(e,t,n){return"on-the-ground"===t&&"on-the-ground"===n?e.staysOnTheGround:t===n||"on-the-ground"!==t&&"on-the-ground"!==n?null==t||null==n?e.definedChanged:b.UPDATE:e.onTheGroundChanged}function d(e){return"relative-to-ground"===e||"relative-to-scene"===e}function g(e){return"absolute-height"!==e}function p(t,n,r,i,a){c(n,r,a,i,D),E(t,D.verticalDistanceToGround);const s=D.sampledElevation,l=e(C,t.transformation);O[0]=n.x,O[1]=n.y,O[2]=D.z;return o(n.spatialReference,O,l,i.spatialReference)?t.transformation=l:console.warn("Could not locate symbol object properly, it might be misplaced"),s}function E(e,t){for(let n=0;n<e.geometries.length;++n){const o=e.geometries[n].getMutableAttribute(l.CENTEROFFSETANDDISTANCE);o&&o.data[3]!==t&&(o.data[3]=t,e.geometryVertexAttributeUpdated(e.geometries[n],l.CENTEROFFSETANDDISTANCE))}}function v(e,t,n,o,r,i){let a=0;const s=i.spatialReference;t*=3,o*=3;for(let l=0;l<r;++l){const r=e[t],l=e[t+1],u=e[t+2],c=i.getElevation(r,l,u,s,"ground")??0;a+=c,n[o]=r,n[o+1]=l,n[o+2]=c,t+=3,o+=3}return a/r}function h(e,t,n,o,r,i,a,s){let l=0;const u=s.calculateOffsetRenderUnits(a),c=s.featureExpressionInfoContext,f=i.spatialReference;t*=3,o*=3;for(let m=0;m<r;++m){const r=e[t],a=e[t+1],s=e[t+2],m=i.getElevation(r,a,s,f,"ground")??0;l+=m,n[o]=r,n[o+1]=a,n[o+2]=null==c?s+m+u:m+u,t+=3,o+=3}return l/r}function A(e,t,n,o,r,i,a,s){let l=0;const u=s.calculateOffsetRenderUnits(a),c=s.featureExpressionInfoContext,f=i.spatialReference;t*=3,o*=3;for(let m=0;m<r;++m){const r=e[t],a=e[t+1],s=e[t+2],m=i.getElevation(r,a,s,f,"scene")??0;l+=m,n[o]=r,n[o+1]=a,n[o+2]=null==c?s+m+u:m+u,t+=3,o+=3}return l/r}function T(e){const t=e.meterUnitOffset,n=e.featureExpressionInfoContext;return 0!==t||null!=n}function y(e,t,n,o,r,i,a,s){const l=s.calculateOffsetRenderUnits(a),u=s.featureExpressionInfoContext;t*=3,o*=3;for(let c=0;c<r;++c){const r=e[t],i=e[t+1],a=e[t+2];n[o]=r,n[o+1]=i,n[o+2]=null==u?a+l:l,t+=3,o+=3}return 0}class R{constructor(){this.verticalDistanceToGround=0,this.sampledElevation=0,this.z=0}}var b;!function(e){e[e.NONE=0]="NONE",e[e.UPDATE=1]="UPDATE",e[e.RECREATE=2]="RECREATE"}(b||(b={}));const x={"absolute-height":{applyElevationAlignmentBuffer:y,requiresAlignment:T},"on-the-ground":{applyElevationAlignmentBuffer:v,requiresAlignment:()=>!0},"relative-to-ground":{applyElevationAlignmentBuffer:h,requiresAlignment:()=>!0},"relative-to-scene":{applyElevationAlignmentBuffer:A,requiresAlignment:()=>!0}},C=t(),D=new R,O=n();export{R as SampleElevationInfo,b as SymbolUpdateType,p as applyElevationAlignmentForHUD,u as applyPerVertexElevationAlignment,m as elevationModeChangeUpdateType,f as evaluateElevationAlignmentAtPoint,c as evaluateElevationInfoAtPoint,d as needsElevationUpdates2D,g as needsElevationUpdates3D,E as updateVertexPointGroundDistance};