cameraUtilsSpherical.js 3.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{Cyclical as t,cyclical2PI as e}from"../core/Cyclical.js";import{deg2rad as o,rad2deg as n,asinClamped as a}from"../core/mathUtils.js";import{d as i,e as s}from"./mat4.js";import{c as r}from"./mat4f64.js";import{n as c,f as l,e as m,m as f,o as p,l as h,g as u}from"./vec3.js";import{f as y,c as M}from"./vec3f64.js";import d from"../geometry/Extent.js";import{getReferenceEllipsoid as g}from"../geometry/projectionEllipsoid.js";import j from"../geometry/SpatialReference.js";import{geographicToWebMercator as T}from"../geometry/support/webMercatorUtils.js";import{createDirectionUp as b,directionToHeadingTilt as x}from"../views/3d/support/cameraUtilsInternal.js";import{getLonDeltaForDistance as R}from"../views/3d/support/earthUtils.js";const I=y(0,0,1),P=c(M(),y(1,1,1)),v=new t(-180,180),w=r(),U=M(),q=M();function E(t,e,n,a=b()){l(U,t,I),0===m(U,U)&&l(U,t,P),i(w,-o(e),t),s(w,w,-o(n),U);const{up:r,direction:h}=a;return l(r,U,t),c(r,r),f(r,r,w),c(h,t),p(h,h),f(h,h,w),a}function S(t,e,o,n){const a=U,i=q;return c(a,t),l(q,a,I),0===m(q,q)&&l(q,a,P),l(i,q,a),x(e,o,n,a,i)}function _(t,e,n,i){const s={eye:M(),up:null,tilt:i,heading:n},r=U;r[0]=t[0],r[1]=t[2],r[2]=-t[1];const c=e,l=o(n),m=o(i),f=Math.sin(l),p=Math.cos(l),y=Math.sin(m),d=Math.cos(m),g=h(r);let j;if(Math.abs(m)<1e-8)j=c+g;else{const t=g/y,e=a(c/t),o=Math.PI-m-e;j=t*Math.sin(o)}const T=d*c,b=c*c*(y*y),x=p*p*b,R=j-T,I=R*R,P=x*(x+I-r[1]*r[1]);if(P<0)return u(s.eye,r,j/g),s.tilt=0,s;const v=Math.sqrt(P),w=r[1]*R,q=x+I;let E;if(E=p>0?-v+w:v+w,Math.abs(q)<1e-8)return g<1e-8?(s.eye[0]=0,s.eye[1]=0,s.eye[2]=c):u(s.eye,r,j/g),s.tilt=0,H(s.eye),W(s,t);s.eye[1]=E/q;const S=f*f*b,_=y*c,k=p*_*s.eye[1],z=s.eye[1]*s.eye[1],A=1-z,C=Math.sqrt(A),G=x*z+S-2*k*C*R+A*I;return Math.abs(G)<1e-8?(u(s.eye,r,j/g),s.tilt=0,H(s.eye),W(s,t)):(s.eye[0]=(A*(j*r[0]-T*r[0])-_*C*(r[0]*s.eye[1]*p+r[2]*f))/G,s.eye[2]=(A*(j*r[2]-T*r[2])-_*C*(r[2]*s.eye[1]*p-r[0]*f))/G,u(s.eye,s.eye,j),H(s.eye),W(s,t))}function H(t){const e=t[1];t[1]=-t[2],t[2]=e}function W(t,e){const o=E(e,t.heading,t.tilt);return t.up=o.up,t}function k(t,e,o){const i=h(e),s=Math.sqrt(o*o+i*i-2*o*i*Math.cos(Math.PI-t)),r=a(o/(s/Math.sin(t)));return n(t-r)}function z(t,e,n){const i=o(t),s=h(e);return a(n/(s/Math.sin(i)))+i}function A(t,a,i,s,r){let c,l,m,f;const p=a.latitude,h=g(t.spatialReference).radius,u=a.longitude,y=R(p,i,h)/2;c=u-y,l=u+y;const M=o(p),b=(1+Math.sin(M))/(1-Math.sin(M)),x=(b+1)*Math.tan(s/h/2),I=x*x;function P(t){const o=Math.PI/2;return(t=e.normalize(t,-o))>o&&(t=Math.PI-t),t}if(m=1.5*Math.PI-2*Math.atan(.5*(x+Math.sqrt(4*b+I))),f=m+s/h,m=P(m),f=P(f),f<m){const t=f;f=m,m=t}if(m=Math.max(n(m),-90),f=Math.min(n(f),90),l=v.monotonic(c,l),l-c>180){const t=(l-c-180)/2;c+=t,l-=t}const w=t.spatialReference&&t.spatialReference.isGeographic?t.spatialReference:j.WGS84;return r?(r.xmin=c,r.ymin=m,r.xmax=l,r.ymax=f,r.spatialReference=w):r=new d(c,m,l,f,w),t.spatialReference&&t.spatialReference.isWebMercator&&T(r,!1,r),r}const C=Object.freeze(Object.defineProperty({__proto__:null,headingTiltToDirectionUp:E,directionToHeadingTilt:S,eyeForCenterWithHeadingTilt:_,lookAtTiltToEyeTilt:k,eyeTiltToLookAtTilt:z,toExtent:A},Symbol.toStringTag,{value:"Module"}));export{z as a,C as c,S as d,_ as e,E as h,k as l,A as t};