@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.75 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{cyclical2PI as e}from"../core/Cyclical.js";import{deg2rad as t,rad2deg as r,asinClamped as o,lerp as s,clamp as n}from"../core/mathUtils.js";import{fromRotation as i,rotate as a}from"../core/libs/gl-matrix-2/math/mat4.js";import{create as c}from"../core/libs/gl-matrix-2/factories/mat4f64.js";import{normalize as l,cross as m,dot as p,length as u,scale as f,transformMat4 as h,negate as g,distance as y,lerp as d,sqrDist as M,scaleAndAdd as j}from"../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as b,clone as x,create as v,fromValues as T}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as w,squaredLength as C}from"../core/libs/gl-matrix-2/math/vec4.js";import{create as R}from"../core/libs/gl-matrix-2/factories/vec4f64.js";import{getEpsilon as S}from"../core/libs/gl-matrix-2/math/common.js";import{getReferenceEllipsoid as U}from"../geometry/ellipsoidUtils.js";import P from"../geometry/Extent.js";import H from"../geometry/Polygon.js";import I from"../geometry/SpatialReference.js";import{isClockwise as q}from"../geometry/support/coordsUtils.js";import{fromPoints as A,create as E}from"../geometry/support/lineSegment.js";import{gcsCyclical as k}from"../geometry/support/normalizeUtils.js";import{fromPositionAndNormal as F,create as _,isPointInside as z,intersectLineOrRay as G,getNormal as W}from"../geometry/support/plane.js";import{wrap as O}from"../geometry/support/ray.js";import{Sphere as D}from"../geometry/support/sphere.js";import{geographicToWebMercator as L}from"../geometry/support/webMercatorUtils.js";import{Frustum as N}from"../views/3d/state/Frustum.js";import{minNearDistanceInMeters as B}from"../views/3d/state/NearFarHeuristic.js";import{directionToHeadingTilt as J,createDirectionUp as K,clampLineSegmentToPlane as Q}from"../views/3d/support/cameraUtilsInternal.js";import{getLonDeltaForDistance as V}from"../views/3d/support/earthUtils.js";import{slerp as X}from"../views/3d/support/mathUtils.js";const Y=T(0,0,1),Z=l(v(),T(1,1,1)),$=c(),ee=v(),te=v();function re(e,r,o,s=K()){m(ee,e,Y),0===p(ee,ee)&&m(ee,e,Z),i($,-t(r),e),a($,$,-t(o),ee);const{up:n,direction:c}=s;return m(n,ee,e),l(n,n),h(n,n,$),l(c,e),g(c,c),h(c,c,$),s}function oe(e,t,r,o){const s=ee,n=te;return l(s,e),m(te,s,Y),0===p(te,te)&&m(te,s,Z),m(n,te,s),J(t,r,o,s,n)}function se(e,r,s,n){const i={eye:v(),up:null,tilt:n,heading:s},a=ee;a[0]=e[0],a[1]=e[2],a[2]=-e[1];const c=r,l=t(s),m=t(n),p=Math.sin(l),h=Math.cos(l),g=Math.sin(m),y=Math.cos(m),d=u(a);let M;if(Math.abs(m)<1e-8)M=c+d;else{const e=d/g,t=o(c/e),r=Math.PI-m-t;M=e*Math.sin(r)}const j=y*c,b=c*c*(g*g),x=h*h*b,T=M-j,w=T*T,C=x*(x+w-a[1]*a[1]);if(C<0)return f(i.eye,a,M/d),i.tilt=0,ie(i,e);const R=Math.sqrt(C),S=a[1]*T,U=x+w;let P;if(P=h>0?-R+S:R+S,Math.abs(U)<1e-8)return d<1e-8?(i.eye[0]=0,i.eye[1]=0,i.eye[2]=c):f(i.eye,a,M/d),i.tilt=0,ne(i.eye),ie(i,e);i.eye[1]=P/U;const H=p*p*b,I=g*c,q=h*I*i.eye[1],A=i.eye[1]*i.eye[1],E=1-A,k=Math.sqrt(E),F=x*A+H-2*q*k*T+E*w;return Math.abs(F)<1e-8?(f(i.eye,a,M/d),i.tilt=0,ne(i.eye),ie(i,e)):(i.eye[0]=(E*(M*a[0]-j*a[0])-I*k*(a[0]*i.eye[1]*h+a[2]*p))/F,i.eye[2]=(E*(M*a[2]-j*a[2])-I*k*(a[2]*i.eye[1]*h-a[0]*p))/F,f(i.eye,i.eye,M),ne(i.eye),ie(i,e))}function ne(e){const t=e[1];e[1]=-e[2],e[2]=t}function ie(e,t){const r=re(t,e.heading,e.tilt);return e.up=r.up,e}function ae(e,t,s){const n=u(t),i=Math.sqrt(s*s+n*n-2*s*n*Math.cos(Math.PI-e)),a=o(s/(i/Math.sin(e)));return r(e-a)}function ce(e,r,s){const n=t(e),i=u(r);return o(s/(i/Math.sin(n)))+n}function le(o,s,n,i,a){let c,l,m,p;const u=s.latitude,f=U(o.spatialReference).radius,h=s.longitude,g=V(u,n,f)/2;c=h-g,l=h+g;const y=t(u),d=(1+Math.sin(y))/(1-Math.sin(y)),M=(d+1)*Math.tan(i/f/2),j=M*M;function b(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*d+j))),p=m+i/f,m=b(m),p=b(p),p<m){const e=p;p=m,m=e}if(m=Math.max(r(m),-90),p=Math.min(r(p),90),l=k.monotonic(c,l),l-c>180){const e=(l-c-180)/2;c+=e,l-=e}const x=o.spatialReference&&o.spatialReference.isGeographic?o.spatialReference:I.WGS84;return a?(a.xmin=c,a.ymin=m,a.xmax=l,a.ymax=p,a.spatialReference=x):a=new P(c,m,l,p,x),o.spatialReference&&o.spatialReference.isWebMercator&&L(a,!1,a),a}function me(e,t){const{renderCoordsHelper:r}=e,o=e.state.camera.clone(),i=new N(r);o.near=B,i.update(o);const a=r.getAltitude(t),c=e.spatialReference,l=r.referenceEllipsoid.radius,m=o.eye,p=1+y(m,t)/(l+a),u=Math.sqrt(p*p-1),{minCurvature:f,maxCurvature:h,minSamples:g,maxSamples:j}=ge,v=he(e),T=n((u-f)/(h-f),0,1),R=Math.round(s(g,j,T)),S=o.aboveGround,U=i.planes[5],P=[],I=F(b,ye,_()),q=F(b,de,_());w(Te,0,0,0,0);const A=e=>{};for(let n=0;n<4;n++){const e=1===n&&!S||3===n&&S?1-v:0,t=1===n&&S||3===n&&!S?v:1,o=i.lines[n],c=i.lines[3===n?0:n+1];for(let i=0;i<R;i++){const l=i/R,p=0===i?0:s(e,t,1===n?1-(1-l)**2:3===n?l**2:l),u=d(je,o.origin,c.origin,p),f=X(o.direction,c.direction,p,Me);r.intersectManifoldClosestSilhouette(O(u,f),a,be),Q(be,m,be,U),P.push(x(be)),0!==P.length&&A(M(P.at(-1),be));const h=(z(I,be)?1:0)|(z(q,be)?2:0);Te[h]=1}}P.length>2&&A(M(P[0],P.at(-1)));const E=pe(C(Te)>1?ue(fe(P,I),q):[P],r,c);return new H({rings:E,spatialReference:c})}function pe(e,t,r){const o=2*S();return e.map(e=>{const s=[];let n=!1;for(const i of e)t.fromRenderCoords(i,be,r),Math.abs(i[0])<o&&Math.abs(i[1])<o?(s.push([null,be[1]]),s.push([null,be[1]]),n=!0):s.push([be[0],be[1]]);if(n)for(let t=0;t<s.length;t++){const e=s[t];if(null!=e[0])continue;const r=s[t+1],o=s.at(0===t?-1:t-1);e[0]=o[0],t++;const n=s.at(t===s.length-1?0:t+1);r[0]=n[0]}return s.push(s[0]),q(s)||s.reverse(),s})}function ue(e,t){const r=[];for(const o of e)r.push(...fe(o,t));return r}function fe(e,t){const r=[],o=[],s=S();for(let i=0;i<e.length;i++){const n=e[i],a=i===e.length-1?e[0]:e[i+1],c=A(n,a,ve),l=G(t,c.origin,c.vector,0,be);switch(l){case 2:r.push(n);break;case 3:o.push(n);break;case 0:case 1:{const[e,i,a]=0===l?[1,r,o]:[-1,o,r],c=W(t),m=j(v(),be,c,e*s),p=j(v(),be,c,e*-s);i.push(n),i.push(m),a.push(p)}}}const n=[];return r.length&&n.push(r),o.length&&n.push(o),n}function he(e){const{renderCoordsHelper:t,state:r}=e,o=Math.abs(t.getAltitude(r.camera.center));return xe.radius=t.referenceEllipsoid.radius+o,r.camera.sphereFrustumCoverage(xe,t)}const ge={minCurvature:t(5),maxCurvature:t(50),minSamples:1,maxSamples:6},ye=T(1,0,0),de=T(0,1,0),Me=v(),je=v(),be=v(),xe=new D,ve=E(),Te=R(),we=Object.freeze(Object.defineProperty({__proto__:null,directionToHeadingTilt:oe,eyeForCenterWithHeadingTilt:se,eyeTiltToLookAtTilt:ce,headingTiltToDirectionUp:re,lookAtTiltToEyeTilt:ae,toArea:me,toExtent:le},Symbol.toStringTag,{value:"Module"}));export{ce as a,le as b,we as c,oe as d,se as e,re as h,ae as l,me as t};