UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 7.1 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{Cyclical as t,cyclical2PI as e}from"../core/Cyclical.js";import{deg2rad as r,rad2deg as s,asinClamped as o,lerp as a,clamp as n}from"../core/mathUtils.js";import{fromRotation as i,rotate as c}from"../core/libs/gl-matrix-2/math/mat4.js";import{create as l}from"../core/libs/gl-matrix-2/factories/mat4f64.js";import{h as m,e as p,n as u,t as f,u as h,l as d,g,j as y,m as M,x as T,b as R}from"./vec32.js";import{fromValues as j,create as _,ZEROS as E,clone as b}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as I,b as S}from"./vec42.js";import{create as v}from"../core/libs/gl-matrix-2/factories/vec4f64.js";import{getEpsilon as x}from"../core/libs/gl-matrix-2/math/common.js";import{getReferenceEllipsoid as A}from"../geometry/ellipsoidUtils.js";import N from"../geometry/Extent.js";import O from"../geometry/Polygon.js";import w from"../geometry/SpatialReference.js";import{isClockwise as C}from"../geometry/support/coordsUtils.js";import{PlaneIndex as F}from"../geometry/support/frustum.js";import{fromPoints as U,create as P}from"../geometry/support/lineSegment.js";import{fromPositionAndNormal as H,create as D,isPointInside as G,intersectLineOrRay as q,IntersectFlags as k,IntersectResult as L,getNormal as B}from"../geometry/support/plane.js";import{wrap as W}from"../geometry/support/ray.js";import{b as z,c as Y,d as J}from"./sphere.js";import{geographicToWebMercator as K}from"../geometry/support/webMercatorUtils.js";import{Frustum as Q,LineIndex as V}from"../views/3d/state/Frustum.js";import{minNearDistanceInMeters as X}from"../views/3d/state/NearFarHeuristic.js";import{viewAngle as Z}from"../views/3d/state/utils/viewUtils.js";import{createDirectionUp as $,directionToHeadingTilt as tt,clampLineSegmentToPlane as et}from"../views/3d/support/cameraUtilsInternal.js";import{getLonDeltaForDistance as rt}from"../views/3d/support/earthUtils.js";import{slerp as st}from"../views/3d/support/mathUtils.js";const ot=j(0,0,1),at=u(_(),j(1,1,1)),nt=new t(-180,180),it=l(),ct=_(),lt=_();function mt(t,e,s,o=$()){m(ct,t,ot),0===p(ct,ct)&&m(ct,t,at),i(it,-r(e),t),c(it,it,-r(s),ct);const{up:a,direction:n}=o;return m(a,ct,t),u(a,a),f(a,a,it),u(n,t),h(n,n),f(n,n,it),o}function pt(t,e,r,s){const o=ct,a=lt;return u(o,t),m(lt,o,ot),0===p(lt,lt)&&m(lt,o,at),m(a,lt,o),tt(e,r,s,o,a)}function ut(t,e,s,a){const n={eye:_(),up:null,tilt:a,heading:s},i=ct;i[0]=t[0],i[1]=t[2],i[2]=-t[1];const c=e,l=r(s),m=r(a),p=Math.sin(l),u=Math.cos(l),f=Math.sin(m),h=Math.cos(m),y=d(i);let M;if(Math.abs(m)<1e-8)M=c+y;else{const t=y/f,e=o(c/t),r=Math.PI-m-e;M=t*Math.sin(r)}const T=h*c,R=c*c*(f*f),j=u*u*R,E=M-T,b=E*E,I=j*(j+b-i[1]*i[1]);if(I<0)return g(n.eye,i,M/y),n.tilt=0,ht(n,t);const S=Math.sqrt(I),v=i[1]*E,x=j+b;let A;if(A=u>0?-S+v:S+v,Math.abs(x)<1e-8)return y<1e-8?(n.eye[0]=0,n.eye[1]=0,n.eye[2]=c):g(n.eye,i,M/y),n.tilt=0,ft(n.eye),ht(n,t);n.eye[1]=A/x;const N=p*p*R,O=f*c,w=u*O*n.eye[1],C=n.eye[1]*n.eye[1],F=1-C,U=Math.sqrt(F),P=j*C+N-2*w*U*E+F*b;return Math.abs(P)<1e-8?(g(n.eye,i,M/y),n.tilt=0,ft(n.eye),ht(n,t)):(n.eye[0]=(F*(M*i[0]-T*i[0])-O*U*(i[0]*n.eye[1]*u+i[2]*p))/P,n.eye[2]=(F*(M*i[2]-T*i[2])-O*U*(i[2]*n.eye[1]*u-i[0]*p))/P,g(n.eye,n.eye,M),ft(n.eye),ht(n,t))}function ft(t){const e=t[1];t[1]=-t[2],t[2]=e}function ht(t,e){const r=mt(e,t.heading,t.tilt);return t.up=r.up,t}function dt(t,e,r){const a=d(e),n=Math.sqrt(r*r+a*a-2*r*a*Math.cos(Math.PI-t)),i=o(r/(n/Math.sin(t)));return s(t-i)}function gt(t,e,s){const a=r(t),n=d(e);return o(s/(n/Math.sin(a)))+a}function yt(t,o,a,n,i){let c,l,m,p;const u=o.latitude,f=A(t.spatialReference).radius,h=o.longitude,d=rt(u,a,f)/2;c=h-d,l=h+d;const g=r(u),y=(1+Math.sin(g))/(1-Math.sin(g)),M=(y+1)*Math.tan(n/f/2),T=M*M;function R(t){const r=Math.PI/2;return(t=e.normalize(t,-r))>r&&(t=Math.PI-t),t}if(m=1.5*Math.PI-2*Math.atan(.5*(M+Math.sqrt(4*y+T))),p=m+n/f,m=R(m),p=R(p),p<m){const t=p;p=m,m=t}if(m=Math.max(s(m),-90),p=Math.min(s(p),90),l=nt.monotonic(c,l),l-c>180){const t=(l-c-180)/2;c+=t,l-=t}const j=t.spatialReference&&t.spatialReference.isGeographic?t.spatialReference:w.WGS84;return i?(i.xmin=c,i.ymin=m,i.xmax=l,i.ymax=p,i.spatialReference=j):i=new N(c,m,l,p,j),t.spatialReference&&t.spatialReference.isWebMercator&&K(i,!1,i),i}function Mt(t,e){const{renderCoordsHelper:r}=t,s=t.state.camera.clone(),o=new Q(r);s.near=X,o.update(s);const i=r.getAltitude(e),c=t.spatialReference,l=r.referenceEllipsoid.radius,m=s.eye,p=1+y(m,e)/(l+i),u=Math.sqrt(p*p-1),{minCurvature:f,maxCurvature:h,minSamples:d,maxSamples:g}=Et,R=_t(t),j=n((u-f)/(h-f),0,1),_=Math.round(a(d,g,j)),v=s.aboveGround,x=o.planes[F.FAR],A=[],N=H(E,bt,D()),w=H(E,It,D());I(Ot,0,0,0,0);const C=t=>{};for(let n=0;n<4;n++){const t=n===V.NEAR_FAR_BOTTOM_RIGHT&&!v||n===V.NEAR_FAR_TOP_LEFT&&v?1-R:0,e=n===V.NEAR_FAR_BOTTOM_RIGHT&&v||n===V.NEAR_FAR_TOP_LEFT&&!v?R:1,s=o.lines[n],c=o.lines[3===n?0:n+1];for(let o=0;o<_;o++){const l=o/_,p=n===V.NEAR_FAR_BOTTOM_RIGHT?1-(1-l)**2:n===V.NEAR_FAR_TOP_LEFT?l**2:l,u=0===o?0:a(t,e,p),f=M(vt,s.origin,c.origin,u),h=st(s.direction,c.direction,u,St);r.intersectManifoldClosestSilhouette(W(f,h),i,xt),et(xt,m,xt,x),A.push(b(xt)),0!==A.length&&C(T(A.at(-1),xt));const d=(G(N,xt)?1:0)|(G(w,xt)?2:0);Ot[d]=1}}A.length>2&&C(T(A[0],A.at(-1)));const U=Tt(S(Ot)>1?Rt(jt(A,N),w):[A],r,c);return new O({rings:U,spatialReference:c})}function Tt(t,e,r){const s=2*x();return t.map((t=>{const o=[];let a=!1;for(const n of t)e.fromRenderCoords(n,xt,r),Math.abs(n[0])<s&&Math.abs(n[1])<s?(o.push([null,xt[1]]),o.push([null,xt[1]]),a=!0):o.push([xt[0],xt[1]]);if(a)for(let e=0;e<o.length;e++){const t=o[e];if(null!=t[0])continue;const r=o[e+1],s=o.at(0===e?-1:e-1);t[0]=s[0],e++;const a=o.at(e===o.length-1?0:e+1);r[0]=a[0]}return o.push(o[0]),C(o)||o.reverse(),o}))}function Rt(t,e){const r=[];for(const s of t)r.push(...jt(s,e));return r}function jt(t,e){const r=[],s=[],o=x();for(let n=0;n<t.length;n++){const a=t[n],i=n===t.length-1?t[0]:t[n+1],c=U(a,i,Nt),l=q(e,c.origin,c.vector,k.NONE,xt);switch(l){case L.INSIDE:r.push(a);break;case L.OUTSIDE:s.push(a);break;case L.INTERSECTS_INSIDE_OUT:case L.INTERSECTS_OUTSIDE_IN:{const[t,n,i]=l===L.INTERSECTS_INSIDE_OUT?[1,r,s]:[-1,s,r],c=B(e),m=R(_(),xt,c,t*o),p=R(_(),xt,c,t*-o);n.push(a),n.push(m),i.push(p)}}}const a=[];return r.length&&a.push(r),s.length&&a.push(s),a}function _t(t){const{renderCoordsHelper:e,state:{camera:r}}=t,{center:s,eye:o}=r,a=Math.abs(e.getAltitude(s)),n=Math.abs(Math.PI/2-Z(e,s,o));return z(At,e.referenceEllipsoid.radius+a),J(At,n,r.distance,r.fovY)}const Et={minCurvature:r(5),maxCurvature:r(50),minSamples:1,maxSamples:6},bt=j(1,0,0),It=j(0,1,0),St=_(),vt=_(),xt=_(),At=Y(),Nt=P(),Ot=v(),wt=Object.freeze(Object.defineProperty({__proto__:null,directionToHeadingTilt:pt,eyeForCenterWithHeadingTilt:ut,eyeTiltToLookAtTilt:gt,headingTiltToDirectionUp:mt,lookAtTiltToEyeTilt:dt,toArea:Mt,toExtent:yt},Symbol.toStringTag,{value:"Module"}));export{gt as a,Mt as b,wt as c,pt as d,ut as e,mt as h,dt as l,yt as t};