@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6.97 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/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{n as m,e as p,f as u,t as f,v as h,l as y,h as d,j as g,m as M,y 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,f as S}from"./vec42.js";import{create as v}from"../core/libs/gl-matrix-2/factories/vec4f64.js";import{getEpsilon as A}from"../core/libs/gl-matrix-2/math/common.js";import{getReferenceEllipsoid as x}from"../geometry/ellipsoidUtils.js";import O from"../geometry/Extent.js";import N from"../geometry/Polygon.js";import C from"../geometry/SpatialReference.js";import{isClockwise as U}from"../geometry/support/coordsUtils.js";import{PlaneIndex as F}from"../geometry/support/frustum.js";import{create as w,fromPoints 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,d as Y,c as J}from"./sphere.js";import{geographicToWebMercator as K}from"../geometry/support/webMercatorUtils.js";import{LineIndex as Q}from"../views/3d/state/Frustum.js";import{viewAngle as V}from"../views/3d/state/utils/viewUtils.js";import{createDirectionUp as X,directionToHeadingTilt as Z,clampLineSegmentToPlane as $}from"../views/3d/support/cameraUtilsInternal.js";import{getLonDeltaForDistance as tt}from"../views/3d/support/earthUtils.js";import{slerp as et}from"../views/3d/support/mathUtils.js";const rt=j(0,0,1),st=m(_(),j(1,1,1)),ot=new t(-180,180),at=l(),nt=_(),it=_();function ct(t,e,s,o=X()){p(nt,t,rt),0===u(nt,nt)&&p(nt,t,st),i(at,-r(e),t),c(at,at,-r(s),nt);const{up:a,direction:n}=o;return p(a,nt,t),m(a,a),f(a,a,at),m(n,t),h(n,n),f(n,n,at),o}function lt(t,e,r,s){const o=nt,a=it;return m(o,t),p(it,o,rt),0===u(it,it)&&p(it,o,st),p(a,it,o),Z(e,r,s,o,a)}function mt(t,e,s,a){const n={eye:_(),up:null,tilt:a,heading:s},i=nt;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),g=y(i);let M;if(Math.abs(m)<1e-8)M=c+g;else{const t=g/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 d(n.eye,i,M/g),n.tilt=0,ut(n,t);const S=Math.sqrt(I),v=i[1]*E,A=j+b;let x;if(x=u>0?-S+v:S+v,Math.abs(A)<1e-8)return g<1e-8?(n.eye[0]=0,n.eye[1]=0,n.eye[2]=c):d(n.eye,i,M/g),n.tilt=0,pt(n.eye),ut(n,t);n.eye[1]=x/A;const O=p*p*R,N=f*c,C=u*N*n.eye[1],U=n.eye[1]*n.eye[1],F=1-U,w=Math.sqrt(F),P=j*U+O-2*C*w*E+F*b;return Math.abs(P)<1e-8?(d(n.eye,i,M/g),n.tilt=0,pt(n.eye),ut(n,t)):(n.eye[0]=(F*(M*i[0]-T*i[0])-N*w*(i[0]*n.eye[1]*u+i[2]*p))/P,n.eye[2]=(F*(M*i[2]-T*i[2])-N*w*(i[2]*n.eye[1]*u-i[0]*p))/P,d(n.eye,n.eye,M),pt(n.eye),ut(n,t))}function pt(t){const e=t[1];t[1]=-t[2],t[2]=e}function ut(t,e){const r=ct(e,t.heading,t.tilt);return t.up=r.up,t}function ft(t,e,r){const a=y(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 ht(t,e,s){const a=r(t),n=y(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=x(t.spatialReference).radius,h=o.longitude,y=tt(u,a,f)/2;c=h-y,l=h+y;const d=r(u),g=(1+Math.sin(d))/(1-Math.sin(d)),M=(g+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*g+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=ot.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:C.WGS84;return i?(i.xmin=c,i.ymin=m,i.xmax=l,i.ymax=p,i.spatialReference=j):i=new O(c,m,l,p,j),t.spatialReference&&t.spatialReference.isWebMercator&&K(i,!1,i),i}function dt(t,e){const r=t.frustum,{renderCoordsHelper:s}=t,o=s.getAltitude(e),i=t.spatialReference,c=s.referenceEllipsoid.radius,l=t.state.camera,m=l.eye,p=1+g(m,e)/(c+o),u=Math.sqrt(p*p-1),{minCurvature:f,maxCurvature:h,minSamples:y,maxSamples:d}=jt,R=Rt(t),j=n((u-f)/(h-f),0,1),_=Math.round(a(y,d,j)),v=l.aboveGround,A=r.planes[F.FAR],x=[],O=H(E,_t,D()),C=H(E,Et,D());I(xt,0,0,0,0);const U=t=>{};for(let n=0;n<4;n++){const t=n===Q.NEAR_FAR_BOTTOM_RIGHT&&!v||n===Q.NEAR_FAR_TOP_LEFT&&v?1-R:0,e=n===Q.NEAR_FAR_BOTTOM_RIGHT&&v||n===Q.NEAR_FAR_TOP_LEFT&&!v?R:1,i=r.lines[n],c=r.lines[3===n?0:n+1];for(let r=0;r<_;r++){const l=r/_,p=n===Q.NEAR_FAR_BOTTOM_RIGHT?1-(1-l)**2:n===Q.NEAR_FAR_TOP_LEFT?l**2:l,u=0===r?0:a(t,e,p),f=M(It,i.origin,c.origin,u),h=et(i.direction,c.direction,u,bt);s.intersectManifoldClosestSilhouette(W(f,h),o,St),$(St,m,St,A),x.push(b(St)),0!==x.length&&U(T(x.at(-1),St));const y=(G(O,St)?1:0)|(G(C,St)?2:0);xt[y]=1}}x.length>2&&U(T(x[0],x.at(-1)));const w=gt(S(xt)>1?Mt(Tt(x,O),C):[x],s,i);return new N({rings:w,spatialReference:i})}function gt(t,e,r){const s=2*A();return t.map((t=>{const o=[];let a=!1;for(const n of t)e.fromRenderCoords(n,St,r),Math.abs(n[0])<s&&Math.abs(n[1])<s?(o.push([null,St[1]]),o.push([null,St[1]]),a=!0):o.push([St[0],St[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]),U(o)||o.reverse(),o}))}function Mt(t,e){const r=[];for(const s of t)r.push(...Tt(s,e));return r}function Tt(t,e){const r=[],s=[],o=A();for(let n=0;n<t.length;n++){const a=t[n],i=n===t.length-1?t[0]:t[n+1],c=P(a,i,At),l=q(e,c.origin,c.vector,k.NONE,St);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(_(),St,c,t*o),p=R(_(),St,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 Rt(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-V(e,s,o));return z(vt,e.referenceEllipsoid.radius+a),Y(vt,n,r.distance,r.fovY)}const jt={minCurvature:r(5),maxCurvature:r(50),minSamples:1,maxSamples:6},_t=j(1,0,0),Et=j(0,1,0),bt=_(),It=_(),St=_(),vt=J(),At=w(),xt=v(),Ot=Object.freeze(Object.defineProperty({__proto__:null,directionToHeadingTilt:lt,eyeForCenterWithHeadingTilt:mt,eyeTiltToLookAtTilt:ht,headingTiltToDirectionUp:ct,lookAtTiltToEyeTilt:ft,toArea:dt,toExtent:yt},Symbol.toStringTag,{value:"Module"}));export{ht as a,dt as b,Ot as c,lt as d,mt as e,ct as h,ft as l,yt as t};