SunCalc.js 2.5 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. var n,t,r,e={exports:{}};n=e,t=function(){var n=Math.PI,t=Math.sin,r=Math.cos,e=Math.tan,o=Math.asin,u=Math.atan2,a=Math.acos,i=n/180,c=864e5,f=2440588,d=2451545,s={dec:0,ra:0};function v(n){return n.valueOf()/c-.5+f}function M(n){return new Date((n+.5-f)*c)}function p(n){return v(n)-d}var h=23.4397*i;function l(n,o){return u(t(n)*r(h)-e(o)*t(h),r(n))}function x(n,e){return o(t(e)*r(h)+r(e)*t(h)*t(n))}function N(n,o,a){return u(t(n),r(n)*t(o)-e(a)*r(o))}function P(n,e,u){return o(t(e)*t(u)+r(e)*r(u)*r(n))}function E(n,t){return i*(280.16+360.9856235*n)-t}function I(n){return i*(357.5291+.98560028*n)}function O(n){return i*(1.9148*t(n)+.02*t(2*n)+3e-4*t(3*n))}function T(t,r){return t+r+102.9372*i+n}function g(n,t){var r=I(n),e=T(r,O(r));return t||(t={dec:0,ra:0}),t.dec=x(e,0),t.ra=l(e,0),t}var m={PolarException:{NORMAL:0,MIDNIGHT_SUN:1,POLAR_NIGHT:2},getPosition:function(n,t,r,e){var o=i*-r,u=i*t,a=p(n),c=g(a,s),f=E(a,o)-c.ra;return e||(e={azimuth:0,altitude:0}),e.azimuth=N(f,u,c.dec),e.altitude=P(f,u,c.dec),e}},A=[[-.83,"sunrise","sunset"]];m.addTime=function(n,t,r){A.push([n,t,r])};var L=9e-4;function R(t,r){return Math.round(t-L-r/(2*n))}function G(t,r,e){return L+(t+r)/(2*n)+e}function H(n,r,e){return d+n+.0053*t(r)-.0069*t(2*e)}function _(n,e,o){return a((t(n)-t(e)*t(o))/(r(e)*r(o)))}function z(n){var e=i*(134.963+13.064993*n),o=i*(93.272+13.22935*n),u=i*(218.316+13.176396*n)+6.289*i*t(e),a=5.128*i*t(o),c=385001-20905*r(e);return{ra:l(u,a),dec:x(u,a),dist:c}}return m.getTimes=function(n,e,o){var u=i*-o,a=i*e,c=R(p(n),u),f=G(0,u,c),d=I(f),s=O(d),v=T(d,s),h=x(v,0),l=H(f,d,v);function N(n){return H(G(_(n,a,h),u,c),d,v)}function P(n){var e=(t(n)-t(a)*t(h))/(r(a)*r(h));return e<-1?m.PolarException.MIDNIGHT_SUN:e>1?m.PolarException.POLAR_NIGHT:m.PolarException.NORMAL}var E,g,L,z,D,S={solarNoon:M(l),nadir:M(l-.5),polarException:m.PolarException.NORMAL};for(E=0,g=A.length;E<g;E+=1)D=l-((z=N((L=A[E])[0]*i))-l),S[L[1]]=M(D),S[L[2]]=M(z);return S.polarException=P(A[0][0]*i),S},m.getMoonPosition=function(n,t,r){var o=i*-r,u=i*t,a=p(n),c=z(a),f=E(a,o)-c.ra,d=P(f,u,c.dec);return d+=.017*i/e(d+10.26*i/(d+5.1*i)),{azimuth:N(f,u,c.dec),altitude:d,distance:c.dist}},m.getMoonFraction=function(n){var e=p(n),o=g(e),i=z(e),c=149598e3,f=a(t(o.dec)*t(i.dec)+r(o.dec)*r(i.dec)*r(o.ra-i.ra)),d=u(c*t(f),i.dist-c*r(f));return(1+r(d))/2},m},void 0!==(r=t())&&(n.exports=r);const o=e.exports;export{o as S};