@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.66 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{max as e,createLength as t,createArea as r}from"../../core/quantity.js";import{deriveLengthUnitFromAreaUnit as o}from"../../core/units.js";import{set as n,scale as i,normalize as s,cross as a,subtract as c,dot as m,add as f}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as p}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{isEarth as u,isSphericalECEF as l}from"../../geometry/ellipsoidUtils.js";import g from"../../geometry/Point.js";import y from"../../geometry/Polygon.js";import O from"../../geometry/Polyline.js";import{projectWithoutEngine as h}from"../../geometry/projectionUtils.js";import S from"../../geometry/SpatialReference.js";import{WGS84ECEFSpatialReference as J,getSphericalPCPF as N,SphericalECEFSpatialReference as d}from"../../geometry/spatialReferenceEllipsoidUtils.js";import{e as j}from"../../chunks/areaOperator.js";import{e as R}from"../../chunks/centroidOperator.js";import{e as w}from"../../chunks/distanceOperator.js";import{l as k,e as v}from"../../chunks/geodeticAreaOperator.js";import{load as U,execute as x}from"../../geometry/operators/geodeticDistanceOperator.js";import{l as L,e as P}from"../../chunks/geodeticLengthOperator.js";import{e as M}from"../../chunks/lengthOperator.js";import{e as b}from"../../chunks/simplifyOperator.js";import{projectDirection as C}from"../../geometry/projection/projectDirection.js";import{isWGS84 as q,isWebMercator as z,isCGCS2000 as E,equals as Z}from"../../geometry/support/spatialReferenceUtils.js";import{makeOrthonormal as D}from"../3d/support/mathUtils.js";import{autoMeasurementMode as W}from"./measurementWorkerUtils.js";async function $({geometryJSON:e,options:t}){await Promise.allSettled([k(),t?.returnLength?L():void 0]);const n=B(e,t),i=t?.unit??"square-meters",s=b(n)??n,a=v(s,{unit:i,...t}),c=r(a,i),m=t?.lengthUnit??o(i);return{area:c,centroid:t?.returnCentroid?F(s).toJSON():void 0,length:t?.returnLength?await G(s,{unit:m}):void 0}}function A(){k(),L(),U()}function B(e,t){const r="rings"in e?y.fromJSON(e):O.fromJSON(e);if(t?.stagedPoint){const e=g.fromJSON(t.stagedPoint),o=("rings"in r?r.rings:r.paths).at(-1);if(o){const{x:t,y:n,z:i,m:s}=e,a=r.hasZ&&r.hasM?[t,n,i??0,s??0]:r.hasZ?[t,n,i??0]:r.hasM?[t,n,s??0]:[t,n];o.push(a)}}return r}function F(e){return R(e)}async function G(e,r){await L();const o=r?.unit??"meters";return t(P(e,{...r,unit:o}),o)}function H({geometryJSON:e,options:t}){return G(B(e,t),t)}async function I({geometry1JSON:e,geometry2JSON:r,options:o}){await U();const n=g.fromJSON(e),i=g.fromJSON(r),s=o?.unit??"meters";return t(x(n,i,{...o,unit:s}),s)}function K({geometryJSON:e,options:t}){return Q(B(e,t),t)}function Q(e,t){const n=t?.unit??"square-meters",i=t?.lengthUnit??o(n),s=b(e)??e,a=j(s,{unit:n,...t});return{area:r(a,n),centroid:t?.returnCentroid?F(s).toJSON():void 0,length:t?.returnLength?T(s,{unit:i}):void 0}}function T(e,r){const o=r?.unit??"meters";return t(M(e,{...r,unit:o}),o)}function V({geometryJSON:e,options:t}){return T(B(e,t),t)}function X({geometry1JSON:e,geometry2JSON:r,options:o}){const n=g.fromJSON(e),i=g.fromJSON(r),s=o?.unit??"meters";return t(w(n,i,{...o,unit:s}),s)}async function Y(e){return re(e.geometryJSON.spatialReference,$,K)(e)}async function _(e){return re(e.geometryJSON.spatialReference,H,V)(e)}async function ee(e){return re(e.geometry1JSON.spatialReference,I,X)(e)}async function te(t){const r=re(t.topLeftJSON.spatialReference,I,X),{topLeftJSON:o,topRightJSON:n,bottomRightJSON:i,bottomLeftJSON:s,options:a}=t,[c,m,f,p]=await Promise.all([r({geometry1JSON:s,geometry2JSON:i,options:a}),r({geometry1JSON:o,geometry2JSON:n,options:a}),r({geometry1JSON:i,geometry2JSON:n,options:a}),r({geometry1JSON:s,geometry2JSON:o,options:a})]);return{width:e(c,m),height:e(p,f)}}function re(e,t,r){switch(W(e)){case 0:return t;case 1:return r}}function oe(e){const{geometryJSON:t}=e,r=ae(t.spatialReference);if(!r)throw new Error("Cannot compute horizontal area without a valid spatial reference.");switch(r.mode){case 0:return K(e);case 1:return ne(r,e)}}function ne(e,{geometryJSON:t,options:r}){const o=B(t,r),n=fe,i=ce,s=me,a=Z(o.spatialReference,e.spatialReference)?o.clone():h(o,o.spatialReference,e.spatialReference);if(!a)throw new Error(`Cannot project geometry from ${o.spatialReference?.wkid??"unknown"} to ${e.spatialReference.wkid}.`);se(a,n,i,s);const{area:c,centroid:m,length:f}=Q(a,r);return{area:c,centroid:ie(m,n,i,s,e.spatialReference,o.spatialReference),length:f}}function ie(e,t,r,o,n,s){if(!e)return e;i(r,r,e.x),i(o,o,e.y);const a=pe;return f(a,r,o),f(a,a,t),e.x=a[0],e.y=a[1],e.z=a[2],e.spatialReference=n,h(e,e.spatialReference,s)?.toJSON()??void 0}function se(e,t,r,o){let f=0;n(t,0,0,0);for(const n of e.rings)for(const e of n)t[0]+=e[0],t[1]+=e[1],t[2]+=e[2],f++;i(t,t,1/f);const p=ue;s(p,t);const u=le,l=Math.atan2(p[1],p[0]);n(u,-Math.sin(l),Math.cos(l),0),Z(e.spatialReference,J)&&(C(t,p,d,p,e.spatialReference),C(t,u,d,u,e.spatialReference)),D(u,p,r),a(o,r,p);const g=pe;for(const i of e.rings)for(const e of i){n(g,e[0],e[1],e[2]),c(g,g,t);const i=m(r,g),s=m(o,g);e[0]=i,e[1]=s}e.hasZ=!1,e.spatialReference=S.WebMercator}function ae(e){return e?u(e)?q(e)||z(e)||E(e)||l(e)||Z(e,J)?{mode:1,spatialReference:J}:{mode:0,spatialReference:e}:{mode:1,spatialReference:N(e)}:null}const ce=p(),me=p(),fe=p(),pe=p(),ue=p(),le=p();export{K as area2D,oe as areaHorizontal,Y as autoArea2D,ee as autoDistance2DBetweenPoints,_ as autoLength2D,te as autoSize2D,X as distance2DBetweenPoints,$ as geodeticArea,I as geodeticDistanceBetweenPoints,H as geodeticLength,V as length2D,A as preloadGeodetic};