@idm-plugin/geo 1.2.0 → 1.2.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
@@ -1,9 +1,9 @@
1
1
  import * as g from "@turf/turf";
2
- import D from "moment";
2
+ import N from "moment";
3
3
  import "moment-timezone";
4
4
  import E from "tz-lookup";
5
- function F(S) {
6
- return S && S.__esModule && Object.prototype.hasOwnProperty.call(S, "default") ? S.default : S;
5
+ function F(C) {
6
+ return C && C.__esModule && Object.prototype.hasOwnProperty.call(C, "default") ? C.default : C;
7
7
  }
8
8
  class x {
9
9
  log() {
@@ -18,9 +18,9 @@ class x {
18
18
  clearContext() {
19
19
  }
20
20
  }
21
- ["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((S) => {
22
- x.prototype[S.toLowerCase()] = () => {
23
- }, x.prototype[`is${S}Enabled`] = () => !1;
21
+ ["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((C) => {
22
+ x.prototype[C.toLowerCase()] = () => {
23
+ }, x.prototype[`is${C}Enabled`] = () => !1;
24
24
  });
25
25
  const L = () => {
26
26
  try {
@@ -40,7 +40,7 @@ class l {
40
40
  * @param lat
41
41
  */
42
42
  static guessTimeZoneOffset(e, t) {
43
- const n = E(t, e), o = D().tz(n).utcOffset();
43
+ const n = E(t, e), o = N().tz(n).utcOffset();
44
44
  return this.roundPrecision(o / 60, 1);
45
45
  }
46
46
  /**
@@ -56,12 +56,12 @@ class l {
56
56
  e = l.convertToStdLng(e, t);
57
57
  let o = "E";
58
58
  e < 0 && (o = "W"), e = Math.abs(e), n = n.toUpperCase();
59
- let i = e * 3600, s, r, c, a, d, u;
60
- s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), d = i / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, t).toString().padStart(3, "0") : u = l.padNumber(d, 3, 2);
61
- const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${o}`;
59
+ let i = e * 3600, s, r, c, a, u, d;
60
+ s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), u = i / 3600, n.indexOf("M") !== -1 ? d = l.roundPrecision(u, t).toString().padStart(3, "0") : d = l.padNumber(u, 3, 2);
61
+ const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, d)}${o}`;
62
62
  return {
63
63
  direction: o,
64
- degree: l.roundPrecision(d, t),
64
+ degree: l.roundPrecision(u, t),
65
65
  minute: l.roundPrecision(c, t),
66
66
  second: l.roundPrecision(s, t),
67
67
  pretty: p
@@ -77,12 +77,12 @@ class l {
77
77
  e = e % 180;
78
78
  let o = "N";
79
79
  e < 0 && (o = "S"), e = Math.abs(e), n = n.toUpperCase();
80
- let i = e * 3600, s, r, c, a, d, u;
81
- s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), d = i / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, t).toString().padStart(2, "0") : u = l.padNumber(d, 2, 2);
82
- const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${o}`;
80
+ let i = e * 3600, s, r, c, a, u, d;
81
+ s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), u = i / 3600, n.indexOf("M") !== -1 ? d = l.roundPrecision(u, t).toString().padStart(2, "0") : d = l.padNumber(u, 2, 2);
82
+ const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, d)}${o}`;
83
83
  return {
84
84
  direction: o,
85
- degree: l.roundPrecision(d, t),
85
+ degree: l.roundPrecision(u, t),
86
86
  minute: l.roundPrecision(c, t),
87
87
  second: l.roundPrecision(s, t),
88
88
  pretty: p
@@ -182,7 +182,7 @@ class l {
182
182
  return `${o}.${i}`;
183
183
  }
184
184
  }
185
- class v {
185
+ class S {
186
186
  /**
187
187
  * 计算方位角
188
188
  * @param from 坐标 {lng, lat}
@@ -261,9 +261,9 @@ class v {
261
261
  static interpolateCoordinates(e, t, n, o = !0, i = !0, s = "nauticalmiles") {
262
262
  const r = [], c = this.calculateBearing(e, t, !1), a = this.calculateDistance(e, t, !1, 8, s);
263
263
  o && r.push({ lng: e.lng, lat: e.lat });
264
- let d = 0;
265
- for (; d < a; )
266
- d += n, d < a && r.push(this.calculateCoordinate(e, c, d, s, !1));
264
+ let u = 0;
265
+ for (; u < a; )
266
+ u += n, u < a && r.push(this.calculateCoordinate(e, c, u, s, !1));
267
267
  return i && r.push({ lng: t.lng, lat: t.lat }), r;
268
268
  }
269
269
  /**
@@ -292,16 +292,16 @@ class v {
292
292
  [i, e[r].lat],
293
293
  [s, e[r + 1].lat]
294
294
  ]);
295
- let d, u;
296
- t ? (d = g.lineString(a), u = g.lineString([
295
+ let u, d;
296
+ t ? (u = g.lineString(a), d = g.lineString([
297
297
  [c > 0 ? 180 : -180, 89],
298
298
  [c > 0 ? 180 : -180, -89]
299
- ])) : (d = g.greatCircle(a[0], a[1]), u = g.greatCircle([c > 0 ? 180 : -180, 89], [c > 0 ? 180 : -180, -89]));
300
- const p = g.lineIntersect(d, u);
299
+ ])) : (u = g.greatCircle(a[0], a[1]), d = g.greatCircle([c > 0 ? 180 : -180, 89], [c > 0 ? 180 : -180, -89]));
300
+ const p = g.lineIntersect(u, d);
301
301
  let f;
302
302
  if (p.features.length) {
303
- const C = g.getCoord(p.features[0]);
304
- f = l.roundPrecision(C[1], 8);
303
+ const M = g.getCoord(p.features[0]);
304
+ f = l.roundPrecision(M[1], 8);
305
305
  } else
306
306
  f = e[r].lat;
307
307
  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]));
@@ -367,9 +367,9 @@ class v {
367
367
  e.lng = l.convertToStdLng(e.lng, 8);
368
368
  let n = Number.MAX_VALUE, o = 0, i = 0, s, r;
369
369
  return t.forEach((c, a) => {
370
- for (let d = 0; d < c.length - 1; d++) {
371
- const u = { lng: c[d][0], lat: c[d][1] }, p = { lng: c[d + 1][0], lat: c[d + 1][1] }, f = this.calculatePointToLineDistance(e, u, p);
372
- n > f && (n = f, i = d, o = a, s = this.calculateDistance(u, e), r = this.calculateDistance(p, e));
370
+ for (let u = 0; u < c.length - 1; u++) {
371
+ const d = { lng: c[u][0], lat: c[u][1] }, p = { lng: c[u + 1][0], lat: c[u + 1][1] }, f = this.calculatePointToLineDistance(e, d, p);
372
+ n > f && (n = f, i = u, o = a, s = this.calculateDistance(d, e), r = this.calculateDistance(p, e));
373
373
  }
374
374
  }), s !== 0 && r !== 0 ? t[o].splice(i + 1, 0, [e.lng, e.lat]) : s === 0 ? t[o].splice(i, 1, [e.lng, e.lat]) : r === 0 && t[o].splice(i + 1, 1, [e.lng, e.lat]), t;
375
375
  }
@@ -380,8 +380,8 @@ class v {
380
380
  */
381
381
  static appendCoordinateToRoute(e, t) {
382
382
  e.lng = l.convertToStdLng(e.lng, 8);
383
- const n = v.convertRouteToCoordinates(t);
384
- return n.push(e), v.divideAccordingToLng(n);
383
+ const n = S.convertRouteToCoordinates(t);
384
+ return n.push(e), S.divideAccordingToLng(n);
385
385
  }
386
386
  /**
387
387
  * 向route头加1个坐标
@@ -389,8 +389,8 @@ class v {
389
389
  * @param route
390
390
  */
391
391
  static unshiftCoordinateToRoute(e, t) {
392
- const n = v.convertRouteToCoordinates(t);
393
- return n.unshift(e), v.divideAccordingToLng(n);
392
+ const n = S.convertRouteToCoordinates(t);
393
+ return n.unshift(e), S.divideAccordingToLng(n);
394
394
  }
395
395
  /**
396
396
  * 合并多个waypoints进航线
@@ -437,11 +437,11 @@ class v {
437
437
  */
438
438
  static calculateRangeWaypoints(e, t, n, o = []) {
439
439
  const i = this.convertRouteToCoordinates(n, 0), s = this.mergeCoordinatesToWaypoints([e, t, ...o], i), r = s.findIndex(
440
- (d) => l.roundPrecision(e.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(d.lat, 8)
440
+ (u) => l.roundPrecision(e.lng, 8) === l.roundPrecision(u.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(u.lat, 8)
441
441
  ), c = s.findIndex(
442
- (d) => l.roundPrecision(t.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(t.lat, 8) === l.roundPrecision(d.lat, 8)
442
+ (u) => l.roundPrecision(t.lng, 8) === l.roundPrecision(u.lng, 8) && l.roundPrecision(t.lat, 8) === l.roundPrecision(u.lat, 8)
443
443
  );
444
- return s.filter((d, u) => u >= r && u <= c);
444
+ return s.filter((u, d) => d >= r && d <= c);
445
445
  }
446
446
  /**
447
447
  * 计算坐标到航路上的最短距离
@@ -452,8 +452,8 @@ class v {
452
452
  let n = Number.MAX_VALUE, o = 0, i = 0;
453
453
  return t.forEach((s, r) => {
454
454
  for (let c = 0; c < s.length - 1; c++) {
455
- const a = { lng: s[c][0], lat: s[c][1] }, d = { lng: s[c + 1][0], lat: s[c + 1][1] }, u = this.calculatePointToLineDistance(e, a, d);
456
- n > u && (n = u, o = c, i = r);
455
+ const a = { lng: s[c][0], lat: s[c][1] }, u = { lng: s[c + 1][0], lat: s[c + 1][1] }, d = this.calculatePointToLineDistance(e, a, u);
456
+ n > d && (n = d, o = c, i = r);
457
457
  }
458
458
  }), { minDist: n, segIndex: i, minIndex: o };
459
459
  }
@@ -492,7 +492,7 @@ class v {
492
492
  if (this.calculateDistance(e, r) === 0)
493
493
  return t;
494
494
  if (this.calculateDistance(e, c) === 0)
495
- return t.filter((d, u) => u > 0);
495
+ return t.filter((u, d) => d > 0);
496
496
  const a = this.calculatePointToLineDistance(e, r, c);
497
497
  n > a && (n = a, o = s);
498
498
  }
@@ -558,8 +558,8 @@ class v {
558
558
  e.lng = l.convertToStdLng(e.lng, 8);
559
559
  let o = Number.MAX_VALUE, i = 0, s = 0, r = 0;
560
560
  for (let c = 0; c < t.length - 1; c++) {
561
- 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);
562
- o >= u && (o = u, i = c, s = this.calculateDistance(a, e, !1, 6), r = this.calculateDistance(d, e, !1, 6));
561
+ const a = { lng: t[c].lng, lat: t[c].lat }, u = { lng: t[c + 1].lng, lat: t[c + 1].lat }, d = this.calculatePointToLineDistance(e, a, u);
562
+ o >= d && (o = d, i = c, s = this.calculateDistance(a, e, !1, 6), r = this.calculateDistance(u, e, !1, 6));
563
563
  }
564
564
  return s !== 0 && r !== 0 ? s < o || s === o && i === 0 ? t.unshift(e) : r < o || r === o && i === t.length - 2 ? t.push(e) : t.splice(i + 1, 0, e) : s === 0 ? n && t.splice(i, 1, e) : r === 0 && n && t.splice(i + 1, 1, e), t.map((c) => (c.lng = l.convertToStdLng(c.lng), c));
565
565
  }
@@ -588,7 +588,7 @@ class v {
588
588
  static nearestCoordinateInRoute(e, t) {
589
589
  const n = g.point([e.lng, e.lat]), o = [];
590
590
  for (const c of t) {
591
- const a = c.map((d) => g.point(d));
591
+ const a = c.map((u) => g.point(u));
592
592
  o.push(...a);
593
593
  }
594
594
  const i = g.featureCollection(o), s = g.nearestPoint(n, i), r = g.getCoord(s);
@@ -626,40 +626,40 @@ class v {
626
626
  static calculateNextCoordinateAlongRoute(e, t, n, o = "nauticalmiles") {
627
627
  var p;
628
628
  const i = e.speed || 12, s = [];
629
- let r = [], c = !1, a = 0, d = 0, u;
630
- if (t && n.length ? (s.push(e), n.forEach((f, C) => {
629
+ let r = [], c = !1, a = 0, u = 0, d;
630
+ if (t && n.length ? (s.push(e), n.forEach((f, M) => {
631
631
  if (c)
632
632
  r.push(f);
633
633
  else {
634
634
  const T = [];
635
635
  let P;
636
- for (let m = 0; m < f.length; m++)
637
- if (u)
638
- T.push(f[m]);
636
+ for (let b = 0; b < f.length; b++)
637
+ if (d)
638
+ T.push(f[b]);
639
639
  else {
640
- P = { lng: f[m][0], lat: f[m][1] };
641
- const h = this.calculateDistance(e, P, !0, 8, o);
642
- if (a += h, a < t)
643
- d += h, s.push(P), e = P;
640
+ P = { lng: f[b][0], lat: f[b][1] };
641
+ const m = this.calculateDistance(e, P, !0, 8, o);
642
+ if (a += m, a < t)
643
+ u += m, s.push(P), e = P;
644
644
  else {
645
- if (d = t, a === t)
646
- u = P, T.push([u.lng, u.lat]);
645
+ if (u = t, a === t)
646
+ d = P, T.push([d.lng, d.lat]);
647
647
  else {
648
- const b = a - t, R = this.calculateBearing(P, e);
649
- u = this.calculateCoordinate(P, R, b, o), T.push([u.lng, u.lat]), T.push([P.lng, P.lat]);
648
+ const h = a - t, v = this.calculateBearing(P, e);
649
+ d = this.calculateCoordinate(P, v, h, o), T.push([d.lng, d.lat]), T.push([P.lng, P.lat]);
650
650
  }
651
651
  c = !0;
652
652
  }
653
653
  }
654
- T.length && r.push(T), C === n.length - 1 && !u && (u = P);
654
+ T.length && r.push(T), M === n.length - 1 && !d && (d = P);
655
655
  }
656
- })) : (r = n, u = { ...e }), u)
657
- if (s.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / i * 1e4) / 1e4, ((p = r[0]) == null ? void 0 : p.length) > 1) {
656
+ })) : (r = n, d = { ...e }), d)
657
+ if (s.push(d), d.distanceFromPrevious = u, d.hourFromPrevious = Math.round(u / i * 1e4) / 1e4, ((p = r[0]) == null ? void 0 : p.length) > 1) {
658
658
  const f = { lng: r[0][1][0], lat: r[0][1][1] };
659
- u.bearing = this.calculateBearing(u, f);
659
+ d.bearing = this.calculateBearing(d, f);
660
660
  } else
661
- u.bearing = 0;
662
- return { coordinate: u, nextRoute: r, prevRoute: s };
661
+ d.bearing = 0;
662
+ return { coordinate: d, nextRoute: r, prevRoute: s };
663
663
  }
664
664
  /**
665
665
  * 返回最近点及其是否为垂足(最近点不是起点或终点)
@@ -671,8 +671,8 @@ class v {
671
671
  const o = l.convertToStdLng(e.lng, 6), i = g.point([o, e.lat]), s = l.convertToStdLng(t.lng, 6), r = l.convertToStdLng(n.lng, 6), c = g.lineString([
672
672
  [s, t.lat],
673
673
  [r, n.lat]
674
- ]), a = g.nearestPointOnLine(c, i), d = g.getCoord(a), u = l.roundPrecision(d[0], 6), p = l.roundPrecision(d[1], 6);
675
- return { lng: u, lat: p, inline: !(u === s && p === t.lat) && !(u === r && p === n.lat) };
674
+ ]), a = g.nearestPointOnLine(c, i), u = g.getCoord(a), d = l.roundPrecision(u[0], 6), p = l.roundPrecision(u[1], 6);
675
+ return { lng: d, lat: p, inline: !(d === s && p === t.lat) && !(d === r && p === n.lat) };
676
676
  }
677
677
  /**
678
678
  * 将route转coordinate
@@ -775,7 +775,7 @@ class v {
775
775
  return this.calculateBBox(t);
776
776
  }
777
777
  }
778
- const N = j.getLogger("vessel");
778
+ const R = j.getLogger("vessel");
779
779
  class q {
780
780
  /**
781
781
  * 将原始数据转换为geojson
@@ -788,41 +788,41 @@ class q {
788
788
  if (o.forecasts) {
789
789
  const i = (n = o.history) == null ? void 0 : n[0];
790
790
  for (const s of o.forecasts) {
791
- const r = [], c = D(s.date).utc(), a = `${o.name}-${s.model}`;
791
+ const r = [], c = N(s.date).utc(), a = `${o.name}-${s.model}`;
792
792
  if (i) {
793
- const d = D(i.updated).utc(), u = g.point([i.lng, i.lat], {
793
+ const u = N(i.updated).utc(), d = g.point([i.lng, i.lat], {
794
794
  model: s.model,
795
795
  name: o.name,
796
- date: d.format(),
796
+ date: u.format(),
797
797
  hour: 0,
798
- format: d.format("MMM-DD/HHmm[Z]"),
798
+ format: u.format("MMM-DD/HHmm[Z]"),
799
799
  pressure: i.pressure > 1e4 ? l.roundPrecision(i.pressure / 100, 0) : l.roundPrecision(i.pressure, 0),
800
800
  wind: { kts: i.kts, spd: i.speed || i.spd },
801
801
  category: a,
802
802
  type: "forecast"
803
803
  });
804
- t.features.push(u), r.push(u.geometry.coordinates);
804
+ t.features.push(d), r.push(d.geometry.coordinates);
805
805
  }
806
- for (const d in s == null ? void 0 : s.hours) {
807
- const u = s.hours[d];
808
- u.wind.spd = u.wind.spd || u.wind.speed;
809
- const p = c.clone().add(Number(d), "hour"), f = g.point([u.lng, u.lat], {
806
+ for (const u in s == null ? void 0 : s.hours) {
807
+ const d = s.hours[u];
808
+ d.wind.spd = d.wind.spd || d.wind.speed;
809
+ const p = c.clone().add(Number(u), "hour"), f = g.point([d.lng, d.lat], {
810
810
  model: s.model,
811
811
  name: o.name,
812
812
  date: p.format(),
813
- hour: Number(d),
813
+ hour: Number(u),
814
814
  format: p.format("MMM-DD/HHmm[Z]"),
815
- pressure: u.pressure > 1e4 ? l.roundPrecision(u.pressure / 100, 0) : l.roundPrecision(u.pressure, 0),
816
- gusts: u.gusts,
817
- wind: u.wind || {},
818
- movement: u.movement,
815
+ pressure: d.pressure > 1e4 ? l.roundPrecision(d.pressure / 100, 0) : l.roundPrecision(d.pressure, 0),
816
+ gusts: d.gusts,
817
+ wind: d.wind || {},
818
+ movement: d.movement,
819
819
  category: a,
820
820
  type: "forecast"
821
821
  });
822
822
  t.features.push(f), r.push(f.geometry.coordinates);
823
823
  }
824
824
  if ((r == null ? void 0 : r.length) > 1) {
825
- const d = g.lineString(l.convertToMonotonicLng2(r), {
825
+ const u = g.lineString(l.convertToMonotonicLng2(r), {
826
826
  date: s.date,
827
827
  id: o.id || o.name,
828
828
  model: s.model,
@@ -830,14 +830,14 @@ class q {
830
830
  category: a,
831
831
  type: "forecast"
832
832
  });
833
- t.features.push(d);
833
+ t.features.push(u);
834
834
  }
835
835
  }
836
836
  }
837
837
  if (o.history) {
838
838
  const i = [];
839
839
  for (const r of o.history) {
840
- const c = D(r.updated).utc(), a = g.point([r.lng, r.lat], {
840
+ const c = N(r.updated).utc(), a = g.point([r.lng, r.lat], {
841
841
  name: o.name,
842
842
  date: c.format(),
843
843
  format: c.format("MMM-DD/HHmm[Z]"),
@@ -875,34 +875,34 @@ class q {
875
875
  * @param step
876
876
  */
877
877
  static interpolate(e, t = 3) {
878
- var i, s, r, c;
879
- const n = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), o = [];
880
- for (const a of n) {
881
- const d = a.properties.name, u = a.properties.model, p = D(a.properties.date).utc();
882
- let f = t * 60 - (p.get("hour") * 60 + p.get("minute")) % (t * 60);
883
- const C = (s = e == null ? void 0 : e.data) == null ? void 0 : s.features.filter(
884
- (m) => m.geometry.type === "Point" && m.properties.type === "forecast" && m.properties.category === `${d}-${u}`
878
+ var i, s, r, c, a;
879
+ const n = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((u) => u.geometry.type === "LineString" && u.properties.type === "forecast"), o = [];
880
+ for (const u of n) {
881
+ const d = u.properties.name, p = u.properties.model, f = N(u.properties.date).utc();
882
+ let M = t * 60 - (f.get("hour") * 60 + f.get("minute")) % (t * 60);
883
+ const T = (s = e == null ? void 0 : e.data) == null ? void 0 : s.features.filter(
884
+ (m) => m.geometry.type === "Point" && m.properties.type === "forecast" && m.properties.category === `${d}-${p}`
885
885
  );
886
- let T, P = p.clone().add(f, "minute").set({ minute: 0, second: 0, millisecond: 0 });
887
- for (; T = this.pickIndex(C, P), T <= C.length - 1; ) {
888
- if (T > 0) {
889
- const m = C[T], h = T === 0 ? void 0 : C[T - 1], b = (f / 60 - ((r = h == null ? void 0 : h.properties) == null ? void 0 : r.hour)) / (m.properties.hour - ((c = h == null ? void 0 : h.properties) == null ? void 0 : c.hour)), R = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[0], m.geometry.coordinates[0], b), y = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[1], m.geometry.coordinates[1], b), I = g.point([R, y], {
886
+ let P, b = f.clone().add(M, "minute").set({ minute: 0, second: 0, millisecond: 0 });
887
+ for (; P = this.pickIndex(T, b), P <= T.length - 1; ) {
888
+ if (P > 0) {
889
+ const m = T[P], h = P === 0 ? void 0 : T[P - 1], v = (M / 60 - ((r = h == null ? void 0 : h.properties) == null ? void 0 : r.hour)) / (m.properties.hour - ((c = h == null ? void 0 : h.properties) == null ? void 0 : c.hour)), y = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[0], m.geometry.coordinates[0], v), I = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[1], m.geometry.coordinates[1], v), D = g.point([y, I], {
890
890
  name: d,
891
- model: u,
891
+ model: p,
892
892
  category: m == null ? void 0 : m.properties.category,
893
- date: P.format(),
894
- format: P.format("MMM-DD/HHmm[Z]"),
895
- gusts: this.computeNumber(h == null ? void 0 : h.properties.gusts, m.properties.gusts, b),
896
- hour: this.computeNumber(h == null ? void 0 : h.properties.hour, m.properties.hour, b),
897
- movement: this.computeNumber(h == null ? void 0 : h.properties.movement, m.properties.movement, b),
898
- pressure: this.computeNumber(h == null ? void 0 : h.properties.pressure, m.properties.pressure, b),
899
- wind: this.computeNumber(h == null ? void 0 : h.properties.wind, m.properties.wind, b),
893
+ date: b.format(),
894
+ format: b.format("MMM-DD/HHmm[Z]"),
895
+ gusts: this.computeNumber(h == null ? void 0 : h.properties.gusts, m.properties.gusts, v),
896
+ hour: this.computeNumber(h == null ? void 0 : h.properties.hour, m.properties.hour, v),
897
+ movement: this.computeNumber(h == null ? void 0 : h.properties.movement, m.properties.movement, v),
898
+ pressure: this.computeNumber(h == null ? void 0 : h.properties.pressure, m.properties.pressure, v),
899
+ wind: this.computeNumber(h == null ? void 0 : h.properties.wind, m.properties.wind, v),
900
900
  type: "forecast",
901
- showCircle: a.showCircle
901
+ showCircle: (a = u == null ? void 0 : u.properties) == null ? void 0 : a.showCircle
902
902
  });
903
- o.push(I);
903
+ o.push(D);
904
904
  }
905
- f += t * 60, P = p.clone().add(f, "minute").set({ minute: 0, second: 0, millisecond: 0 });
905
+ M += t * 60, b = f.clone().add(M, "minute").set({ minute: 0, second: 0, millisecond: 0 });
906
906
  }
907
907
  }
908
908
  return o;
@@ -916,27 +916,27 @@ class q {
916
916
  * @param options
917
917
  */
918
918
  static diversionPassageAt(e, t, n, o, i = { requestId: "" }) {
919
- var d, u, p, f, C, T, P, m, h;
920
- const s = (u = (d = t == null ? void 0 : t.forecasts) == null ? void 0 : d[0]) == null ? void 0 : u.hours, r = ((p = t == null ? void 0 : t.history) == null ? void 0 : p[0]) || (s == null ? void 0 : s[(f = Object.keys(s)) == null ? void 0 : f[0]]);
921
- N.info("[%s] the first evasion point: %j", i.requestId, r);
922
- const c = (C = Object.keys(s || {}).filter((b) => Number(b) <= 24)) == null ? void 0 : C.at(-1), a = s == null ? void 0 : s[c || -1];
923
- if (N.info("[%s] the second evasion point in %s hrs: %j", i.requestId, c, r), r && a) {
924
- const b = v.calculateBearing(e, r), R = v.calculateBearing(r, a), y = v.calculateCoordinate(r, b - R + 90, n);
925
- N.info("[%s] the right tangent point: %j", i.requestId, { from: e, p1: r, p2: a, radius: n, bearing1: b, bearing2: R, right: y });
926
- const I = v.calculateBearing(e, y);
927
- let M = v.calculateCoordinate(e, I, o * Number(c));
928
- M.utc = D((P = (T = t == null ? void 0 : t.forecasts) == null ? void 0 : T[0]) == null ? void 0 : P.date).add(Number(c), "hours").utc().format(), N.info("[%s] the temp evasion point: %j", i.requestId, M);
929
- const $ = v.calculateDistance(M, a);
930
- return N.info("[%s] the distance(%d) between tmp & p2: %j - %j", i.requestId, $, M, a), $ < n && (M = v.calculateCoordinate(e, I, o * Number(c) / 2), M.utc = D((h = (m = t == null ? void 0 : t.forecasts) == null ? void 0 : m[0]) == null ? void 0 : h.date).add(Number(c) / 2, "hours").utc().format(), N.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j", i.requestId, M)), M;
919
+ var u, d, p, f, M, T, P, b, m;
920
+ const s = (d = (u = t == null ? void 0 : t.forecasts) == null ? void 0 : u[0]) == null ? void 0 : d.hours, r = ((p = t == null ? void 0 : t.history) == null ? void 0 : p[0]) || (s == null ? void 0 : s[(f = Object.keys(s)) == null ? void 0 : f[0]]);
921
+ R.info("[%s] the first evasion point: %j", i.requestId, r);
922
+ const c = (M = Object.keys(s || {}).filter((h) => Number(h) <= 24)) == null ? void 0 : M.at(-1), a = s == null ? void 0 : s[c || -1];
923
+ if (R.info("[%s] the second evasion point in %s hrs: %j", i.requestId, c, r), r && a) {
924
+ const h = S.calculateBearing(e, r), v = S.calculateBearing(r, a), y = S.calculateCoordinate(r, h - v + 90, n);
925
+ R.info("[%s] the right tangent point: %j", i.requestId, { from: e, p1: r, p2: a, radius: n, bearing1: h, bearing2: v, right: y });
926
+ const I = S.calculateBearing(e, y);
927
+ let D = S.calculateCoordinate(e, I, o * Number(c));
928
+ D.utc = N((P = (T = t == null ? void 0 : t.forecasts) == null ? void 0 : T[0]) == null ? void 0 : P.date).add(Number(c), "hours").utc().format(), R.info("[%s] the temp evasion point: %j", i.requestId, D);
929
+ const $ = S.calculateDistance(D, a);
930
+ return R.info("[%s] the distance(%d) between tmp & p2: %j - %j", i.requestId, $, D, a), $ < n && (D = S.calculateCoordinate(e, I, o * Number(c) / 2), D.utc = N((m = (b = t == null ? void 0 : t.forecasts) == null ? void 0 : b[0]) == null ? void 0 : m.date).add(Number(c) / 2, "hours").utc().format(), R.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j", i.requestId, D)), D;
931
931
  } else {
932
- N.info("[%s] no need evasion: %j", i.requestId, { from: e, p1: r, p2: a });
932
+ R.info("[%s] no need evasion: %j", i.requestId, { from: e, p1: r, p2: a });
933
933
  return;
934
934
  }
935
935
  }
936
936
  static pickIndex(e, t) {
937
937
  let n = 0;
938
938
  for (const o of e) {
939
- if (D(o.properties.date).isAfter(t))
939
+ if (N(o.properties.date).isAfter(t))
940
940
  return n === 0 ? -1 : n;
941
941
  n++;
942
942
  }
@@ -959,7 +959,7 @@ class q {
959
959
  }
960
960
  }
961
961
  export {
962
- v as LaneHelper,
962
+ S as LaneHelper,
963
963
  l as LngLatHelper,
964
964
  q as TropicalHelper
965
965
  };
@@ -1 +1 @@
1
- (function(C,I){typeof exports=="object"&&typeof module<"u"?I(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"],I):(C=typeof globalThis<"u"?globalThis:C||self,I(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,I,D,q,W){"use strict";function F(T){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const t in T)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(T,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>T[t]})}}return e.default=T,Object.freeze(e)}const g=F(I);function O(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(T=>{j.prototype[T.toLowerCase()]=()=>{},j.prototype[`is${T}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var E={getLogger:k?k.getLogger:()=>new j};const A=O(E);class l{static guessTimeZoneOffset(e,t){const n=W(t,e),o=D().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 i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(3,"0"):a=l.padNumber(d,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}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 i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(2,"0"):a=l.padNumber(d,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}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 i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>360&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(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 i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>90&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(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,i=Number(o.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${o}E`:i<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${i>0?"E":"W"}`:e=`${o}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${i}`}}class S{static calculateBearing(e,t,n=!0,o=4){const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=g.rhumbBearing(i.features[0],i.features[1]):s=g.bearing(i.features[0],i.features[1]),s<0&&(s+=360),l.roundPrecision(s,o)}static calculateDistance(e,t,n=!0,o=4,i="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(s.features[0],s.features[1],{units:i}):r=g.distance(s.features[0],s.features[1],{units:i}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,i;for(const s of e)for(let r=0;r<s.length-1;r++){const c={lng:s[r][0],lat:s[r][1]};r===0&&i&&(o+=this.calculateDistance(i,c,!0,t,n));const u={lng:s[r+1][0],lat:s[r+1][1]};o+=this.calculateDistance(c,u,!0,t,n),i=u}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",i=!0){const s=g.point([e.lng,e.lat]);let r;i?r=g.rhumbDestination(s,n,t,{units:o}):r=g.destination(s,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,i=!0,s="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),u=this.calculateDistance(e,t,!1,8,s);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<u;)d+=n,d<u&&r.push(this.calculateCoordinate(e,c,d,s,!1));return i&&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 i,s;for(let r=0;r<e.length-1;r++){i=l.convertToStdLng(e[r].lng,8),s=l.convertToStdLng(e[r+1].lng,8),n.push([i,e[r].lat]);const c=i-s;if(Math.abs(c)>180){const u=l.convertToMonotonicLng2([[i,e[r].lat],[s,e[r+1].lat]]);let d,a;t?(d=g.lineString(u),a=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(u[0],u[1]),a=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(d,a);let h;if(p.features.length){const M=g.getCoord(p.features[0]);h=l.roundPrecision(M[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),o.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),o.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([s,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((i,s)=>(i.findIndex(r=>r[0]===s[0]&&r[1]===s[1])===-1&&i.push(s),i),[]);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,i=0,s,r;return t.forEach((c,u)=>{for(let d=0;d<c.length-1;d++){const a={lng:c[d][0],lat:c[d][1]},p={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(e,a,p);n>h&&(n=h,i=d,o=u,s=this.calculateDistance(a,e),r=this.calculateDistance(p,e))}}),s!==0&&r!==0?t[o].splice(i+1,0,[e.lng,e.lat]):s===0?t[o].splice(i,1,[e.lng,e.lat]):r===0&&t[o].splice(i+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=S.convertRouteToCoordinates(t);return n.push(e),S.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=S.convertRouteToCoordinates(t);return n.unshift(e),S.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 i=0;return n.forEach(s=>{if(i===2)return;const r=[];for(const c of s){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),i===0&&r.push([e.lng,e.lat]),i=2;break}i===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(i=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const i=this.convertRouteToCoordinates(n,0),s=this.mergeCoordinatesToWaypoints([e,t,...o],i),r=s.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=s.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return s.filter((d,a)=>a>=r&&a<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,i=0;return t.forEach((s,r)=>{for(let c=0;c<s.length-1;c++){const u={lng:s[c][0],lat:s[c][1]},d={lng:s[c+1][0],lat:s[c+1][1]},a=this.calculatePointToLineDistance(e,u,d);n>a&&(n=a,o=c,i=r)}}),{minDist:n,segIndex:i,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let s=!0;for(let r=n;r<t.length;r++)if(s){const c=[];c.push([e.lng,e.lat]);for(let u=o+1;u<t[r].length;u++)e.lng===t[r][u][0]&&e.lat===t[r][u][1]||c.push(t[r][u]);i.push(c),s=!1}else i.push([...t[r]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let s=0;s<t.length-1;s++){const r=t[s],c=t[s+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,a)=>a>0);const u=this.calculatePointToLineDistance(e,r,c);n>u&&(n=u,o=s)}e.lng=l.convertToStdLng(e.lng);const i=[e];for(let s=o+1;s<t.length;s++)i.push(t[s]);return i}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 i=l.convertToMonotonicLng([t,n]);t=i[0],n=i[1];const s=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),s,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),s,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],i=e[n+1],s=this.calculateRangeRoute(o,i,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),i.distanceFromPrevious=this.calculateRouteDistance(s),i.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+i.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,i=0,s=0,r=0;for(let c=0;c<t.length-1;c++){const u={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},a=this.calculatePointToLineDistance(e,u,d);o>=a&&(o=a,i=c,s=this.calculateDistance(u,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return s!==0&&r!==0?s<o||s===o&&i===0?t.unshift(e):r<o||r===o&&i===t.length-2?t.push(e):t.splice(i+1,0,e):s===0?n&&t.splice(i,1,e):r===0&&n&&t.splice(i+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],i=e[n];if(n===1&&t.push(o),i.gcToPrevious){const s=this.interpolateCoordinates(o,i,200,!1,!0,"nauticalmiles");t.push(...s)}else t.push(i)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const u=c.map(d=>g.point(d));o.push(...u)}const i=g.featureCollection(o),s=g.nearestPoint(n,i),r=g.getCoord(s);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 i=t[o],s=t[o+1];if(this.calculateDistance(e,i)===0){n=o;break}if(this.calculateDistance(e,s)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var p;const i=e.speed||12,s=[];let r=[],c=!1,u=0,d=0,a;if(t&&n.length?(s.push(e),n.forEach((h,M)=>{if(c)r.push(h);else{const P=[];let b;for(let m=0;m<h.length;m++)if(a)P.push(h[m]);else{b={lng:h[m][0],lat:h[m][1]};const f=this.calculateDistance(e,b,!0,8,o);if(u+=f,u<t)d+=f,s.push(b),e=b;else{if(d=t,u===t)a=b,P.push([a.lng,a.lat]);else{const v=u-t,R=this.calculateBearing(b,e);a=this.calculateCoordinate(b,R,v,o),P.push([a.lng,a.lat]),P.push([b.lng,b.lat])}c=!0}}P.length&&r.push(P),M===n.length-1&&!a&&(a=b)}})):(r=n,a={...e}),a)if(s.push(a),a.distanceFromPrevious=d,a.hourFromPrevious=Math.round(d/i*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};a.bearing=this.calculateBearing(a,h)}else a.bearing=0;return{coordinate:a,nextRoute:r,prevRoute:s}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),i=g.point([o,e.lat]),s=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[s,t.lat],[r,n.lat]]),u=g.nearestPointOnLine(c,i),d=g.getCoord(u),a=l.roundPrecision(d[0],6),p=l.roundPrecision(d[1],6);return{lng:a,lat:p,inline:!(a===s&&p===t.lat)&&!(a===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,i;return e.forEach(s=>{s.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!i)n.push(c),i=c;else if(i.bearing===void 0)i.bearing=this.calculateBearing(i,c,!0);else{const u=this.calculateDistance(o,c,!0);u&&u>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),i=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 i=t[o-1],s=t[o];if(s.gcToPrevious){const r=e.findIndex(u=>u.lng===i.lng&&u.lat===i.lat),c=e.findIndex(u=>u.lng===s.lng&&u.lat===s.lat);for(let u=c-1;u>r;u--)e.splice(u,1)}}let n=0;for(let o=1;o<e.length;o++){const i=e[o-1],s=e[o];s.gcToPrevious?(i.bearing=this.calculateBearing(i,s,!1),s.distanceFromPrevious=this.calculateDistance(i,s,!1)):(i.bearing=this.calculateBearing(i,s,!0),s.distanceFromPrevious=this.calculateDistance(i,s,!0)),n=l.roundPrecision(n+s.distanceFromPrevious),s.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 s=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(s[0],8),lat:l.roundPrecision(s[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const i of e)for(const s of i)t.push(s);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)}}const y=A.getLogger("vessel");class B{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const i=(n=o.history)==null?void 0:n[0];for(const s of o.forecasts){const r=[],c=D(s.date).utc(),u=`${o.name}-${s.model}`;if(i){const d=D(i.updated).utc(),a=g.point([i.lng,i.lat],{model:s.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?l.roundPrecision(i.pressure/100,0):l.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:u,type:"forecast"});t.features.push(a),r.push(a.geometry.coordinates)}for(const d in s==null?void 0:s.hours){const a=s.hours[d];a.wind.spd=a.wind.spd||a.wind.speed;const p=c.clone().add(Number(d),"hour"),h=g.point([a.lng,a.lat],{model:s.model,name:o.name,date:p.format(),hour:Number(d),format:p.format("MMM-DD/HHmm[Z]"),pressure:a.pressure>1e4?l.roundPrecision(a.pressure/100,0):l.roundPrecision(a.pressure,0),gusts:a.gusts,wind:a.wind||{},movement:a.movement,category:u,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:s.date,id:o.id||o.name,model:s.model,name:o.name,category:u,type:"forecast"});t.features.push(d)}}}if(o.history){const i=[];for(const r of o.history){const c=D(r.updated).utc(),u=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(u),i.push(u.geometry.coordinates)}const s=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const r=g.lineString(l.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?l.roundPrecision((s==null?void 0:s.pressure)/100,0):l.roundPrecision(s==null?void 0:s.pressure,0),spd:(s==null?void 0:s.speed)||(s==null?void 0:s.spd),kts:s==null?void 0:s.kts,source:s==null?void 0:s.source,level:s==null?void 0:s.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var i,s,r,c;const n=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(u=>u.geometry.type==="LineString"&&u.properties.type==="forecast"),o=[];for(const u of n){const d=u.properties.name,a=u.properties.model,p=D(u.properties.date).utc();let h=t*60-(p.get("hour")*60+p.get("minute"))%(t*60);const M=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${d}-${a}`);let P,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(M,b),P<=M.length-1;){if(P>0){const m=M[P],f=P===0?void 0:M[P-1],v=(h/60-((r=f==null?void 0:f.properties)==null?void 0:r.hour))/(m.properties.hour-((c=f==null?void 0:f.properties)==null?void 0:c.hour)),R=this.computeNumber(f==null?void 0:f.geometry.coordinates[0],m.geometry.coordinates[0],v),x=this.computeNumber(f==null?void 0:f.geometry.coordinates[1],m.geometry.coordinates[1],v),$=g.point([R,x],{name:d,model:a,category:m==null?void 0:m.properties.category,date:b.format(),format:b.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(f==null?void 0:f.properties.gusts,m.properties.gusts,v),hour:this.computeNumber(f==null?void 0:f.properties.hour,m.properties.hour,v),movement:this.computeNumber(f==null?void 0:f.properties.movement,m.properties.movement,v),pressure:this.computeNumber(f==null?void 0:f.properties.pressure,m.properties.pressure,v),wind:this.computeNumber(f==null?void 0:f.properties.wind,m.properties.wind,v),type:"forecast",showCircle:u.showCircle});o.push($)}h+=t*60,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o,i={requestId:""}){var d,a,p,h,M,P,b,m,f;const s=(a=(d=t==null?void 0:t.forecasts)==null?void 0:d[0])==null?void 0:a.hours,r=((p=t==null?void 0:t.history)==null?void 0:p[0])||(s==null?void 0:s[(h=Object.keys(s))==null?void 0:h[0]]);y.info("[%s] the first evasion point: %j",i.requestId,r);const c=(M=Object.keys(s||{}).filter(v=>Number(v)<=24))==null?void 0:M.at(-1),u=s==null?void 0:s[c||-1];if(y.info("[%s] the second evasion point in %s hrs: %j",i.requestId,c,r),r&&u){const v=S.calculateBearing(e,r),R=S.calculateBearing(r,u),x=S.calculateCoordinate(r,v-R+90,n);y.info("[%s] the right tangent point: %j",i.requestId,{from:e,p1:r,p2:u,radius:n,bearing1:v,bearing2:R,right:x});const $=S.calculateBearing(e,x);let N=S.calculateCoordinate(e,$,o*Number(c));N.utc=D((b=(P=t==null?void 0:t.forecasts)==null?void 0:P[0])==null?void 0:b.date).add(Number(c),"hours").utc().format(),y.info("[%s] the temp evasion point: %j",i.requestId,N);const L=S.calculateDistance(N,u);return y.info("[%s] the distance(%d) between tmp & p2: %j - %j",i.requestId,L,N,u),L<n&&(N=S.calculateCoordinate(e,$,o*Number(c)/2),N.utc=D((f=(m=t==null?void 0:t.forecasts)==null?void 0:m[0])==null?void 0:f.date).add(Number(c)/2,"hours").utc().format(),y.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j",i.requestId,N)),N}else{y.info("[%s] no need evasion: %j",i.requestId,{from:e,p1:r,p2:u});return}}static pickIndex(e,t){let n=0;for(const o of e){if(D(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 i in e)o[i]=this.computeNumber(e[i],t[i],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=S,C.LngLatHelper=l,C.TropicalHelper=B,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
1
+ (function(C,I){typeof exports=="object"&&typeof module<"u"?I(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"],I):(C=typeof globalThis<"u"?globalThis:C||self,I(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,I,y,q,W){"use strict";function F(T){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const t in T)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(T,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>T[t]})}}return e.default=T,Object.freeze(e)}const g=F(I);function O(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(T=>{j.prototype[T.toLowerCase()]=()=>{},j.prototype[`is${T}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var E={getLogger:k?k.getLogger:()=>new j};const A=O(E);class l{static guessTimeZoneOffset(e,t){const n=W(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 i=e*3600,s,r,c,u,a,d;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),a=i/3600,n.indexOf("M")!==-1?d=l.roundPrecision(a,t).toString().padStart(3,"0"):d=l.padNumber(a,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,d)}${o}`;return{direction:o,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}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 i=e*3600,s,r,c,u,a,d;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),a=i/3600,n.indexOf("M")!==-1?d=l.roundPrecision(a,t).toString().padStart(2,"0"):d=l.padNumber(a,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,d)}${o}`;return{direction:o,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}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 i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>360&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(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 i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>90&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(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,i=Number(o.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${o}E`:i<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${i>0?"E":"W"}`:e=`${o}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${i}`}}class v{static calculateBearing(e,t,n=!0,o=4){const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=g.rhumbBearing(i.features[0],i.features[1]):s=g.bearing(i.features[0],i.features[1]),s<0&&(s+=360),l.roundPrecision(s,o)}static calculateDistance(e,t,n=!0,o=4,i="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(s.features[0],s.features[1],{units:i}):r=g.distance(s.features[0],s.features[1],{units:i}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,i;for(const s of e)for(let r=0;r<s.length-1;r++){const c={lng:s[r][0],lat:s[r][1]};r===0&&i&&(o+=this.calculateDistance(i,c,!0,t,n));const u={lng:s[r+1][0],lat:s[r+1][1]};o+=this.calculateDistance(c,u,!0,t,n),i=u}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",i=!0){const s=g.point([e.lng,e.lat]);let r;i?r=g.rhumbDestination(s,n,t,{units:o}):r=g.destination(s,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,i=!0,s="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),u=this.calculateDistance(e,t,!1,8,s);o&&r.push({lng:e.lng,lat:e.lat});let a=0;for(;a<u;)a+=n,a<u&&r.push(this.calculateCoordinate(e,c,a,s,!1));return i&&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 i,s;for(let r=0;r<e.length-1;r++){i=l.convertToStdLng(e[r].lng,8),s=l.convertToStdLng(e[r+1].lng,8),n.push([i,e[r].lat]);const c=i-s;if(Math.abs(c)>180){const u=l.convertToMonotonicLng2([[i,e[r].lat],[s,e[r+1].lat]]);let a,d;t?(a=g.lineString(u),d=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(a=g.greatCircle(u[0],u[1]),d=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(a,d);let h;if(p.features.length){const D=g.getCoord(p.features[0]);h=l.roundPrecision(D[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),o.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),o.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([s,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((i,s)=>(i.findIndex(r=>r[0]===s[0]&&r[1]===s[1])===-1&&i.push(s),i),[]);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,i=0,s,r;return t.forEach((c,u)=>{for(let a=0;a<c.length-1;a++){const d={lng:c[a][0],lat:c[a][1]},p={lng:c[a+1][0],lat:c[a+1][1]},h=this.calculatePointToLineDistance(e,d,p);n>h&&(n=h,i=a,o=u,s=this.calculateDistance(d,e),r=this.calculateDistance(p,e))}}),s!==0&&r!==0?t[o].splice(i+1,0,[e.lng,e.lat]):s===0?t[o].splice(i,1,[e.lng,e.lat]):r===0&&t[o].splice(i+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 i=0;return n.forEach(s=>{if(i===2)return;const r=[];for(const c of s){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),i===0&&r.push([e.lng,e.lat]),i=2;break}i===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(i=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const i=this.convertRouteToCoordinates(n,0),s=this.mergeCoordinatesToWaypoints([e,t,...o],i),r=s.findIndex(a=>l.roundPrecision(e.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(a.lat,8)),c=s.findIndex(a=>l.roundPrecision(t.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(a.lat,8));return s.filter((a,d)=>d>=r&&d<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,i=0;return t.forEach((s,r)=>{for(let c=0;c<s.length-1;c++){const u={lng:s[c][0],lat:s[c][1]},a={lng:s[c+1][0],lat:s[c+1][1]},d=this.calculatePointToLineDistance(e,u,a);n>d&&(n=d,o=c,i=r)}}),{minDist:n,segIndex:i,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let s=!0;for(let r=n;r<t.length;r++)if(s){const c=[];c.push([e.lng,e.lat]);for(let u=o+1;u<t[r].length;u++)e.lng===t[r][u][0]&&e.lat===t[r][u][1]||c.push(t[r][u]);i.push(c),s=!1}else i.push([...t[r]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let s=0;s<t.length-1;s++){const r=t[s],c=t[s+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((a,d)=>d>0);const u=this.calculatePointToLineDistance(e,r,c);n>u&&(n=u,o=s)}e.lng=l.convertToStdLng(e.lng);const i=[e];for(let s=o+1;s<t.length;s++)i.push(t[s]);return i}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 i=l.convertToMonotonicLng([t,n]);t=i[0],n=i[1];const s=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),s,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),s,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],i=e[n+1],s=this.calculateRangeRoute(o,i,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),i.distanceFromPrevious=this.calculateRouteDistance(s),i.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+i.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,i=0,s=0,r=0;for(let c=0;c<t.length-1;c++){const u={lng:t[c].lng,lat:t[c].lat},a={lng:t[c+1].lng,lat:t[c+1].lat},d=this.calculatePointToLineDistance(e,u,a);o>=d&&(o=d,i=c,s=this.calculateDistance(u,e,!1,6),r=this.calculateDistance(a,e,!1,6))}return s!==0&&r!==0?s<o||s===o&&i===0?t.unshift(e):r<o||r===o&&i===t.length-2?t.push(e):t.splice(i+1,0,e):s===0?n&&t.splice(i,1,e):r===0&&n&&t.splice(i+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],i=e[n];if(n===1&&t.push(o),i.gcToPrevious){const s=this.interpolateCoordinates(o,i,200,!1,!0,"nauticalmiles");t.push(...s)}else t.push(i)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const u=c.map(a=>g.point(a));o.push(...u)}const i=g.featureCollection(o),s=g.nearestPoint(n,i),r=g.getCoord(s);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 i=t[o],s=t[o+1];if(this.calculateDistance(e,i)===0){n=o;break}if(this.calculateDistance(e,s)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var p;const i=e.speed||12,s=[];let r=[],c=!1,u=0,a=0,d;if(t&&n.length?(s.push(e),n.forEach((h,D)=>{if(c)r.push(h);else{const P=[];let b;for(let S=0;S<h.length;S++)if(d)P.push(h[S]);else{b={lng:h[S][0],lat:h[S][1]};const m=this.calculateDistance(e,b,!0,8,o);if(u+=m,u<t)a+=m,s.push(b),e=b;else{if(a=t,u===t)d=b,P.push([d.lng,d.lat]);else{const f=u-t,M=this.calculateBearing(b,e);d=this.calculateCoordinate(b,M,f,o),P.push([d.lng,d.lat]),P.push([b.lng,b.lat])}c=!0}}P.length&&r.push(P),D===n.length-1&&!d&&(d=b)}})):(r=n,d={...e}),d)if(s.push(d),d.distanceFromPrevious=a,d.hourFromPrevious=Math.round(a/i*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};d.bearing=this.calculateBearing(d,h)}else d.bearing=0;return{coordinate:d,nextRoute:r,prevRoute:s}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),i=g.point([o,e.lat]),s=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[s,t.lat],[r,n.lat]]),u=g.nearestPointOnLine(c,i),a=g.getCoord(u),d=l.roundPrecision(a[0],6),p=l.roundPrecision(a[1],6);return{lng:d,lat:p,inline:!(d===s&&p===t.lat)&&!(d===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,i;return e.forEach(s=>{s.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!i)n.push(c),i=c;else if(i.bearing===void 0)i.bearing=this.calculateBearing(i,c,!0);else{const u=this.calculateDistance(o,c,!0);u&&u>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),i=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 i=t[o-1],s=t[o];if(s.gcToPrevious){const r=e.findIndex(u=>u.lng===i.lng&&u.lat===i.lat),c=e.findIndex(u=>u.lng===s.lng&&u.lat===s.lat);for(let u=c-1;u>r;u--)e.splice(u,1)}}let n=0;for(let o=1;o<e.length;o++){const i=e[o-1],s=e[o];s.gcToPrevious?(i.bearing=this.calculateBearing(i,s,!1),s.distanceFromPrevious=this.calculateDistance(i,s,!1)):(i.bearing=this.calculateBearing(i,s,!0),s.distanceFromPrevious=this.calculateDistance(i,s,!0)),n=l.roundPrecision(n+s.distanceFromPrevious),s.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 s=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(s[0],8),lat:l.roundPrecision(s[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const i of e)for(const s of i)t.push(s);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)}}const R=A.getLogger("vessel");class B{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const i=(n=o.history)==null?void 0:n[0];for(const s of o.forecasts){const r=[],c=y(s.date).utc(),u=`${o.name}-${s.model}`;if(i){const a=y(i.updated).utc(),d=g.point([i.lng,i.lat],{model:s.model,name:o.name,date:a.format(),hour:0,format:a.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?l.roundPrecision(i.pressure/100,0):l.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:u,type:"forecast"});t.features.push(d),r.push(d.geometry.coordinates)}for(const a in s==null?void 0:s.hours){const d=s.hours[a];d.wind.spd=d.wind.spd||d.wind.speed;const p=c.clone().add(Number(a),"hour"),h=g.point([d.lng,d.lat],{model:s.model,name:o.name,date:p.format(),hour:Number(a),format:p.format("MMM-DD/HHmm[Z]"),pressure:d.pressure>1e4?l.roundPrecision(d.pressure/100,0):l.roundPrecision(d.pressure,0),gusts:d.gusts,wind:d.wind||{},movement:d.movement,category:u,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const a=g.lineString(l.convertToMonotonicLng2(r),{date:s.date,id:o.id||o.name,model:s.model,name:o.name,category:u,type:"forecast"});t.features.push(a)}}}if(o.history){const i=[];for(const r of o.history){const c=y(r.updated).utc(),u=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(u),i.push(u.geometry.coordinates)}const s=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const r=g.lineString(l.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?l.roundPrecision((s==null?void 0:s.pressure)/100,0):l.roundPrecision(s==null?void 0:s.pressure,0),spd:(s==null?void 0:s.speed)||(s==null?void 0:s.spd),kts:s==null?void 0:s.kts,source:s==null?void 0:s.source,level:s==null?void 0:s.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var i,s,r,c,u;const n=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,p=a.properties.model,h=y(a.properties.date).utc();let D=t*60-(h.get("hour")*60+h.get("minute"))%(t*60);const P=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${d}-${p}`);let b,S=h.clone().add(D,"minute").set({minute:0,second:0,millisecond:0});for(;b=this.pickIndex(P,S),b<=P.length-1;){if(b>0){const m=P[b],f=b===0?void 0:P[b-1],M=(D/60-((r=f==null?void 0:f.properties)==null?void 0:r.hour))/(m.properties.hour-((c=f==null?void 0:f.properties)==null?void 0:c.hour)),x=this.computeNumber(f==null?void 0:f.geometry.coordinates[0],m.geometry.coordinates[0],M),$=this.computeNumber(f==null?void 0:f.geometry.coordinates[1],m.geometry.coordinates[1],M),N=g.point([x,$],{name:d,model:p,category:m==null?void 0:m.properties.category,date:S.format(),format:S.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(f==null?void 0:f.properties.gusts,m.properties.gusts,M),hour:this.computeNumber(f==null?void 0:f.properties.hour,m.properties.hour,M),movement:this.computeNumber(f==null?void 0:f.properties.movement,m.properties.movement,M),pressure:this.computeNumber(f==null?void 0:f.properties.pressure,m.properties.pressure,M),wind:this.computeNumber(f==null?void 0:f.properties.wind,m.properties.wind,M),type:"forecast",showCircle:(u=a==null?void 0:a.properties)==null?void 0:u.showCircle});o.push(N)}D+=t*60,S=h.clone().add(D,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o,i={requestId:""}){var a,d,p,h,D,P,b,S,m;const s=(d=(a=t==null?void 0:t.forecasts)==null?void 0:a[0])==null?void 0:d.hours,r=((p=t==null?void 0:t.history)==null?void 0:p[0])||(s==null?void 0:s[(h=Object.keys(s))==null?void 0:h[0]]);R.info("[%s] the first evasion point: %j",i.requestId,r);const c=(D=Object.keys(s||{}).filter(f=>Number(f)<=24))==null?void 0:D.at(-1),u=s==null?void 0:s[c||-1];if(R.info("[%s] the second evasion point in %s hrs: %j",i.requestId,c,r),r&&u){const f=v.calculateBearing(e,r),M=v.calculateBearing(r,u),x=v.calculateCoordinate(r,f-M+90,n);R.info("[%s] the right tangent point: %j",i.requestId,{from:e,p1:r,p2:u,radius:n,bearing1:f,bearing2:M,right:x});const $=v.calculateBearing(e,x);let N=v.calculateCoordinate(e,$,o*Number(c));N.utc=y((b=(P=t==null?void 0:t.forecasts)==null?void 0:P[0])==null?void 0:b.date).add(Number(c),"hours").utc().format(),R.info("[%s] the temp evasion point: %j",i.requestId,N);const L=v.calculateDistance(N,u);return R.info("[%s] the distance(%d) between tmp & p2: %j - %j",i.requestId,L,N,u),L<n&&(N=v.calculateCoordinate(e,$,o*Number(c)/2),N.utc=y((m=(S=t==null?void 0:t.forecasts)==null?void 0:S[0])==null?void 0:m.date).add(Number(c)/2,"hours").utc().format(),R.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j",i.requestId,N)),N}else{R.info("[%s] no need evasion: %j",i.requestId,{from:e,p1:r,p2:u});return}}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 i in e)o[i]=this.computeNumber(e[i],t[i],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=B,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.0",
4
+ "version": "1.2.1",
5
5
  "description": "idm plugin for geo",
6
6
  "type": "module",
7
7
  "keywords": [