UNPKG

geodesy-fn

Version:

Geodesic functions for GeoJSON, based on geodesy

3 lines (2 loc) 1.51 kB
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).GeodesyFn={})}(this,(function(t){"use strict";function n(t){return t/180*Math.PI}function a(t){return t/Math.PI*180}function s(t){return(t+360)%360}function i(t,i){if(h=t,o=i,!(Math.abs(h[0]-o[0])>Number.EPSILON||Math.abs(h[1]-o[1])>Number.EPSILON))return NaN;var h,o;const M=n(t[1]),e=n(i[1]),c=n(i[0]-t[0]),r=Math.cos(M)*Math.sin(e)-Math.sin(M)*Math.cos(e)*Math.cos(c),u=Math.sin(c)*Math.cos(e);return s(a(Math.atan2(u,r)))}t.destinationPoint=function(t,s,i,h=6371e3){const o=s/h,M=n(i),e=n(t[1]),c=n(t[0]),r=Math.sin(e)*Math.cos(o)+Math.cos(e)*Math.sin(o)*Math.cos(M),u=Math.asin(r),f=Math.sin(M)*Math.sin(o)*Math.cos(e),d=Math.cos(o)-Math.sin(e)*r,y=c+Math.atan2(f,d),l=a(u);return[a(y),l]},t.distance=function(t,a,s=6371e3){const i=s,h=n(t[1]),o=n(t[0]),M=n(a[1]),e=M-h,c=n(a[0])-o,r=Math.sin(e/2)*Math.sin(e/2)+Math.cos(h)*Math.cos(M)*Math.sin(c/2)*Math.sin(c/2);return i*(2*Math.atan2(Math.sqrt(r),Math.sqrt(1-r)))},t.finalBearing=function(t,n){return s(i(n,t)+180)},t.initialBearing=i,t.midpoint=function(t,s){const i=n(t[1]),h=n(t[0]),o=n(s[1]),M=n(s[0]-t[0]),e=Math.cos(i),c=0,r=Math.sin(i),u={x:e+Math.cos(o)*Math.cos(M),y:c+Math.cos(o)*Math.sin(M),z:r+Math.sin(o)},f=Math.atan2(u.z,Math.sqrt(u.x*u.x+u.y*u.y)),d=h+Math.atan2(u.y,u.x),y=a(f);return[a(d),y]}})); //# sourceMappingURL=geodesy-fn.umd.min.js.map