@idm-plugin/geo 1.2.9 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ class l {
131
131
  lng: l.str2Lng(t, e)
132
132
  };
133
133
  }
134
- static convertToStdLng(t, e = 4) {
134
+ static convertToStdLng(t, e = 6) {
135
135
  return t > 180 ? (t = t % 360, t = t > 180 ? t - 360 : t) : t < -180 && (t = t % 360, t = t < -180 ? t + 360 : t), l.roundPrecision(t, e);
136
136
  }
137
137
  static roundPrecision(t, e = 4) {
@@ -285,7 +285,7 @@ class S {
285
285
  const i = [];
286
286
  let o, s;
287
287
  for (let r = 0; r < t.length - 1; r++) {
288
- o = l.convertToStdLng(t[r].lng, 8), s = l.convertToStdLng(t[r + 1].lng, 8), n.push([o, t[r].lat]);
288
+ o = l.convertToStdLng(t[r].lng, 8), s = l.convertToStdLng(t[r + 1].lng, 8), t[r].lat = l.roundPrecision(t[r].lat, 8), t[r + 1].lat = l.roundPrecision(t[r + 1].lat, 8), n.push([o, t[r].lat]);
289
289
  const c = o - s;
290
290
  if (Math.abs(c) > 180) {
291
291
  const a = l.convertToMonotonicLng2([
@@ -510,7 +510,7 @@ class S {
510
510
  * @param options
511
511
  */
512
512
  static calculatePointToLineDistance(t, e, n, i = { units: "nauticalmiles", method: "geodesic" }) {
513
- t.lng = l.convertToStdLng(t.lng), e = { ...e }, n = { ...n }, e.lng = l.convertToStdLng(e.lng, 8), n.lng = l.convertToStdLng(n.lng, 8);
513
+ t.lng = l.convertToStdLng(t.lng, 8), e = { ...e }, n = { ...n }, e.lng = l.convertToStdLng(e.lng, 8), n.lng = l.convertToStdLng(n.lng, 8);
514
514
  const o = l.convertToMonotonicLng([e, n]);
515
515
  e = o[0], n = o[1];
516
516
  const s = g.lineString([
@@ -632,26 +632,26 @@ class S {
632
632
  r.push(h);
633
633
  else {
634
634
  const m = [];
635
- let b;
635
+ let P;
636
636
  for (let M = 0; M < h.length; M++)
637
637
  if (u)
638
638
  m.push(h[M]);
639
639
  else {
640
- b = { lng: h[M][0], lat: h[M][1] };
641
- const T = this.calculateDistance(t, b, !0, 8, i);
642
- if (a += T, a < e)
643
- d += T, s.push(b), t = b;
640
+ P = { lng: h[M][0], lat: h[M][1] };
641
+ const b = this.calculateDistance(t, P, !0, 8, i);
642
+ if (a += b, a < e)
643
+ d += b, s.push(P), t = P;
644
644
  else {
645
645
  if (d = e, a === e)
646
- u = b, m.push([u.lng, u.lat]);
646
+ u = P, m.push([u.lng, u.lat]);
647
647
  else {
648
- const p = a - e, N = this.calculateBearing(b, t);
649
- u = this.calculateCoordinate(b, N, p, i), m.push([u.lng, u.lat]), m.push([b.lng, b.lat]);
648
+ const p = a - e, N = this.calculateBearing(P, t);
649
+ u = this.calculateCoordinate(P, N, p, i), m.push([u.lng, u.lat]), m.push([P.lng, P.lat]);
650
650
  }
651
651
  c = !0;
652
652
  }
653
653
  }
654
- m.length && r.push(m), C === n.length - 1 && !u && (u = b);
654
+ m.length && r.push(m), C === n.length - 1 && !u && (u = P);
655
655
  }
656
656
  })) : (r = n, u = { ...t }), u)
657
657
  if (s.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / o * 1e4) / 1e4, ((f = r[0]) == null ? void 0 : f.length) > 1) {
@@ -684,7 +684,7 @@ class S {
684
684
  let i, o;
685
685
  return t.forEach((s) => {
686
686
  s.forEach((r) => {
687
- const c = { lng: r[0], lat: r[1] };
687
+ const c = { lng: l.roundPrecision(r[0], 8), lat: l.roundPrecision(r[1], 8) };
688
688
  if (!o)
689
689
  n.push(c), o = c;
690
690
  else if (o.bearing === void 0)
@@ -714,7 +714,7 @@ class S {
714
714
  */
715
715
  static simplifyGCCoordinates(t, e) {
716
716
  e.forEach((i) => {
717
- this.mergeCoordinateToWaypoints(i, t);
717
+ this.mergeCoordinateToWaypoints(i, t, !0);
718
718
  });
719
719
  for (let i = 1; i < e.length; i++) {
720
720
  const o = e[i - 1], s = e[i];
@@ -775,9 +775,9 @@ class S {
775
775
  return this.calculateBBox(e);
776
776
  }
777
777
  }
778
- let P;
778
+ let T;
779
779
  try {
780
- P = L.getLogger("vessel");
780
+ T = L.getLogger("vessel");
781
781
  } catch {
782
782
  } finally {
783
783
  }
@@ -886,22 +886,22 @@ class U {
886
886
  const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = D(a.properties.date).utc();
887
887
  let C = e * 60 - (h.get("hour") * 60 + h.get("minute")) % (e * 60);
888
888
  const m = (s = t == null ? void 0 : t.data) == null ? void 0 : s.features.filter(
889
- (T) => T.geometry.type === "Point" && T.properties.type === "forecast" && T.properties.category === `${d}-${u}`
889
+ (b) => b.geometry.type === "Point" && b.properties.type === "forecast" && b.properties.category === `${d}-${u}`
890
890
  );
891
- let b, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
892
- for (; b = this.pickIndex(m, M), b <= m.length - 1; ) {
893
- if (b > 0) {
894
- const T = m[b], p = b === 0 ? void 0 : m[b - 1], N = (C / 60 - ((r = p == null ? void 0 : p.properties) == null ? void 0 : r.hour)) / (T.properties.hour - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)), x = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], T.geometry.coordinates[0], N), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], T.geometry.coordinates[1], N), $ = g.point([x, I], {
891
+ let P, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
892
+ for (; P = this.pickIndex(m, M), P <= m.length - 1; ) {
893
+ if (P > 0) {
894
+ const b = m[P], p = P === 0 ? void 0 : m[P - 1], N = (C / 60 - ((r = p == null ? void 0 : p.properties) == null ? void 0 : r.hour)) / (b.properties.hour - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)), x = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], b.geometry.coordinates[0], N), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], b.geometry.coordinates[1], N), $ = g.point([x, I], {
895
895
  name: d,
896
896
  model: u,
897
- category: T == null ? void 0 : T.properties.category,
897
+ category: b == null ? void 0 : b.properties.category,
898
898
  date: M.format(),
899
899
  format: M.format("MMM-DD/HHmm[Z]"),
900
- gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, T.properties.gusts, N),
901
- hour: this.computeNumber(p == null ? void 0 : p.properties.hour, T.properties.hour, N),
902
- movement: this.computeNumber(p == null ? void 0 : p.properties.movement, T.properties.movement, N),
903
- pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, T.properties.pressure, N),
904
- wind: this.computeNumber(p == null ? void 0 : p.properties.wind, T.properties.wind, N),
900
+ gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, b.properties.gusts, N),
901
+ hour: this.computeNumber(p == null ? void 0 : p.properties.hour, b.properties.hour, N),
902
+ movement: this.computeNumber(p == null ? void 0 : p.properties.movement, b.properties.movement, N),
903
+ pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, b.properties.pressure, N),
904
+ wind: this.computeNumber(p == null ? void 0 : p.properties.wind, b.properties.wind, N),
905
905
  type: "forecast",
906
906
  showCircle: f
907
907
  });
@@ -930,7 +930,7 @@ class U {
930
930
  let f = 0;
931
931
  u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
932
932
  const h = S.calculateCoordinate(o, f, n);
933
- return P == null || P.info("[%s] the right tangent position: %j", i.requestId, {
933
+ return T == null || T.info("[%s] the right tangent position: %j", i.requestId, {
934
934
  from: t,
935
935
  t1: o,
936
936
  t2: s,
@@ -958,7 +958,7 @@ class U {
958
958
  const a = S.calculateBearing(t, o), d = S.calculateBearing(o, s), u = S.calculateDistance(t, o);
959
959
  return { at: S.calculateCoordinate(o, a - d + 180, n < u ? n : u), t1: o, t2: s, hr: Number(r), hours: c };
960
960
  } else
961
- return P == null || P.info("[%s] no need drift: %j", i.requestId, { from: t, t1: o, t2: s, hr: r }), {};
961
+ return T == null || T.info("[%s] no need drift: %j", i.requestId, { from: t, t1: o, t2: s, hr: r }), {};
962
962
  }
963
963
  /**
964
964
  * 获取台风中心点对
@@ -974,11 +974,11 @@ class U {
974
974
  i = { ...m.hours, ...i };
975
975
  });
976
976
  const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (i == null ? void 0 : i[(f = Object.keys(i)) == null ? void 0 : f[0]]);
977
- P == null || P.info("[%s] the first tropical center: %j", n.requestId, o);
977
+ T == null || T.info("[%s] the first tropical center: %j", n.requestId, o);
978
978
  let s = (h = Object.keys(i || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
979
979
  s || (s = (C = Object.keys(i || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : C.at(-1));
980
980
  const r = i == null ? void 0 : i[s || -1];
981
- P == null || P.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, s);
981
+ T == null || T.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, s);
982
982
  const c = Object.keys(i || {}).filter((m) => Number(m) <= Number(s)), a = { 0: o };
983
983
  for (const m of c)
984
984
  a[m] = i[m];
@@ -1 +1 @@
1
- (function(C,R){typeof exports=="object"&&typeof module<"u"?R(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],R):(C=typeof globalThis<"u"?globalThis:C||self,R(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,R,y,B,$){"use strict";function k(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const g=k(R);function j(b){return b&&b.__esModule&&Object.prototype.hasOwnProperty.call(b,"default")?b.default:b}class x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(b=>{x.prototype[b.toLowerCase()]=()=>{},x.prototype[`is${b}Enabled`]=()=>!1});const I=(()=>{try{return require("log4js")}catch{return null}})();var L={getLogger:I?I.getLogger:()=>new x};const O=j(L);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),o=y().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,s=Number(o.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${o}E`:s<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${s>0?"E":"W"}`:e=`${o}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${s}`}}class v{static calculateBearing(e,t,n=!0,o=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(s.features[0],s.features[1]):i=g.bearing(s.features[0],s.features[1]),i<0&&(i+=360),l.roundPrecision(i,o)}static calculateDistance(e,t,n=!0,o=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:s}):r=g.distance(i.features[0],i.features[1],{units:s}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,s;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&s&&(o+=this.calculateDistance(s,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};o+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",s=!0){const i=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(i,n,t,{units:o}):r=g.destination(i,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,s=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let s,i;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),n.push([s,e[r].lat]);const c=s-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const h=g.lineIntersect(d,u);let f;if(h.features.length){const M=g.getCoord(h.features[0]);f=l.roundPrecision(M[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),o.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),o.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((s,i)=>(s.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&s.push(i),s),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,s=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},h={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,h);n>f&&(n=f,s=d,o=a,i=this.calculateDistance(u,e),r=this.calculateDistance(h,e))}}),i!==0&&r!==0?t[o].splice(s+1,0,[e.lng,e.lat]):i===0?t[o].splice(s,1,[e.lng,e.lat]):r===0&&t[o].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=v.convertRouteToCoordinates(t);return n.push(e),v.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=v.convertRouteToCoordinates(t);return n.unshift(e),v.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let s=0;return n.forEach(i=>{if(s===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const s=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...o],s),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,s=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,o=c,s=r)}}),{minDist:n,segIndex:s,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let i=!0;for(let r=n;r<t.length;r++)if(i){const c=[];c.push([e.lng,e.lat]);for(let a=o+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),i=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,o=i)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let i=o+1;i<t.length;i++)s.push(t[i]);return s}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],s=e[n+1],i=this.calculateRangeRoute(o,s,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(i),s.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,s=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,d);o>=u&&(o=u,s=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<o||i===o&&s===0?t.unshift(e):r<o||r===o&&s===t.length-2?t.push(e):t.splice(s+1,0,e):i===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],s=e[n];if(n===1&&t.push(o),s.gcToPrevious){const i=this.interpolateCoordinates(o,s,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const a=c.map(d=>g.point(d));o.push(...a)}const s=g.featureCollection(o),i=g.nearestPoint(n,s),r=g.getCoord(i);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const s=t[o],i=t[o+1];if(this.calculateDistance(e,s)===0){n=o;break}if(this.calculateDistance(e,i)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var h;const s=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((f,M)=>{if(c)r.push(f);else{const m=[];let T;for(let D=0;D<f.length;D++)if(u)m.push(f[D]);else{T={lng:f[D][0],lat:f[D][1]};const P=this.calculateDistance(e,T,!0,8,o);if(a+=P,a<t)d+=P,i.push(T),e=T;else{if(d=t,a===t)u=T,m.push([u.lng,u.lat]);else{const p=a-t,N=this.calculateBearing(T,e);u=this.calculateCoordinate(T,N,p,o),m.push([u.lng,u.lat]),m.push([T.lng,T.lat])}c=!0}}m.length&&r.push(m),M===n.length-1&&!u&&(u=T)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((h=r[0])==null?void 0:h.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),s=g.point([o,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),h=l.roundPrecision(d[1],6);return{lng:u,lat:h,inline:!(u===i&&h===t.lat)&&!(u===r&&h===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,s;return e.forEach(i=>{i.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(o,c,!0);a&&a>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),s=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e)});for(let o=1;o<t.length;o++){const s=t[o-1],i=t[o];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let o=1;o<e.length;o++){const s=e[o-1],i=e[o];i.gcToPrevious?(s.bearing=this.calculateBearing(s,i,!1),i.distanceFromPrevious=this.calculateDistance(s,i,!1)):(s.bearing=this.calculateBearing(s,i,!0),i.distanceFromPrevious=this.calculateDistance(s,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const i of s)t.push(i);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let S;try{S=O.getLogger("vessel")}catch{}finally{}class W{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const s=(n=o.history)==null?void 0:n[0];for(const i of o.forecasts){const r=[],c=y(i.date).utc(),a=`${o.name}-${i.model}`;if(s){const d=y(s.updated).utc(),u=g.point([s.lng,s.lat],{model:i.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const h=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:o.name,date:h.format(),hour:Number(d),format:h.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:a,type:"forecast"});t.features.push(d)}}}if(o.history){const s=[];for(const r of o.history){const c=y(r.updated).utc(),a=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const i=o.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:o.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,i,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,u=a.properties.model,h=a.properties.showCircle,f=y(a.properties.date).utc();let M=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const m=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(P=>P.geometry.type==="Point"&&P.properties.type==="forecast"&&P.properties.category===`${d}-${u}`);let T,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;T=this.pickIndex(m,D),T<=m.length-1;){if(T>0){const P=m[T],p=T===0?void 0:m[T-1],N=(M/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(P.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),E=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],P.geometry.coordinates[0],N),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],P.geometry.coordinates[1],N),A=g.point([E,F],{name:d,model:u,category:P==null?void 0:P.properties.category,date:D.format(),format:D.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,P.properties.gusts,N),hour:this.computeNumber(p==null?void 0:p.properties.hour,P.properties.hour,N),movement:this.computeNumber(p==null?void 0:p.properties.movement,P.properties.movement,N),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,P.properties.pressure,N),wind:this.computeNumber(p==null?void 0:p.properties.wind,P.properties.wind,N),type:"forecast",showCircle:h});o.push(A)}M+=t*60,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=Math.abs(a-d);let h=0;u<180?h=u+90:u>=180&&(h=u-90);const f=v.calculateCoordinate(s,h,n);return S==null||S.info("[%s] the right tangent position: %j",o.requestId,{from:e,t1:s,t2:i,radius:n,bearing1:a,bearing2:d,right:f}),{at:f,t1:s,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=v.calculateDistance(e,s);return{at:v.calculateCoordinate(s,a-d+180,n<u?n:u),t1:s,t2:i,hr:Number(r),hours:c}}else return S==null||S.info("[%s] no need drift: %j",o.requestId,{from:e,t1:s,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var d,u,h,f,M;let o={};(d=e.forecasts)==null||d.forEach(m=>{o={...m.hours,...o}});const s=((u=e==null?void 0:e.history)==null?void 0:u[0])||(o==null?void 0:o[(h=Object.keys(o))==null?void 0:h[0]]);S==null||S.info("[%s] the first tropical center: %j",n.requestId,s);let i=(f=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);i||(i=(M=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:M.at(-1));const r=o==null?void 0:o[i||-1];S==null||S.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(o||{}).filter(m=>Number(m)<=Number(i)),a={0:s};for(const m of c)a[m]=o[m];return{t1:s,t2:r,hr:i,hours:a}}static pickIndex(e,t){let n=0;for(const o of e){if(y(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const s in e)o[s]=this.computeNumber(e[s],t[s],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=v,C.LngLatHelper=l,C.TropicalHelper=W,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
1
+ (function(C,R){typeof exports=="object"&&typeof module<"u"?R(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],R):(C=typeof globalThis<"u"?globalThis:C||self,R(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,R,y,B,$){"use strict";function k(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const g=k(R);function j(b){return b&&b.__esModule&&Object.prototype.hasOwnProperty.call(b,"default")?b.default:b}class x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(b=>{x.prototype[b.toLowerCase()]=()=>{},x.prototype[`is${b}Enabled`]=()=>!1});const I=(()=>{try{return require("log4js")}catch{return null}})();var L={getLogger:I?I.getLogger:()=>new x};const O=j(L);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),o=y().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,s=Number(o.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${o}E`:s<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${s>0?"E":"W"}`:e=`${o}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${s}`}}class v{static calculateBearing(e,t,n=!0,o=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(s.features[0],s.features[1]):i=g.bearing(s.features[0],s.features[1]),i<0&&(i+=360),l.roundPrecision(i,o)}static calculateDistance(e,t,n=!0,o=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:s}):r=g.distance(i.features[0],i.features[1],{units:s}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,s;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&s&&(o+=this.calculateDistance(s,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};o+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",s=!0){const i=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(i,n,t,{units:o}):r=g.destination(i,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,s=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let s,i;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([s,e[r].lat]);const c=s-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const h=g.lineIntersect(d,u);let f;if(h.features.length){const M=g.getCoord(h.features[0]);f=l.roundPrecision(M[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),o.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),o.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((s,i)=>(s.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&s.push(i),s),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,s=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},h={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,h);n>f&&(n=f,s=d,o=a,i=this.calculateDistance(u,e),r=this.calculateDistance(h,e))}}),i!==0&&r!==0?t[o].splice(s+1,0,[e.lng,e.lat]):i===0?t[o].splice(s,1,[e.lng,e.lat]):r===0&&t[o].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=v.convertRouteToCoordinates(t);return n.push(e),v.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=v.convertRouteToCoordinates(t);return n.unshift(e),v.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let s=0;return n.forEach(i=>{if(s===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const s=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...o],s),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,s=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,o=c,s=r)}}),{minDist:n,segIndex:s,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let i=!0;for(let r=n;r<t.length;r++)if(i){const c=[];c.push([e.lng,e.lat]);for(let a=o+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),i=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,o=i)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let i=o+1;i<t.length;i++)s.push(t[i]);return s}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],s=e[n+1],i=this.calculateRangeRoute(o,s,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(i),s.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,s=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,d);o>=u&&(o=u,s=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<o||i===o&&s===0?t.unshift(e):r<o||r===o&&s===t.length-2?t.push(e):t.splice(s+1,0,e):i===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],s=e[n];if(n===1&&t.push(o),s.gcToPrevious){const i=this.interpolateCoordinates(o,s,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const a=c.map(d=>g.point(d));o.push(...a)}const s=g.featureCollection(o),i=g.nearestPoint(n,s),r=g.getCoord(i);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const s=t[o],i=t[o+1];if(this.calculateDistance(e,s)===0){n=o;break}if(this.calculateDistance(e,i)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var h;const s=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((f,M)=>{if(c)r.push(f);else{const m=[];let P;for(let D=0;D<f.length;D++)if(u)m.push(f[D]);else{P={lng:f[D][0],lat:f[D][1]};const T=this.calculateDistance(e,P,!0,8,o);if(a+=T,a<t)d+=T,i.push(P),e=P;else{if(d=t,a===t)u=P,m.push([u.lng,u.lat]);else{const p=a-t,N=this.calculateBearing(P,e);u=this.calculateCoordinate(P,N,p,o),m.push([u.lng,u.lat]),m.push([P.lng,P.lat])}c=!0}}m.length&&r.push(m),M===n.length-1&&!u&&(u=P)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((h=r[0])==null?void 0:h.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),s=g.point([o,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),h=l.roundPrecision(d[1],6);return{lng:u,lat:h,inline:!(u===i&&h===t.lat)&&!(u===r&&h===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,s;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(o,c,!0);a&&a>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),s=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e,!0)});for(let o=1;o<t.length;o++){const s=t[o-1],i=t[o];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let o=1;o<e.length;o++){const s=e[o-1],i=e[o];i.gcToPrevious?(s.bearing=this.calculateBearing(s,i,!1),i.distanceFromPrevious=this.calculateDistance(s,i,!1)):(s.bearing=this.calculateBearing(s,i,!0),i.distanceFromPrevious=this.calculateDistance(s,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const i of s)t.push(i);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let S;try{S=O.getLogger("vessel")}catch{}finally{}class W{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const s=(n=o.history)==null?void 0:n[0];for(const i of o.forecasts){const r=[],c=y(i.date).utc(),a=`${o.name}-${i.model}`;if(s){const d=y(s.updated).utc(),u=g.point([s.lng,s.lat],{model:i.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const h=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:o.name,date:h.format(),hour:Number(d),format:h.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:a,type:"forecast"});t.features.push(d)}}}if(o.history){const s=[];for(const r of o.history){const c=y(r.updated).utc(),a=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const i=o.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:o.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,i,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,u=a.properties.model,h=a.properties.showCircle,f=y(a.properties.date).utc();let M=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const m=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(T=>T.geometry.type==="Point"&&T.properties.type==="forecast"&&T.properties.category===`${d}-${u}`);let P,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(m,D),P<=m.length-1;){if(P>0){const T=m[P],p=P===0?void 0:m[P-1],N=(M/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(T.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),E=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],T.geometry.coordinates[0],N),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],T.geometry.coordinates[1],N),A=g.point([E,F],{name:d,model:u,category:T==null?void 0:T.properties.category,date:D.format(),format:D.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,T.properties.gusts,N),hour:this.computeNumber(p==null?void 0:p.properties.hour,T.properties.hour,N),movement:this.computeNumber(p==null?void 0:p.properties.movement,T.properties.movement,N),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,T.properties.pressure,N),wind:this.computeNumber(p==null?void 0:p.properties.wind,T.properties.wind,N),type:"forecast",showCircle:h});o.push(A)}M+=t*60,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=Math.abs(a-d);let h=0;u<180?h=u+90:u>=180&&(h=u-90);const f=v.calculateCoordinate(s,h,n);return S==null||S.info("[%s] the right tangent position: %j",o.requestId,{from:e,t1:s,t2:i,radius:n,bearing1:a,bearing2:d,right:f}),{at:f,t1:s,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=v.calculateDistance(e,s);return{at:v.calculateCoordinate(s,a-d+180,n<u?n:u),t1:s,t2:i,hr:Number(r),hours:c}}else return S==null||S.info("[%s] no need drift: %j",o.requestId,{from:e,t1:s,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var d,u,h,f,M;let o={};(d=e.forecasts)==null||d.forEach(m=>{o={...m.hours,...o}});const s=((u=e==null?void 0:e.history)==null?void 0:u[0])||(o==null?void 0:o[(h=Object.keys(o))==null?void 0:h[0]]);S==null||S.info("[%s] the first tropical center: %j",n.requestId,s);let i=(f=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);i||(i=(M=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:M.at(-1));const r=o==null?void 0:o[i||-1];S==null||S.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(o||{}).filter(m=>Number(m)<=Number(i)),a={0:s};for(const m of c)a[m]=o[m];return{t1:s,t2:r,hr:i,hours:a}}static pickIndex(e,t){let n=0;for(const o of e){if(y(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const s in e)o[s]=this.computeNumber(e[s],t[s],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=v,C.LngLatHelper=l,C.TropicalHelper=W,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "1.2.9",
4
+ "version": "1.3.1",
5
5
  "description": "idm plugin for geo",
6
6
  "type": "module",
7
7
  "keywords": [