@idm-plugin/geo 2.1.9 → 2.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
@@ -2,8 +2,8 @@ import * as f from "@turf/turf";
2
2
  import b from "moment";
3
3
  import w from "@log4js-node/log4js-api";
4
4
  import "moment-timezone";
5
- import F from "tz-lookup";
6
- import k from "shpjs";
5
+ import W from "tz-lookup";
6
+ import q from "shpjs";
7
7
  class d {
8
8
  /**
9
9
  * 基于输入的经度,计算出时区
@@ -12,7 +12,7 @@ class d {
12
12
  */
13
13
  static guessTimeZoneOffset(t, e) {
14
14
  t = d.convertToStdLng(t);
15
- const n = F(e, t), i = b().tz(n).utcOffset();
15
+ const n = W(e, t), i = b().tz(n).utcOffset();
16
16
  return d.roundPrecision(i / 60, 1);
17
17
  }
18
18
  /**
@@ -164,7 +164,7 @@ class d {
164
164
  return i >= 1 ? o : n > 0 ? `${o}.${Math.trunc(i * Math.pow(10, n)).toString().padStart(n, "0")}` : o;
165
165
  }
166
166
  }
167
- class W {
167
+ class j {
168
168
  static json2Str(t) {
169
169
  const e = t.type ? t.type[0].toUpperCase() : "A";
170
170
  return `${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo || {})}|${t.vendor}|${t.deleted}`;
@@ -200,7 +200,7 @@ class W {
200
200
  if (n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))
201
201
  continue;
202
202
  const h = g.positionTime - l.positionTime;
203
- if (v.calculateDistance(g, l, !0, 4) / (h / 3600) < e)
203
+ if (y.calculateDistance(g, l, !0, 4) / (h / 3600) < e)
204
204
  r || (r = a), u === t.length - 1 && (s = g, c = u);
205
205
  else {
206
206
  r && (s = t[u - 1], c = u);
@@ -224,8 +224,8 @@ class W {
224
224
  utc: b.unix(s.positionTime).utc().format()
225
225
  },
226
226
  duration: s.positionTime - r.positionTime
227
- }, l = t.filter((h) => h.positionTime >= u.start.positionTime && h.positionTime <= u.end.positionTime), g = v.divideAccordingToLng(l);
228
- u.distance = v.calculateRouteDistance(g), u.hours = Math.round(u.duration / 3600 * 10) / 10, u.avgSog = Math.round(u.distance / u.hours * 10) / 10, o.push(u);
227
+ }, l = t.filter((h) => h.positionTime >= u.start.positionTime && h.positionTime <= u.end.positionTime), g = y.divideAccordingToLng(l);
228
+ u.distance = y.calculateRouteDistance(g), u.hours = Math.round(u.duration / 3600 * 10) / 10, u.avgSog = Math.round(u.distance / u.hours * 10) / 10, o.push(u);
229
229
  }
230
230
  r = void 0, s = void 0;
231
231
  }
@@ -244,7 +244,7 @@ class W {
244
244
  if (r.length > 1)
245
245
  for (let u = 0; u < r.length - 1; u++) {
246
246
  const l = r[u], g = r[u + 1];
247
- s += v.calculateDistance(l, g, !0, 4), c += Math.abs(g.positionTime - l.positionTime);
247
+ s += y.calculateDistance(l, g, !0, 4), c += Math.abs(g.positionTime - l.positionTime);
248
248
  }
249
249
  s = Math.round(s * 100) / 100, c = Math.round(c / 3600 * 100) / 100;
250
250
  const a = c ? Math.round(s / c * 100) / 100 : 0;
@@ -257,7 +257,7 @@ try {
257
257
  } catch {
258
258
  } finally {
259
259
  }
260
- class v {
260
+ class y {
261
261
  /**
262
262
  * 计算方位角
263
263
  * @param from 坐标 {lng, lat}
@@ -374,13 +374,13 @@ class v {
374
374
  [a > 0 ? 180 : -180, -89]
375
375
  ])) : (l = f.greatCircle(u[0], u[1]), g = f.greatCircle([a > 0 ? 180 : -180, 89], [a > 0 ? 180 : -180, -89]));
376
376
  const h = f.lineIntersect(l, g);
377
- let p;
377
+ let T;
378
378
  if (h.features.length) {
379
- const T = f.getCoord(h.features[0]);
380
- p = d.roundPrecision(T[1], 8);
379
+ const S = f.getCoord(h.features[0]);
380
+ T = d.roundPrecision(S[1], 8);
381
381
  } else
382
- p = t[c].lat;
383
- a > 0 ? (i.push([180 - 1e-6, p]), o.push([...i]), i = [], i.push([-(180 - 1e-6), p])) : (i.push([-(180 - 1e-6), p]), o.push([...i]), i = [], i.push([180 - 1e-6, p]));
382
+ T = t[c].lat;
383
+ a > 0 ? (i.push([180 - 1e-6, T]), o.push([...i]), i = [], i.push([-(180 - 1e-6), T])) : (i.push([-(180 - 1e-6), T]), o.push([...i]), i = [], i.push([180 - 1e-6, T]));
384
384
  }
385
385
  c === t.length - 2 && i.push([s, t[c + 1].lat]);
386
386
  }
@@ -456,8 +456,8 @@ class v {
456
456
  */
457
457
  static appendCoordinateToRoute(t, e) {
458
458
  t.lng = d.convertToStdLng(t.lng, 8);
459
- const n = v.convertRouteToCoordinates(e);
460
- return n.push(t), v.divideAccordingToLng(n);
459
+ const n = y.convertRouteToCoordinates(e);
460
+ return n.push(t), y.divideAccordingToLng(n);
461
461
  }
462
462
  /**
463
463
  * 向route头加1个坐标
@@ -465,8 +465,8 @@ class v {
465
465
  * @param route
466
466
  */
467
467
  static unshiftCoordinateToRoute(t, e) {
468
- const n = v.convertRouteToCoordinates(e);
469
- return n.unshift(t), v.divideAccordingToLng(n);
468
+ const n = y.convertRouteToCoordinates(e);
469
+ return n.unshift(t), y.divideAccordingToLng(n);
470
470
  }
471
471
  /**
472
472
  * 合并多个waypoints进航线
@@ -540,8 +540,8 @@ class v {
540
540
  * @return [[[lng, lat]]]
541
541
  */
542
542
  static calculateSubRoute(t, e) {
543
- const n = v.convertRouteToCoordinates(e);
544
- v.mergeCoordinateToWaypoints(t, n, !0), e = v.divideAccordingToLng(n);
543
+ const n = y.convertRouteToCoordinates(e);
544
+ y.mergeCoordinateToWaypoints(t, n, !0), e = y.divideAccordingToLng(n);
545
545
  const { segIndex: i, minIndex: o } = this.calculateMinDistanceToRoute({ ...t }, e);
546
546
  t.lng = d.convertToStdLng(t.lng);
547
547
  const r = [];
@@ -715,31 +715,31 @@ class v {
715
715
  var g;
716
716
  const o = t.speed || 12, r = [];
717
717
  let s = [], c = !1, a = 0, u = 0, l;
718
- if (e && n.length ? (r.push(t), n.forEach((h, p) => {
718
+ if (e && n.length ? (r.push(t), n.forEach((h, T) => {
719
719
  if (c)
720
720
  s.push(h);
721
721
  else {
722
- const T = [];
722
+ const S = [];
723
723
  let m;
724
- for (let y = 0; y < h.length; y++)
724
+ for (let v = 0; v < h.length; v++)
725
725
  if (l)
726
- T.push(h[y]);
726
+ S.push(h[v]);
727
727
  else {
728
- m = { lng: h[y][0], lat: h[y][1] };
728
+ m = { lng: h[v][0], lat: h[v][1] };
729
729
  const P = this.calculateDistance(t, m, !0, 8, i);
730
730
  if (a += P, a < e)
731
731
  u += P, P && r.push(m), t = m;
732
732
  else {
733
733
  if (u = e, a === e)
734
- l = m, T.push([l.lng, l.lat]);
734
+ l = m, S.push([l.lng, l.lat]);
735
735
  else {
736
- const M = a - e, S = this.calculateBearing(m, t);
737
- l = this.calculateCoordinate(m, S, M, i), T.push([l.lng, l.lat]), T.push([m.lng, m.lat]);
736
+ const M = a - e, p = this.calculateBearing(m, t);
737
+ l = this.calculateCoordinate(m, p, M, i), S.push([l.lng, l.lat]), S.push([m.lng, m.lat]);
738
738
  }
739
739
  c = !0;
740
740
  }
741
741
  }
742
- T.length && s.push(T), p === n.length - 1 && !l && (l = m);
742
+ S.length && s.push(S), T === n.length - 1 && !l && (l = m);
743
743
  }
744
744
  })) : (s = n, l = { ...t }), l)
745
745
  if (r.push(l), l.distanceFromPrevious = Math.round(u * 1e4) / 1e4, l.hourFromPrevious = Math.round(u / o * 1e4) / 1e4, ((g = s[0]) == null ? void 0 : g.length) > 1) {
@@ -874,8 +874,8 @@ class v {
874
874
  const r = t[o - 1], s = t[o], c = t[o + 1];
875
875
  let a = !1, u = !1;
876
876
  if ((r.velocity || r.suspend || r.important || r.pilot || o === 1) && (a = !0, i.push(r)), s.gcToPrevious && (a || (a = !0, i.push(r)), u = !0, i.push(s), o++), c) {
877
- const l = v.calculateDistance(r, s, !0), g = v.calculateDistance(s, c, !0), h = v.calculateDistance(r, c, !0), p = (Math.pow(l, 2) + Math.pow(g, 2) - Math.pow(h, 2)) / (2 * l * g);
878
- Math.round(Math.acos(p) * 180 / Math.PI) < n && h > e && !u && (i.push(s), o++);
877
+ const l = y.calculateDistance(r, s, !0), g = y.calculateDistance(s, c, !0), h = y.calculateDistance(r, c, !0), T = (Math.pow(l, 2) + Math.pow(g, 2) - Math.pow(h, 2)) / (2 * l * g);
878
+ Math.round(Math.acos(T) * 180 / Math.PI) < n && h > e && !u && (i.push(s), o++);
879
879
  }
880
880
  if (o >= t.length - 1) {
881
881
  const l = t.at(-1);
@@ -909,8 +909,8 @@ class v {
909
909
  if (!i) {
910
910
  const a = (r = (o = e.filter((l) => (l == null ? void 0 : l.positionTime) < n.unix())) == null ? void 0 : o.sort((l, g) => (l.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : r.at(-1), u = (c = (s = e.filter((l) => (l == null ? void 0 : l.positionTime) > n.unix())) == null ? void 0 : s.sort((l, g) => (l.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : c.at(0);
911
911
  if (a && u) {
912
- const l = v.calculateBearing(a, u, !0), g = v.calculateDistance(a, u), h = (n.unix() - a.positionTime) / (u.positionTime - a.positionTime);
913
- i = v.calculateCoordinate(a, l, g * h), i.positionTime = n.unix(), i.utc = n.utc().format(), i.cog = l, i.sog = Math.round(g / ((u.positionTime - a.positionTime) / 3600) * 100) / 100;
912
+ const l = y.calculateBearing(a, u, !0), g = y.calculateDistance(a, u), h = (n.unix() - a.positionTime) / (u.positionTime - a.positionTime);
913
+ i = y.calculateCoordinate(a, l, g * h), i.positionTime = n.unix(), i.utc = n.utc().format(), i.cog = l, i.sog = Math.round(g / ((u.positionTime - a.positionTime) / 3600) * 100) / 100;
914
914
  } else
915
915
  i = a || u, i && (i.utc = b.unix(i == null ? void 0 : i.positionTime).utc().format());
916
916
  }
@@ -925,16 +925,16 @@ class v {
925
925
  e = JSON.parse(JSON.stringify(e)), e.sort((a, u) => (a.positionTime || 0) - (u.positionTime || 0));
926
926
  let n = Number.MAX_SAFE_INTEGER, i = Number.MAX_SAFE_INTEGER;
927
927
  for (let a = 0; a < e.length - 1; a++) {
928
- const u = e[a], l = e[a + 1], g = v.calculatePointToLineDistance(t, u, l);
928
+ const u = e[a], l = e[a + 1], g = y.calculatePointToLineDistance(t, u, l);
929
929
  g < n && (n = g, i = a);
930
930
  }
931
- const o = e[i], r = e[i + 1], s = v.calculateDistance(o, t), c = v.calculateDistance(r, t);
931
+ const o = e[i], r = e[i + 1], s = y.calculateDistance(o, t), c = y.calculateDistance(r, t);
932
932
  if (s === 0)
933
933
  t = o;
934
934
  else if (c === 0)
935
935
  t = r;
936
936
  else {
937
- const a = o.positionTime || 0, u = r.positionTime || 0, l = v.calculateDistance(o, r);
937
+ const a = o.positionTime || 0, u = r.positionTime || 0, l = y.calculateDistance(o, r);
938
938
  t.positionTime = Math.round(a + (u - a) * (s / l));
939
939
  }
940
940
  return t.utc = t.positionTime ? b.unix(t.positionTime).utc().format() : void 0, t.positionTime ? t : void 0;
@@ -973,7 +973,7 @@ class v {
973
973
  */
974
974
  static waypoints2RTZ(t, e) {
975
975
  const i = [];
976
- return i.push('<?xml version="1.0" encoding="UTF-8"?>'), i.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), i.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), i.push(...v.toRTZWaypoints(e, 6)), i.push("</route>"), i.join(`
976
+ return i.push('<?xml version="1.0" encoding="UTF-8"?>'), i.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), i.push(` <routeInfo routeName="${y.xmlEscape(t)}"></routeInfo>`), i.push(...y.toRTZWaypoints(e, 6)), i.push("</route>"), i.join(`
977
977
  `);
978
978
  }
979
979
  /**
@@ -984,7 +984,7 @@ class v {
984
984
  */
985
985
  static waypoints2RTZ10(t, e, n = !0) {
986
986
  const o = [];
987
- return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), o.push(...v.toRTZWaypoints(e, 6, n)), o.push("</route>"), o.join(`
987
+ return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${y.xmlEscape(t)}"></routeInfo>`), o.push(...y.toRTZWaypoints(e, 6, n)), o.push("</route>"), o.join(`
988
988
  `);
989
989
  }
990
990
  static toRTZWaypoints(t, e = 6, n = !0) {
@@ -992,20 +992,20 @@ class v {
992
992
  i.push(" <waypoints>");
993
993
  for (let o = 0; o < t.length; o++) {
994
994
  const r = t[o], s = o + 1, c = (r.lat ?? "").toFixed ? r.lat.toFixed(e).padEnd(e + 2, "0") : r.lat, a = (r.lng ?? "").toFixed ? r.lng.toFixed(e).padEnd(e + 2, "0") : r.lng, u = [`id="${s}"`, 'revision="0"'];
995
- if (r.name && u.push(`name="${v.xmlEscape(r.name)}"`), i.push(` <waypoint ${u.join(" ")}>`), i.push(` <position lat="${v.xmlEscape(c)}" lon="${v.xmlEscape(a)}" />`), o > 0) {
995
+ if (r.name && u.push(`name="${y.xmlEscape(r.name)}"`), i.push(` <waypoint ${u.join(" ")}>`), i.push(` <position lat="${y.xmlEscape(c)}" lon="${y.xmlEscape(a)}" />`), o > 0) {
996
996
  const l = r.gcToPrevious ? "Orthodrome" : "Loxodrome";
997
997
  i.push(` <leg geometryType="${l}" />`);
998
998
  }
999
999
  if (n) {
1000
1000
  const l = [];
1001
- if (r.description && l.push(` <description>${v.xmlEscape(r.description)}</description>`), r.utc)
1002
- l.push(` <time>${v.xmlEscape(r.utc)}</time>`);
1001
+ if (r.description && l.push(` <description>${y.xmlEscape(r.description)}</description>`), r.utc)
1002
+ l.push(` <time>${y.xmlEscape(r.utc)}</time>`);
1003
1003
  else if (r.positionTime)
1004
1004
  try {
1005
- l.push(` <time>${v.xmlEscape(b.unix(r.positionTime).utc().format())}</time>`);
1005
+ l.push(` <time>${y.xmlEscape(b.unix(r.positionTime).utc().format())}</time>`);
1006
1006
  } catch {
1007
1007
  }
1008
- r.cog !== void 0 && l.push(` <cog>${v.xmlEscape(r.cog)}</cog>`), r.sog !== void 0 && l.push(` <sog>${v.xmlEscape(r.sog)}</sog>`), l.length && (i.push(" <extensions>"), i.push(...l), i.push(" </extensions>"));
1008
+ r.cog !== void 0 && l.push(` <cog>${y.xmlEscape(r.cog)}</cog>`), r.sog !== void 0 && l.push(` <sog>${y.xmlEscape(r.sog)}</sog>`), l.length && (i.push(" <extensions>"), i.push(...l), i.push(" </extensions>"));
1009
1009
  }
1010
1010
  i.push(" </waypoint>");
1011
1011
  }
@@ -1020,15 +1020,15 @@ class v {
1020
1020
  */
1021
1021
  static waypoints2CSV(t, e, n) {
1022
1022
  I.debug("keep name for waypoints2CSV for legacy compatibility only", t);
1023
- const i = (n == null ? void 0 : n.precision) ?? 6, o = e.some((m) => m.name), r = e.some((m) => m.description), s = e.some((m) => m.port != null), c = e.some((m) => m.stbd != null), a = e.some((m) => m.arrRad != null), u = e.some((m) => m.speed != null), l = e.some((m, y) => y > 0 && m.gcToPrevious != null), g = e.some((m) => m.bearing != null), h = e.some((m) => m.distanceFromPrevious != null), p = ["WPT No.", "Latitude", "Longitude"];
1024
- o && p.push("Name"), r && p.push("Description"), l && p.push("Leg"), g && p.push("Bearing[deg]"), h && p.push("Distance[NM]"), u && p.push("Speed[kn]"), s && p.push("PORT XTD[NM]"), c && p.push("STBD XTD[NM]"), a && p.push("Arr.Rad[NM]");
1025
- const T = [];
1026
- T.push(p.map((m) => v.csvEscapeField(m)).join(","));
1023
+ const i = (n == null ? void 0 : n.precision) ?? 6, o = e.some((m) => m.name), r = e.some((m) => m.description), s = e.some((m) => m.port != null), c = e.some((m) => m.stbd != null), a = e.some((m) => m.arrRad != null), u = e.some((m) => m.speed != null), l = e.some((m, v) => v > 0 && m.gcToPrevious != null), g = e.some((m) => m.bearing != null), h = e.some((m) => m.distanceFromPrevious != null), T = ["WPT No.", "Latitude", "Longitude"];
1024
+ o && T.push("Name"), r && T.push("Description"), l && T.push("Leg"), g && T.push("Bearing[deg]"), h && T.push("Distance[NM]"), u && T.push("Speed[kn]"), s && T.push("PORT XTD[NM]"), c && T.push("STBD XTD[NM]"), a && T.push("Arr.Rad[NM]");
1025
+ const S = [];
1026
+ S.push(T.map((m) => y.csvEscapeField(m)).join(","));
1027
1027
  for (let m = 0; m < e.length; m++) {
1028
- const y = e[m], P = [];
1029
- P.push((m + 1).toString()), P.push(y.lat.toFixed(i)), P.push(y.lng.toFixed(i)), o && P.push(y.name ?? ""), r && P.push(y.description ?? ""), l && P.push(m === 0 ? "" : y.gcToPrevious ? "GC" : "RL"), g && P.push(y.bearing != null ? String(y.bearing) : ""), h && P.push(y.distanceFromPrevious != null ? String(y.distanceFromPrevious) : ""), u && P.push(y.speed != null ? String(y.speed) : ""), s && P.push(y.port != null ? String(y.port) : ""), c && P.push(y.stbd != null ? String(y.stbd) : ""), a && P.push(y.arrRad != null ? String(y.arrRad) : ""), T.push(P.map((M) => v.csvEscapeField(M)).join(","));
1028
+ const v = e[m], P = [];
1029
+ P.push((m + 1).toString()), P.push(v.lat.toFixed(i)), P.push(v.lng.toFixed(i)), o && P.push(v.name ?? ""), r && P.push(v.description ?? ""), l && P.push(m === 0 ? "" : v.gcToPrevious ? "GC" : "RL"), g && P.push(v.bearing != null ? String(v.bearing) : ""), h && P.push(v.distanceFromPrevious != null ? String(v.distanceFromPrevious) : ""), u && P.push(v.speed != null ? String(v.speed) : ""), s && P.push(v.port != null ? String(v.port) : ""), c && P.push(v.stbd != null ? String(v.stbd) : ""), a && P.push(v.arrRad != null ? String(v.arrRad) : ""), S.push(P.map((M) => y.csvEscapeField(M)).join(","));
1030
1030
  }
1031
- return T.join(`
1031
+ return S.join(`
1032
1032
  `);
1033
1033
  }
1034
1034
  /**
@@ -1068,7 +1068,7 @@ class v {
1068
1068
  static waypoints2NMEA(t) {
1069
1069
  const e = [];
1070
1070
  for (let n = 0; n < t.length; n++) {
1071
- const i = t[n], o = v.decimalToNmeaDm(i.lat, !0), r = v.decimalToNmeaDm(i.lng, !1), s = i.name ? String(i.name).slice(0, 6) : `WPT${(n + 1).toString().padStart(3, "0")}`, c = `GPWPL,${o.dm},${o.dir},${r.dm},${r.dir},${s}`, a = v.nmeaChecksum(c);
1071
+ const i = t[n], o = y.decimalToNmeaDm(i.lat, !0), r = y.decimalToNmeaDm(i.lng, !1), s = i.name ? String(i.name).slice(0, 6) : `WPT${(n + 1).toString().padStart(3, "0")}`, c = `GPWPL,${o.dm},${o.dir},${r.dm},${r.dir},${s}`, a = y.nmeaChecksum(c);
1072
1072
  e.push(`$${c}*${a}`);
1073
1073
  }
1074
1074
  return e.join(`\r
@@ -1088,8 +1088,8 @@ class v {
1088
1088
  */
1089
1089
  static coordinatesSummary(t, e = 3) {
1090
1090
  if (t.length > 1) {
1091
- const n = t[0], i = t[t.length - 1], o = (n == null ? void 0 : n.positionTime) < (i == null ? void 0 : i.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(i == null ? void 0 : i.positionTime), r = (n == null ? void 0 : n.positionTime) > (i == null ? void 0 : i.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(i == null ? void 0 : i.positionTime), s = Math.round(r.diff(o, "hours", !0) * 100) / 100, c = this.generateRouteAccordingToWaypoints(t, !0, !0), a = this.calculateRouteDistance(c), l = W.inspectStoppages(t, e).reduce(
1092
- (h, p) => (h.duration += p.duration, h.distance += p.distance, h),
1091
+ const n = t[0], i = t[t.length - 1], o = (n == null ? void 0 : n.positionTime) < (i == null ? void 0 : i.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(i == null ? void 0 : i.positionTime), r = (n == null ? void 0 : n.positionTime) > (i == null ? void 0 : i.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(i == null ? void 0 : i.positionTime), s = Math.round(r.diff(o, "hours", !0) * 100) / 100, c = this.generateRouteAccordingToWaypoints(t, !0, !0), a = this.calculateRouteDistance(c), l = j.inspectStoppages(t, e).reduce(
1092
+ (h, T) => (h.duration += T.duration, h.distance += T.distance, h),
1093
1093
  { hours: 0, distance: 0, spd: 0, duration: 0 }
1094
1094
  );
1095
1095
  l.hours = Math.round(l.duration / 3600 * 100) / 100, l.distance = Math.round(l.distance * 100) / 100, l.spd = l.hours ? Math.round(l.distance / l.hours * 100) / 100 : 0;
@@ -1127,16 +1127,16 @@ class v {
1127
1127
  const n = e.sample.hours.at(0), i = b.utc(t), o = b.utc(e.eta), r = i.isAfter(o) ? o : i;
1128
1128
  let s = e.sample.all.find((h) => h.eta === r.format());
1129
1129
  if (!s) {
1130
- const h = e.sample.all.filter((N) => b.utc(N.eta).isBefore(r)).at(-1), p = this.calculateSubRoute(h, e.route);
1131
- s = (g = this.calculateNextCoordinateAlongRoute(h, h.speed * r.diff(b(h.etd), "hours", !0), p)) == null ? void 0 : g.coordinate;
1132
- const { cFactor: T, cog: m, wxFactor: y, meteo: P } = h, M = Math.round(s.distanceFromPrevious * 1e4) / 1e4, S = Math.round((M + h.distanceFromStart) * 1e4) / 1e4;
1130
+ const h = e.sample.all.filter((N) => b.utc(N.eta).isBefore(r)).at(-1), T = this.calculateSubRoute(h, e.route);
1131
+ s = (g = this.calculateNextCoordinateAlongRoute(h, h.speed * r.diff(b(h.etd), "hours", !0), T)) == null ? void 0 : g.coordinate;
1132
+ const { cFactor: S, cog: m, wxFactor: v, meteo: P } = h, M = Math.round(s.distanceFromPrevious * 1e4) / 1e4, p = Math.round((M + h.distanceFromStart) * 1e4) / 1e4;
1133
1133
  s = {
1134
1134
  ...s,
1135
- cFactor: T,
1135
+ cFactor: S,
1136
1136
  cog: m,
1137
1137
  speed: h.speed,
1138
- wxFactor: y,
1139
- distanceFromStart: S,
1138
+ wxFactor: v,
1139
+ distanceFromStart: p,
1140
1140
  distanceFromPrevious: M,
1141
1141
  meteo: P,
1142
1142
  eta: r.format(),
@@ -1189,7 +1189,7 @@ try {
1189
1189
  } catch {
1190
1190
  } finally {
1191
1191
  }
1192
- class z {
1192
+ class X {
1193
1193
  /**
1194
1194
  * 将原始数据转换为geojson
1195
1195
  * @param raw
@@ -1204,16 +1204,16 @@ class z {
1204
1204
  for (const c of r.forecasts) {
1205
1205
  let a;
1206
1206
  const u = [], l = [], g = b(c.date).utc(), h = `${r.name}-${c.model}`;
1207
- for (const T in c == null ? void 0 : c.hours) {
1208
- const m = c.hours[T];
1207
+ for (const S in c == null ? void 0 : c.hours) {
1208
+ const m = c.hours[S];
1209
1209
  a = a || m;
1210
- const y = g.clone().add(Number(T), "hour"), P = f.point([m.lng, m.lat], {
1210
+ const v = g.clone().add(Number(S), "hour"), P = f.point([m.lng, m.lat], {
1211
1211
  model: c.model,
1212
1212
  name: r.name,
1213
1213
  nameCn: r.nameCn,
1214
- date: y.format(),
1215
- hour: Number(T),
1216
- format: y.format("MMM-DD/HHmm[Z]"),
1214
+ date: v.format(),
1215
+ hour: Number(S),
1216
+ format: v.format("MMM-DD/HHmm[Z]"),
1217
1217
  pressure: m.pressure > 1e4 ? d.roundPrecision(m.pressure / 100, 0) : d.roundPrecision(m.pressure, 0),
1218
1218
  gusts: m.gusts,
1219
1219
  wind: m.wind || {},
@@ -1223,26 +1223,26 @@ class z {
1223
1223
  });
1224
1224
  l.push(P), u.push(P.geometry.coordinates);
1225
1225
  }
1226
- const p = {
1226
+ const T = {
1227
1227
  kts: void 0,
1228
1228
  deg: void 0
1229
1229
  };
1230
1230
  if (s) {
1231
- const T = b(s.updated).utc();
1231
+ const S = b(s.updated).utc();
1232
1232
  if (a) {
1233
- const y = v.calculateDistance(s, a), P = b(a.utc || a.updated).diff(T, "h", !0);
1234
- p.kts = Math.round(y / P * 100) / 100, p.deg = v.calculateBearing(s, a, !0, 0);
1233
+ const v = y.calculateDistance(s, a), P = b(a.utc || a.updated).diff(S, "h", !0);
1234
+ T.kts = Math.round(v / P * 100) / 100, T.deg = y.calculateBearing(s, a, !0, 0);
1235
1235
  }
1236
1236
  const m = f.point([s.lng, s.lat], {
1237
1237
  model: c.model,
1238
1238
  name: r.name,
1239
1239
  nameCn: r.nameCn,
1240
- date: T.format(),
1240
+ date: S.format(),
1241
1241
  hour: 0,
1242
- format: T.format("MMM-DD/HHmm[Z]"),
1242
+ format: S.format("MMM-DD/HHmm[Z]"),
1243
1243
  pressure: s.pressure > 1e4 ? d.roundPrecision((s == null ? void 0 : s.pressure) / 100, 0) : d.roundPrecision(s.pressure, 0),
1244
1244
  wind: s.wind,
1245
- movement: p,
1245
+ movement: T,
1246
1246
  category: h,
1247
1247
  type: "forecast",
1248
1248
  important: !0
@@ -1251,25 +1251,25 @@ class z {
1251
1251
  l.unshift(m), u.unshift(m.geometry.coordinates);
1252
1252
  }
1253
1253
  if (e.features.push(...l), (u == null ? void 0 : u.length) > 1) {
1254
- const T = f.lineString(d.convertToMonotonicLng2(u), {
1254
+ const S = f.lineString(d.convertToMonotonicLng2(u), {
1255
1255
  date: (s == null ? void 0 : s.updated) || (g == null ? void 0 : g.format()),
1256
1256
  id: r.id || r.name,
1257
1257
  model: c.model,
1258
1258
  name: r.name,
1259
1259
  category: h,
1260
1260
  type: "forecast",
1261
- movement: p
1261
+ movement: T
1262
1262
  });
1263
- e.features.push(T);
1263
+ e.features.push(S);
1264
1264
  }
1265
1265
  }
1266
1266
  }
1267
1267
  if (e.features.sort((c, a) => c.properties.type === "forecast" && a.properties.type === "forecast" && c.geometry.type === "Point" && a.geometry.type === "Point" ? b(c.properties.date).valueOf() - b(a.properties.date).valueOf() : 0), (i = r.history) != null && i.length) {
1268
1268
  const c = [], a = b(s == null ? void 0 : s.updated).utc(), u = b((o = r.history) == null ? void 0 : o.at(-1).updated).utc(), l = a.diff(u, "h") % 24 > 2 ? 24 : 12;
1269
1269
  for (const g of r.history) {
1270
- const h = b(g.updated).utc(), p = h.isSameOrBefore(a) || h.isSame(u);
1271
- p && a.add(-l, "h");
1272
- const T = f.point([g.lng, g.lat], {
1270
+ const h = b(g.updated).utc(), T = h.isSameOrBefore(a) || h.isSame(u);
1271
+ T && a.add(-l, "h");
1272
+ const S = f.point([g.lng, g.lat], {
1273
1273
  name: r.name,
1274
1274
  nameCn: r.nameCn,
1275
1275
  date: h.format(),
@@ -1281,9 +1281,9 @@ class z {
1281
1281
  category: `${r.name}-history`,
1282
1282
  wind: g.wind,
1283
1283
  movement: g.movement,
1284
- important: p
1284
+ important: T
1285
1285
  });
1286
- e.features.push(T), c.push(T.geometry.coordinates);
1286
+ e.features.push(S), c.push(S.geometry.coordinates);
1287
1287
  }
1288
1288
  if (c.length === 1 && c.push(c[0]), c.length > 1) {
1289
1289
  const g = f.lineString(d.convertToMonotonicLng2(c), {
@@ -1309,32 +1309,32 @@ class z {
1309
1309
  var o, r, s, c;
1310
1310
  const n = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), i = [];
1311
1311
  for (const a of n) {
1312
- const u = a.properties.name, l = a.properties.model, g = a.properties.showCircle, h = a.properties.disabled, p = b(a.properties.date).utc();
1313
- let T = e * 60;
1312
+ const u = a.properties.name, l = a.properties.model, g = a.properties.showCircle, h = a.properties.disabled, T = b(a.properties.date).utc();
1313
+ let S = e * 60;
1314
1314
  const m = (r = t == null ? void 0 : t.data) == null ? void 0 : r.features.filter(
1315
1315
  (M) => M.geometry.type === "Point" && M.properties.type === "forecast" && M.properties.category === `${u}-${l}`
1316
1316
  );
1317
- let y, P = p.clone().add(T, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1318
- for (; y = this.pickIndex(m, P), y <= m.length - 1; ) {
1319
- if (y > 0) {
1320
- const M = m[y], S = y === 0 ? void 0 : m[y - 1], N = (T / 60 - ((s = S == null ? void 0 : S.properties) == null ? void 0 : s.hour)) / (M.properties.hour - ((c = S == null ? void 0 : S.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(S == null ? void 0 : S.geometry.coordinates[0], M.geometry.coordinates[0], N), O = this.computeNumber(S == null ? void 0 : S.geometry.coordinates[1], M.geometry.coordinates[1], N), A = f.point([$, O], {
1317
+ let v, P = T.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1318
+ for (; v = this.pickIndex(m, P), v <= m.length - 1; ) {
1319
+ if (v > 0) {
1320
+ const M = m[v], p = v === 0 ? void 0 : m[v - 1], N = (S / 60 - ((s = p == null ? void 0 : p.properties) == null ? void 0 : s.hour)) / (M.properties.hour - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], M.geometry.coordinates[0], N), O = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], M.geometry.coordinates[1], N), A = f.point([$, O], {
1321
1321
  name: u,
1322
1322
  model: l,
1323
1323
  category: M == null ? void 0 : M.properties.category,
1324
1324
  date: P.format(),
1325
1325
  format: P.format("MMM-DD/HHmm[Z]"),
1326
- gusts: this.computeNumber(S == null ? void 0 : S.properties.gusts, M.properties.gusts, N),
1327
- hour: this.computeNumber(S == null ? void 0 : S.properties.hour, M.properties.hour, N),
1328
- movement: this.computeNumber(S == null ? void 0 : S.properties.movement, M.properties.movement, N),
1329
- pressure: this.computeNumber(S == null ? void 0 : S.properties.pressure, M.properties.pressure, N),
1330
- wind: this.computeNumber(S == null ? void 0 : S.properties.wind, M.properties.wind, N),
1326
+ gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, M.properties.gusts, N),
1327
+ hour: this.computeNumber(p == null ? void 0 : p.properties.hour, M.properties.hour, N),
1328
+ movement: this.computeNumber(p == null ? void 0 : p.properties.movement, M.properties.movement, N),
1329
+ pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, M.properties.pressure, N),
1330
+ wind: this.computeNumber(p == null ? void 0 : p.properties.wind, M.properties.wind, N),
1331
1331
  type: "forecast",
1332
1332
  disabled: h,
1333
1333
  showCircle: g
1334
1334
  });
1335
1335
  i.push(A);
1336
1336
  }
1337
- T += e * 60, P = p.clone().add(T, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1337
+ S += e * 60, P = T.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1338
1338
  }
1339
1339
  }
1340
1340
  return i;
@@ -1364,19 +1364,19 @@ class z {
1364
1364
  const { t1: o, t2: r, hr: s, hours: c } = this.tropicalCenterTwin(e, 24, i);
1365
1365
  if (o && r) {
1366
1366
  if (!i.debug) {
1367
- const p = v.calculateDistance(t, o), T = v.calculateDistance(t, r);
1368
- if (p > 2 * n && T > 2 * n)
1369
- return C == null || C.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", i.requestId, p, T, {
1367
+ const T = y.calculateDistance(t, o), S = y.calculateDistance(t, r);
1368
+ if (T > 2 * n && S > 2 * n)
1369
+ return C == null || C.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", i.requestId, T, S, {
1370
1370
  from: t,
1371
1371
  t1: o,
1372
1372
  t2: r,
1373
1373
  hr: s
1374
1374
  }), {};
1375
1375
  }
1376
- const a = v.calculateBearing(t, o), u = v.calculateBearing(o, r), l = Math.abs(a - u);
1376
+ const a = y.calculateBearing(t, o), u = y.calculateBearing(o, r), l = Math.abs(a - u);
1377
1377
  let g = 0;
1378
1378
  l < 180 ? g = l + 90 : l >= 180 && (g = l - 90);
1379
- const h = v.calculateCoordinate(o, g, n);
1379
+ const h = y.calculateCoordinate(o, g, n);
1380
1380
  return C == null || C.info("[%s] the right tangent position: %j", i.requestId, {
1381
1381
  from: t,
1382
1382
  t1: o,
@@ -1403,17 +1403,17 @@ class z {
1403
1403
  const { t1: o, t2: r, hr: s, hours: c } = this.tropicalCenterTwin(e, 24, i);
1404
1404
  if (o && r) {
1405
1405
  if (!i.debug) {
1406
- const h = v.calculateDistance(t, o), p = v.calculateDistance(t, r);
1407
- if (h > 2 * n && p > 2 * n)
1408
- return C == null || C.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", i.requestId, h, p, {
1406
+ const h = y.calculateDistance(t, o), T = y.calculateDistance(t, r);
1407
+ if (h > 2 * n && T > 2 * n)
1408
+ return C == null || C.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", i.requestId, h, T, {
1409
1409
  from: t,
1410
1410
  t1: o,
1411
1411
  t2: r,
1412
1412
  hr: s
1413
1413
  }), {};
1414
1414
  }
1415
- const a = v.calculateBearing(t, o), u = v.calculateBearing(o, r), l = v.calculateDistance(t, o);
1416
- return { at: v.calculateCoordinate(o, a - u + 180, n < l ? n : l), t1: o, t2: r, hr: Number(s), hours: c };
1415
+ const a = y.calculateBearing(t, o), u = y.calculateBearing(o, r), l = y.calculateDistance(t, o);
1416
+ return { at: y.calculateCoordinate(o, a - u + 180, n < l ? n : l), t1: o, t2: r, hr: Number(s), hours: c };
1417
1417
  } else
1418
1418
  return C == null || C.info("[%s] no need drift: %j", i.requestId, { from: t, t1: o, t2: r, hr: s }), {};
1419
1419
  }
@@ -1426,20 +1426,20 @@ class z {
1426
1426
  * @private
1427
1427
  */
1428
1428
  static tropicalCenterTwin(t, e = 24, n = {}) {
1429
- var u, l, g, h, p;
1429
+ var u, l, g, h, T;
1430
1430
  let i = {};
1431
- (u = t.forecasts) == null || u.forEach((T) => {
1432
- i = { ...T.hours, ...i };
1431
+ (u = t.forecasts) == null || u.forEach((S) => {
1432
+ i = { ...S.hours, ...i };
1433
1433
  });
1434
1434
  const o = ((l = t == null ? void 0 : t.history) == null ? void 0 : l[0]) || (i == null ? void 0 : i[(g = Object.keys(i)) == null ? void 0 : g[0]]);
1435
1435
  C == null || C.info("[%s] the first tropical center: %j", n.requestId, o);
1436
- let r = (h = Object.keys(i || {}).filter((T) => Number(T) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
1437
- r || (r = (p = Object.keys(i || {}).filter((T) => Number(T) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : p.at(-1));
1436
+ let r = (h = Object.keys(i || {}).filter((S) => Number(S) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
1437
+ r || (r = (T = Object.keys(i || {}).filter((S) => Number(S) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : T.at(-1));
1438
1438
  const s = i == null ? void 0 : i[r || -1];
1439
1439
  C == null || C.info("[%s] the second tropical center: %j in %d hrs", n.requestId, s, r);
1440
- const c = Object.keys(i || {}).filter((T) => Number(T) <= Number(r)), a = { 0: o };
1441
- for (const T of c)
1442
- a[T] = i[T];
1440
+ const c = Object.keys(i || {}).filter((S) => Number(S) <= Number(r)), a = { 0: o };
1441
+ for (const S of c)
1442
+ a[S] = i[S];
1443
1443
  return { t1: o, t2: s, hr: Number(r), hours: a };
1444
1444
  }
1445
1445
  static pickIndex(t, e) {
@@ -1487,7 +1487,7 @@ try {
1487
1487
  } catch {
1488
1488
  } finally {
1489
1489
  }
1490
- function q() {
1490
+ function U() {
1491
1491
  if (typeof DOMParser < "u")
1492
1492
  return new DOMParser();
1493
1493
  const { JSDOM: D } = require("jsdom"), { DOMParser: t } = new D("").window;
@@ -1593,8 +1593,8 @@ class R {
1593
1593
  const u = (n == null ? void 0 : n.units) || "nauticalmiles";
1594
1594
  let l = n == null ? void 0 : n.radius;
1595
1595
  if (!l) {
1596
- const p = f.polygonToLine(t);
1597
- l = f.pointToLineDistance(c, p, { units: u });
1596
+ const T = f.polygonToLine(t);
1597
+ l = f.pointToLineDistance(c, T, { units: u });
1598
1598
  }
1599
1599
  a = "end";
1600
1600
  const g = ((o = n == null ? void 0 : n.end) == null ? void 0 : o.length) == 2 ? f.point(n.end) : f.destination(c, l, 90, { units: u });
@@ -1690,33 +1690,46 @@ class R {
1690
1690
  const e = new Uint8Array(t), n = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), i = new DataView(n), o = new Uint8Array(n), r = /* @__PURE__ */ new Map();
1691
1691
  let s = 0;
1692
1692
  for (; s + 4 <= n.byteLength && i.getUint32(s, !0) === 67324752; ) {
1693
- const u = i.getUint16(s + 8, !0), l = i.getUint32(s + 18, !0), g = i.getUint16(s + 26, !0), h = i.getUint16(s + 28, !0), p = o.slice(s + 30, s + 30 + g), T = new TextDecoder().decode(p), m = s + 30 + g + h, y = o.slice(m, m + l);
1694
- if (u === 0)
1695
- r.set(T, y);
1696
- else if (u === 8) {
1693
+ const u = i.getUint16(s + 6, !0), l = i.getUint16(s + 8, !0);
1694
+ let g = i.getUint32(s + 18, !0);
1695
+ const h = i.getUint16(s + 26, !0), T = i.getUint16(s + 28, !0), S = o.slice(s + 30, s + 30 + h), m = new TextDecoder().decode(S), v = s + 30 + h + T;
1696
+ if ((u & 8) !== 0 || g === 0) {
1697
+ let p = v;
1698
+ for (; p + 4 <= n.byteLength; ) {
1699
+ const N = i.getUint32(p, !0);
1700
+ if (N === 67324752 || N === 33639248)
1701
+ break;
1702
+ p++;
1703
+ }
1704
+ g = p - v;
1705
+ }
1706
+ const M = o.slice(v, v + g);
1707
+ if (l === 0)
1708
+ r.set(m, M);
1709
+ else if (l === 8) {
1697
1710
  if (typeof DecompressionStream < "u") {
1698
- const P = new DecompressionStream("deflate-raw"), M = P.writable.getWriter(), S = P.readable.getReader();
1699
- M.write(y), M.close();
1700
- const N = [];
1701
- let $ = 0;
1711
+ const p = new DecompressionStream("deflate-raw"), N = p.writable.getWriter(), $ = p.readable.getReader();
1712
+ N.write(M), N.close();
1713
+ const O = [];
1714
+ let A = 0;
1702
1715
  for (; ; ) {
1703
- const { done: E, value: B } = await S.read();
1716
+ const { done: E, value: k } = await $.read();
1704
1717
  if (E)
1705
1718
  break;
1706
- N.push(B), $ += B.length;
1719
+ O.push(k), A += k.length;
1707
1720
  }
1708
- const O = new Uint8Array($);
1709
- let A = 0;
1710
- for (const E of N)
1711
- O.set(E, A), A += E.length;
1712
- r.set(T, O);
1721
+ const F = new Uint8Array(A);
1722
+ let B = 0;
1723
+ for (const E of O)
1724
+ F.set(E, B), B += E.length;
1725
+ r.set(m, F);
1713
1726
  } else if (typeof process < "u" && ((c = process.versions) != null && c.node))
1714
1727
  try {
1715
- r.set(T, R._inflateRawSync(y));
1728
+ r.set(m, R._inflateRawSync(M));
1716
1729
  } catch {
1717
1730
  }
1718
1731
  }
1719
- s = m + l;
1732
+ s = v + g;
1720
1733
  }
1721
1734
  return r;
1722
1735
  }
@@ -1732,39 +1745,39 @@ class R {
1732
1745
  static async convertKML2GeoJSON(t, e = {}) {
1733
1746
  var s, c;
1734
1747
  x.info("[%s] convert kml to geojson", e == null ? void 0 : e.requestId);
1735
- const i = q().parseFromString(t, "application/xml"), o = Array.from(i.querySelectorAll("Placemark")), r = [];
1748
+ const i = U().parseFromString(t, "application/xml"), o = Array.from(i.querySelectorAll("Placemark")), r = [];
1736
1749
  for (const a of o) {
1737
1750
  const u = {}, l = Array.from(a.querySelectorAll("ExtendedData > Data"));
1738
- for (const S of l) {
1739
- const N = S.getAttribute("name"), $ = (c = (s = S.querySelector("value")) == null ? void 0 : s.textContent) == null ? void 0 : c.trim();
1751
+ for (const p of l) {
1752
+ const N = p.getAttribute("name"), $ = (c = (s = p.querySelector("value")) == null ? void 0 : s.textContent) == null ? void 0 : c.trim();
1740
1753
  N && $ !== void 0 && $ !== null && (u[N] = $);
1741
1754
  }
1742
- const g = b.utc(), h = Object.keys(u).find((S) => S.toLowerCase().indexOf("name") !== -1), p = h ? u[h] : void 0, T = `${g.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, m = (S) => S.trim().split(/[\s\n]+/).filter((N) => N.length > 0).map((N) => {
1755
+ const g = b.utc(), h = Object.keys(u).find((p) => p.toLowerCase().indexOf("name") !== -1), T = h ? u[h] : void 0, S = `${g.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, m = (p) => p.trim().split(/[\s\n]+/).filter((N) => N.length > 0).map((N) => {
1743
1756
  const $ = N.split(",").map(Number);
1744
1757
  return [$[0], $[1]];
1745
- }), y = a.querySelector("LineString > coordinates");
1746
- if (y) {
1747
- const S = m(y.textContent || "");
1748
- if (S.length >= 2) {
1749
- const N = f.lineString(S, { ...u, shape: "line", id: T, name: p });
1758
+ }), v = a.querySelector("LineString > coordinates");
1759
+ if (v) {
1760
+ const p = m(v.textContent || "");
1761
+ if (p.length >= 2) {
1762
+ const N = f.lineString(p, { ...u, shape: "line", id: S, name: T });
1750
1763
  r.push(N);
1751
1764
  }
1752
1765
  continue;
1753
1766
  }
1754
1767
  const P = a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");
1755
1768
  if (P) {
1756
- const S = m(P.textContent || "");
1757
- if (S.length >= 4) {
1758
- const N = S[0][0] === S[S.length - 1][0] && S[0][1] === S[S.length - 1][1] ? S : [...S, S[0]], $ = f.polygon([N], { ...u, shape: "polygon", id: T, name: p });
1769
+ const p = m(P.textContent || "");
1770
+ if (p.length >= 4) {
1771
+ const N = p[0][0] === p[p.length - 1][0] && p[0][1] === p[p.length - 1][1] ? p : [...p, p[0]], $ = f.polygon([N], { ...u, shape: "polygon", id: S, name: T });
1759
1772
  r.push($);
1760
1773
  }
1761
1774
  continue;
1762
1775
  }
1763
1776
  const M = a.querySelector("Point > coordinates");
1764
1777
  if (M) {
1765
- const S = m(M.textContent || "");
1766
- if (S.length >= 1) {
1767
- const N = f.point(S[0], { ...u, shape: "point", id: T, name: p });
1778
+ const p = m(M.textContent || "");
1779
+ if (p.length >= 1) {
1780
+ const N = f.point(p[0], { ...u, shape: "point", id: S, name: T });
1768
1781
  r.push(N);
1769
1782
  }
1770
1783
  continue;
@@ -1822,7 +1835,7 @@ class R {
1822
1835
  x.info("[%s] convert shp zip to geojson", e == null ? void 0 : e.requestId);
1823
1836
  try {
1824
1837
  typeof Buffer < "u" && Buffer.isBuffer(t) && (t = R.toArrayBuffer(t));
1825
- const n = await k(t);
1838
+ const n = await q(t);
1826
1839
  if (Array.isArray(n)) {
1827
1840
  const i = n.flatMap((c) => c.features || []), o = b.utc(), r = (e == null ? void 0 : e.id) || o.valueOf().toString(), s = {
1828
1841
  Point: "point",
@@ -1833,10 +1846,10 @@ class R {
1833
1846
  MultiPolygon: "polygon"
1834
1847
  };
1835
1848
  return i.forEach((c, a) => {
1836
- var p;
1837
- const u = ((p = c.geometry) == null ? void 0 : p.type) || "", l = s[u] || u.toLowerCase();
1849
+ var T;
1850
+ const u = ((T = c.geometry) == null ? void 0 : T.type) || "", l = s[u] || u.toLowerCase();
1838
1851
  c.properties = c.properties || {}, c.properties.shape = l, c.properties.parentId = r, c.properties.id = `${r}_${a}`;
1839
- const g = Object.keys(c.properties).find((T) => T.toLowerCase().indexOf("name") !== -1), h = g ? c.properties[g] : void 0;
1852
+ const g = Object.keys(c.properties).find((S) => S.toLowerCase().indexOf("name") !== -1), h = g ? c.properties[g] : void 0;
1840
1853
  c.properties.name = h || `${l}_${o.format()}_${a}`;
1841
1854
  }), f.featureCollection(i);
1842
1855
  }
@@ -1847,9 +1860,9 @@ class R {
1847
1860
  }
1848
1861
  }
1849
1862
  export {
1850
- W as AisHelper,
1863
+ j as AisHelper,
1851
1864
  R as GeoJsonHelper,
1852
- v as LaneHelper,
1865
+ y as LaneHelper,
1853
1866
  d as LngLatHelper,
1854
- z as TropicalHelper
1867
+ X as TropicalHelper
1855
1868
  };
@@ -1,6 +1,6 @@
1
- (function($,I){typeof exports=="object"&&typeof module<"u"?I(exports,require("@turf/turf"),require("moment"),require("@log4js-node/log4js-api"),require("moment-timezone"),require("tz-lookup"),require("shpjs")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","@log4js-node/log4js-api","moment-timezone","tz-lookup","shpjs"],I):($=typeof globalThis<"u"?globalThis:$||self,I($["idm-plugin-rabbitmq"]={},$["@turf/turf"],$.moment,$["@log4js-node/log4js-api"],$["moment-timezone"],$["tz-lookup"],$.shpjs))})(this,function($,I,b,B,Z,q,W){"use strict";function U(C){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(C){for(const t in C)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(C,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>C[t]})}}return e.default=C,Object.freeze(e)}const f=U(I);class d{static guessTimeZoneOffset(e,t){e=d.convertToStdLng(e);const n=q(t,e),i=b().tz(n).utcOffset();return d.roundPrecision(i/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=d.convertToStdLng(e,t);let i="E";e<0&&(i="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,s,c,a,u,l;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,s=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),u=o/3600,n.indexOf("M")!==-1?l=d.roundPrecision(u,t).toString().padStart(3,"0"):l=d.padNumber(u,3,6),Number(s)>=60&&(a=Number(a)+1,s=0),Number(a)>=60&&(l=Number(l)+1,a=0);const g=`${n.replace(/S+/gi,s).replace(/M+/gi,a).replace(/H+/gi,l)}${i}`;return{direction:i,degree:d.roundPrecision(u,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:s,M:a,H:l}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let i="N";e<0&&(i="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,s,c,a,u,l;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,s=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),u=o/3600,n.indexOf("M")!==-1?l=d.roundPrecision(u,t).toString().padStart(2,"0"):l=d.padNumber(u,2,6),Number(s)>=60&&(a=Number(a)+1,s=0),Number(a)>=60&&(l=Number(l)+1,a=0);const g=`${n.replace(/S+/gi,s).replace(/M+/gi,a).replace(/H+/gi,l)}${i}`;return{direction:i,degree:d.roundPrecision(u,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:s,M:a,H:l}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LNG");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,s,c]=o;if(s=s||0,s=s>60?s/Math.pow(10,String(s).length-2):s,c=c||0,c=c>60?c/Math.pow(10,String(c).length-2):c,r>360&&!s){const a=this.roundPrecision(r/100,0);s=r-a*100,r=a}n=r+s/60+c/3600,i==="W"&&(n=n*-1)}else n=Number(e);return d.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LAT");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,s,c]=o;if(c=c||0,s=s||0,s=s>60?s/Math.pow(10,String(s).length-2):s,c=c>60?c/Math.pow(10,String(c).length-2):c,r>90&&!s){const a=this.roundPrecision(r/100,0);s=r-a*100,r=a}if(n=r+s/60+c/3600,n>90)throw new Error(`latitude out of range: ${e}${i}`);i==="S"&&(n=n*-1)}else n=Number(e);return d.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=d.strReplace(e,n);const i=e[e.length-1].toUpperCase();return["N","S"].includes(i)?{lat:d.str2Lat(e,t)}:{lng:d.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),d.roundPrecision(e,t)}static roundPrecision(e,t=6){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}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(/([0-9]+)-([0-9]+\.[0-9]+)/g,"$1 $2").replace(/°/," ").replace(/(\d+)-(\d?)/g,"$1 $2").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 i=e,o=Number(i.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${i}E`:o<=-90?e=`${i}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${i}${o>0?"E":"W"}`:e=`${i}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const i=d.roundPrecision(e-Math.trunc(e),n),o=i>=1?Math.trunc(e+1).toString().padStart(t,"0"):Math.trunc(e).toString().padStart(t,"0");return i>=1?o:n>0?`${o}.${Math.trunc(i*Math.pow(10,n)).toString().padStart(n,"0")}`:o}}class F{static json2Str(e){const t=e.type?e.type[0].toUpperCase():"A";return`${e.lat}|${e.lng}|${e.positionTime}|${e.sog}|${e.cog}|${e.hdg}|${e.draught}|${t}|${JSON.stringify(e.meteo||{})}|${e.vendor}|${e.deleted}`}static str2Json(e){const[t,n,i,o,r,s,c,a,u,l,g]=e.split("|");return{lat:Number(t),lng:Number(n),positionTime:Number(i),sog:Number(o),cog:Number(r),hdg:Number(s),draught:isNaN(c)?null:Number(c),type:a,important:a!=="A",meteo:u?JSON.parse(u):void 0,vendor:l,deleted:g==="true"}}static inspectStoppages(e,t=1,n=!0){const i=e.at(0).positionTime<e.at(-1).positionTime;i||e.sort((c,a)=>c.positionTime-a.positionTime);const o=[];let r,s;for(let c=0;c<e.length-1;c++){const a=e[c];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let u=c+1;u<e.length;u++){const l=e[u-1],g=e[u];if(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))continue;const h=g.positionTime-l.positionTime;if(y.calculateDistance(g,l,!0,4)/(h/3600)<t)r||(r=a),u===e.length-1&&(s=g,c=u);else{r&&(s=e[u-1],c=u);break}}if((s==null?void 0:s.positionTime)>(r==null?void 0:r.positionTime)&&r){const u={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:b.unix(r.positionTime).utc().format()},end:{lat:s.lat,lng:s.lng,sog:s.sog,positionTime:s.positionTime,utc:b.unix(s.positionTime).utc().format()},duration:s.positionTime-r.positionTime},l=e.filter(h=>h.positionTime>=u.start.positionTime&&h.positionTime<=u.end.positionTime),g=y.divideAccordingToLng(l);u.distance=y.calculateRouteDistance(g),u.hours=Math.round(u.duration/3600*10)/10,u.avgSog=Math.round(u.distance/u.hours*10)/10,o.push(u)}r=void 0,s=void 0}}return i||e.sort((c,a)=>a.positionTime-c.positionTime),o}static inspectSummary(e,t,n){const i=b(t),o=b(n),r=e.filter(u=>u.positionTime>=i.unix()&&u.positionTime<=o.unix());let s=0,c=0;if(r.length>1)for(let u=0;u<r.length-1;u++){const l=r[u],g=r[u+1];s+=y.calculateDistance(l,g,!0,4),c+=Math.abs(g.positionTime-l.positionTime)}s=Math.round(s*100)/100,c=Math.round(c/3600*100)/100;const a=c?Math.round(s/c*100)/100:0;return{distance:s,interval:c,avgSpd:a}}}let A;try{A=B.getLogger("meteo")}catch{}finally{}class y{static calculateBearing(e,t,n=!0,i=4){const o=f.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=f.rhumbBearing(o.features[0],o.features[1]):r=f.bearing(o.features[0],o.features[1]),r<0&&(r+=360),d.roundPrecision(r,i)}static calculateDistance(e,t,n=!0,i=4,o="nauticalmiles"){e={...e},t={...t},e.lng=d.convertToStdLng(e.lng,i),t.lng=d.convertToStdLng(t.lng,i);const r=f.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=f.rhumbDistance(r.features[0],r.features[1],{units:o}):s=f.distance(r.features[0],r.features[1],{units:o}),d.roundPrecision(s,i)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let i=0,o;for(const r of e)for(let s=0;s<r.length-1;s++){const c={lng:r[s][0],lat:r[s][1]};s===0&&o&&(i+=this.calculateDistance(o,c,!0,t,n));const a={lng:r[s+1][0],lat:r[s+1][1]};i+=this.calculateDistance(c,a,!0,t,n),o=a}return d.roundPrecision(i,t)}static calculateCoordinate(e,t,n,i="nauticalmiles",o=!0){const r=f.point([e.lng,e.lat]);let s;o?s=f.rhumbDestination(r,n,t,{units:i}):s=f.destination(r,n,t,{units:i});const c=s.geometry.coordinates;return{lng:d.convertToStdLng(c[0],8),lat:d.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,i=!0,o=!0,r="nauticalmiles"){const s=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,r);i&&s.push({lng:e.lng,lat:e.lat});let u=0;for(;u<a;)u+=n,u<a&&s.push(this.calculateCoordinate(e,c,u,r,!1));return o&&s.push({lng:t.lng,lat:t.lat}),s}static divideAccordingToLng(e,t=!1,n=!0){if((e==null?void 0:e.length)<2)return[];e=n?this.deduplicateCoordinates(e):e;let i=[];const o=[];let r,s;for(let c=0;c<e.length-1;c++){r=d.convertToStdLng(e[c].lng,8),s=d.convertToStdLng(e[c+1].lng,8),e[c].lat=d.roundPrecision(e[c].lat,8),e[c+1].lat=d.roundPrecision(e[c+1].lat,8),i.push([r,e[c].lat]);const a=r-s;if(Math.abs(a)>180){const u=d.convertToMonotonicLng2([[r,e[c].lat],[s,e[c+1].lat]]);let l,g;t?(l=f.lineString(u),g=f.lineString([[a>0?180:-180,89],[a>0?180:-180,-89]])):(l=f.greatCircle(u[0],u[1]),g=f.greatCircle([a>0?180:-180,89],[a>0?180:-180,-89]));const h=f.lineIntersect(l,g);let m;if(h.features.length){const T=f.getCoord(h.features[0]);m=d.roundPrecision(T[1],8)}else m=e[c].lat;a>0?(i.push([180-1e-6,m]),o.push([...i]),i=[],i.push([-(180-1e-6),m])):(i.push([-(180-1e-6),m]),o.push([...i]),i=[],i.push([180-1e-6,m]))}c===e.length-2&&i.push([s,e[c+1].lat])}return o.push(i),o}static deduplicateRoute(e){const t=[];for(const n of e){const i=n.reduce((o,r)=>(o.findIndex(s=>s[0]===r[0]&&s[1]===r[1])===-1&&o.push(r),o),[]);t.push(i)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(i=>i.lat===n.lat&&i.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);for(const n of t)for(let i=n.length-1;i>=0;i--)d.roundPrecision(n[i][0],8)===e.lng&&d.roundPrecision(n[i][1],8)===d.roundPrecision(e.lat,8)&&n.splice(i,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=d.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)d.roundPrecision(t[n].lng,8)===e.lng&&d.roundPrecision(t[n].lat,8)===d.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,i=0,o=0,r,s;return t.forEach((c,a)=>{for(let u=0;u<c.length-1;u++){const l={lng:c[u][0],lat:c[u][1]},g={lng:c[u+1][0],lat:c[u+1][1]},h=this.calculatePointToLineDistance(e,l,g);n>h&&(n=h,o=u,i=a,r=this.calculateDistance(l,e),s=this.calculateDistance(g,e))}}),r!==0&&s!==0?t[i].splice(o+1,0,[e.lng,e.lat]):r===0?t[i].splice(o,1,[e.lng,e.lat]):s===0&&t[i].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);const n=y.convertRouteToCoordinates(t);return n.push(e),y.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=y.convertRouteToCoordinates(t);return n.unshift(e),y.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 i=[];let o=0;return n.forEach(r=>{if(o===2)return;const s=[];for(const c of r){if(d.roundPrecision(t.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(c[1],8)){s.push(c),o===0&&s.push([e.lng,e.lat]),o=2;break}o===1?s.push(c):d.roundPrecision(e.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(c[1],8)&&(o=1,s.push(c))}s.length&&i.push(s)}),i}static calculateRangeWaypoints(e,t,n,i=[]){const o=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([e,t],o.length?o:i),s=r.findIndex(u=>d.roundPrecision(e.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(u.lat,8)),c=r.findIndex(u=>d.roundPrecision(t.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(u.lat,8));return r.filter((u,l)=>l>=s&&l<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,i=0,o=0;return t.forEach((r,s)=>{for(let c=0;c<r.length-1;c++){const a={lng:r[c][0],lat:r[c][1]},u={lng:r[c+1][0],lat:r[c+1][1]},l=this.calculatePointToLineDistance(e,a,u);n>l&&(n=l,i=c,o=s)}}),{minDist:n,segIndex:o,minIndex:i}}static calculateSubRoute(e,t){const n=y.convertRouteToCoordinates(t);y.mergeCoordinateToWaypoints(e,n,!0),t=y.divideAccordingToLng(n);const{segIndex:i,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=d.convertToStdLng(e.lng);const r=[];let s=!0;for(let c=i;c<t.length;c++)if(s){const a=[];a.push([e.lng,e.lat]);for(let u=o+1;u<t[c].length;u++)e.lng===t[c][u][0]&&e.lat===t[c][u][1]||a.push(t[c][u]);r.push(a),s=!1}else r.push([...t[c]]);return r}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,i=0;for(let r=0;r<t.length-1;r++){const s=t[r],c=t[r+1];if(this.calculateDistance(e,s)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((u,l)=>l>0);const a=this.calculatePointToLineDistance(e,s,c);n>a&&(n=a,i=r)}e.lng=d.convertToStdLng(e.lng);const o=[e];for(let r=i+1;r<t.length;r++)o.push(t[r]);return o}static calculatePointToLineDistance(e,t,n,i={units:"nauticalmiles",method:"geodesic"}){e.lng=d.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=d.convertToStdLng(t.lng,8),n.lng=d.convertToStdLng(n.lng,8);const o=d.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const r=f.lineString([[t.lng,t.lat],[n.lng,n.lat]]),s=f.pointToLineDistance(f.point([e.lng,e.lat]),r,i),c=f.pointToLineDistance(f.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),r,i);return d.roundPrecision(Math.min(s,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const i=e[n],o=e[n+1],r=this.calculateRangeRoute(i,o,t);n===0&&(i.distanceFromPrevious=0,i.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(r),o.distanceFromStart=d.roundPrecision((i.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const i of e)this.mergeCoordinateToWaypoints(i,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=d.convertToStdLng(e.lng,8);let i=Number.MAX_VALUE,o=0,r=0,s=0;if(t.length<2)t.push(e);else{for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},u={lng:t[c+1].lng,lat:t[c+1].lat},l=this.calculatePointToLineDistance(e,a,u);i>=l&&(i=l,o=c,r=this.calculateDistance(a,e,!1,6),s=this.calculateDistance(u,e,!1,6))}r!==0&&s!==0?r<=i&&o===0?t.unshift(e):s<=i&&o===t.length-2?t.push(e):t.splice(o+1,0,e):r===0?n?t.splice(o,1,e):t.splice(o+1,0,e):s===0&&(n?t.splice(o+1,1,e):t.splice(o+1,0,e))}return t.map((c,a)=>{c.lng=d.convertToStdLng(c.lng);const u=t[a+1];if(u&&((c.bearing===null||c.bearing===void 0)&&((c.positionTime||0)>(u.positionTime||0)?c.bearing=this.calculateBearing(u,c,!0):c.bearing=this.calculateBearing(c,u,!0)),c.cog=c.cog||c.bearing,!c.sog&&c.positionTime&&u.positionTime)){const l=this.calculateDistance(c,u,!0),g=Math.abs(u.positionTime-c.positionTime)/3600;c.sog=d.roundPrecision(l/g,2)}return c})}static generateRouteAccordingToWaypoints(e,t=!0,n=!0){const i=[];for(let o=1;o<e.length;o++){const r=e[o-1],s=e[o];if(o===1&&i.push(r),s.gcToPrevious){const c=this.interpolateCoordinates(r,s,200,!1,!0,"nauticalmiles");i.push(...c)}else i.push(s)}return this.divideAccordingToLng(i,t,n)}static nearestCoordinateInRoute(e,t){const n=f.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),r=f.lineString(o),s=f.nearestPointOnLine(r,n),c=f.getCoord(s);return{lng:d.roundPrecision(c[0],8),lat:d.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let i=0;i<t.length-1;i++){const o=t[i],r=t[i+1];if(this.calculateDistance(e,o)===0){n=i;break}if(this.calculateDistance(e,r)===0){n=i+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,i="nauticalmiles"){var g;const o=e.speed||12,r=[];let s=[],c=!1,a=0,u=0,l;if(t&&n.length?(r.push(e),n.forEach((h,m)=>{if(c)s.push(h);else{const T=[];let p;for(let v=0;v<h.length;v++)if(l)T.push(h[v]);else{p={lng:h[v][0],lat:h[v][1]};const P=this.calculateDistance(e,p,!0,8,i);if(a+=P,a<t)u+=P,P&&r.push(p),e=p;else{if(u=t,a===t)l=p,T.push([l.lng,l.lat]);else{const M=a-t,S=this.calculateBearing(p,e);l=this.calculateCoordinate(p,S,M,i),T.push([l.lng,l.lat]),T.push([p.lng,p.lat])}c=!0}}T.length&&s.push(T),m===n.length-1&&!l&&(l=p)}})):(s=n,l={...e}),l)if(r.push(l),l.distanceFromPrevious=Math.round(u*1e4)/1e4,l.hourFromPrevious=Math.round(u/o*1e4)/1e4,((g=s[0])==null?void 0:g.length)>1){const h={lng:s[0][1][0],lat:s[0][1][1]};l.bearing=this.calculateBearing(l,h)}else l.bearing=0;return{coordinate:l,nextRoute:s,prevRoute:r}}static nearestCoordinateInLine(e,t,n){const i=d.convertToStdLng(e.lng,6),o=f.point([i,e.lat]),r=d.convertToStdLng(t.lng,6),s=d.convertToStdLng(n.lng,6),c=f.lineString([[r,t.lat],[s,n.lat]]),a=f.nearestPointOnLine(c,o),u=f.getCoord(a),l=d.roundPrecision(u[0],6),g=d.roundPrecision(u[1],6);return{lng:l,lat:g,inline:!(l===r&&g===t.lat)&&!(l===s&&g===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let i,o;return e.forEach(r=>{r.forEach(s=>{const c={lng:d.roundPrecision(s[0],8),lat:d.roundPrecision(s[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0||o.bearing===null)o.bearing=this.calculateBearing(o,c,!0);else{const a=this.calculateDistance(i,c,!0);a&&a>=t&&(i.bearing=this.calculateBearing(i,c,!0),n.push(i),o=i)}i=c})}),i&&n.push(i),n}static simplifyRouteToCoordinates(e,t,n=1){let i=this.convertRouteToCoordinates(e,n);return i=this.simplifyGCCoordinates(i,t),i}static simplifyGCCoordinates(e,t){t.forEach(i=>{this.mergeCoordinateToWaypoints(i,e,!0)});for(let i=1;i<t.length;i++){const o=t[i-1],r=t[i];if(r.gcToPrevious){const s=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=e.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=c-1;a>s;a--)e.splice(a,1)}}let n=0;for(let i=1;i<e.length;i++){const o=e[i-1],r=e[i];r.gcToPrevious?(o.bearing=this.calculateBearing(o,r,!1),r.distanceFromPrevious=this.calculateDistance(o,r,!1)):(o.bearing=this.calculateBearing(o,r,!0),r.distanceFromPrevious=this.calculateDistance(o,r,!0)),n=d.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return e.map(i=>(i.lng=d.convertToStdLng(i.lng),i))}static calculateCenter(e){const t=[];for(const s of e)for(const c of s)t.push(c);const n=f.featureCollection([]),i=d.convertToMonotonicLng2(t);for(const s of i)n.features.push(f.point(s));const r=f.center(n).geometry.coordinates;return{lng:d.convertToStdLng(r[0],8),lat:d.roundPrecision(r[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const r of o)t.push(r);const n=d.convertToMonotonicLng2(t),i=f.lineString(n);return f.bbox(i)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}static simplifyCoordinates(e,t=1,n=180){const i=[];for(let o=1;o<e.length;o++){const r=e[o-1],s=e[o],c=e[o+1];let a=!1,u=!1;if((r.velocity||r.suspend||r.important||r.pilot||o===1)&&(a=!0,i.push(r)),s.gcToPrevious&&(a||(a=!0,i.push(r)),u=!0,i.push(s),o++),c){const l=y.calculateDistance(r,s,!0),g=y.calculateDistance(s,c,!0),h=y.calculateDistance(r,c,!0),m=(Math.pow(l,2)+Math.pow(g,2)-Math.pow(h,2))/(2*l*g);Math.round(Math.acos(m)*180/Math.PI)<n&&h>t&&!u&&(i.push(s),o++)}if(o>=e.length-1){const l=e.at(-1);l&&i.push(l)}}return i}static nearestTSPointInWaypoints(e,t,n){const i=b.unix(e),o=n.filter(r=>i.clone().subtract(t,"hour").unix()<=(r.positionTime||0)&&i.clone().add(t,"h").unix()>=(r.positionTime||0));return o.sort((r,s)=>(r.positionTime||0)-(s.positionTime||0)),o.at(-1)}static deadReckoning(e,t){var o,r,s,c;e>1e12&&(e=Math.round(e/1e3));const n=b.unix(e);let i=t.find(a=>a.positionTime===n.unix());if(!i){const a=(r=(o=t.filter(l=>(l==null?void 0:l.positionTime)<n.unix()))==null?void 0:o.sort((l,g)=>(l.positionTime||0)-(g.positionTime||0)))==null?void 0:r.at(-1),u=(c=(s=t.filter(l=>(l==null?void 0:l.positionTime)>n.unix()))==null?void 0:s.sort((l,g)=>(l.positionTime||0)-(g.positionTime||0)))==null?void 0:c.at(0);if(a&&u){const l=y.calculateBearing(a,u,!0),g=y.calculateDistance(a,u),h=(n.unix()-a.positionTime)/(u.positionTime-a.positionTime);i=y.calculateCoordinate(a,l,g*h),i.positionTime=n.unix(),i.utc=n.utc().format(),i.cog=l,i.sog=Math.round(g/((u.positionTime-a.positionTime)/3600)*100)/100}else i=a||u,i&&(i.utc=b.unix(i==null?void 0:i.positionTime).utc().format())}return i}static deadReckoningTime(e,t){t=JSON.parse(JSON.stringify(t)),t.sort((a,u)=>(a.positionTime||0)-(u.positionTime||0));let n=Number.MAX_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER;for(let a=0;a<t.length-1;a++){const u=t[a],l=t[a+1],g=y.calculatePointToLineDistance(e,u,l);g<n&&(n=g,i=a)}const o=t[i],r=t[i+1],s=y.calculateDistance(o,e),c=y.calculateDistance(r,e);if(s===0)e=o;else if(c===0)e=r;else{const a=o.positionTime||0,u=r.positionTime||0,l=y.calculateDistance(o,r);e.positionTime=Math.round(a+(u-a)*(s/l))}return e.utc=e.positionTime?b.unix(e.positionTime).utc().format():void 0,e.positionTime?e:void 0}static reverseRoute(e){const t=[];for(const n of e)t.push(n.reverse());return t}static reverseCoordinates(e){return e.reverse()}static xmlEscape(e){return e==null?"":String(e).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(e,t){const i=[];return i.push('<?xml version="1.0" encoding="UTF-8"?>'),i.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'),i.push(` <routeInfo routeName="${y.xmlEscape(e)}"></routeInfo>`),i.push(...y.toRTZWaypoints(t,6)),i.push("</route>"),i.join(`
1
+ (function($,I){typeof exports=="object"&&typeof module<"u"?I(exports,require("@turf/turf"),require("moment"),require("@log4js-node/log4js-api"),require("moment-timezone"),require("tz-lookup"),require("shpjs")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","@log4js-node/log4js-api","moment-timezone","tz-lookup","shpjs"],I):($=typeof globalThis<"u"?globalThis:$||self,I($["idm-plugin-rabbitmq"]={},$["@turf/turf"],$.moment,$["@log4js-node/log4js-api"],$["moment-timezone"],$["tz-lookup"],$.shpjs))})(this,function($,I,b,F,J,U,L){"use strict";function z(C){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(C){for(const t in C)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(C,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>C[t]})}}return e.default=C,Object.freeze(e)}const h=z(I);class d{static guessTimeZoneOffset(e,t){e=d.convertToStdLng(e);const n=U(t,e),i=b().tz(n).utcOffset();return d.roundPrecision(i/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=d.convertToStdLng(e,t);let i="E";e<0&&(i="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,s,c,a,u,l;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,s=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),u=o/3600,n.indexOf("M")!==-1?l=d.roundPrecision(u,t).toString().padStart(3,"0"):l=d.padNumber(u,3,6),Number(s)>=60&&(a=Number(a)+1,s=0),Number(a)>=60&&(l=Number(l)+1,a=0);const g=`${n.replace(/S+/gi,s).replace(/M+/gi,a).replace(/H+/gi,l)}${i}`;return{direction:i,degree:d.roundPrecision(u,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:s,M:a,H:l}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let i="N";e<0&&(i="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,s,c,a,u,l;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,s=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),u=o/3600,n.indexOf("M")!==-1?l=d.roundPrecision(u,t).toString().padStart(2,"0"):l=d.padNumber(u,2,6),Number(s)>=60&&(a=Number(a)+1,s=0),Number(a)>=60&&(l=Number(l)+1,a=0);const g=`${n.replace(/S+/gi,s).replace(/M+/gi,a).replace(/H+/gi,l)}${i}`;return{direction:i,degree:d.roundPrecision(u,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:s,M:a,H:l}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LNG");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,s,c]=o;if(s=s||0,s=s>60?s/Math.pow(10,String(s).length-2):s,c=c||0,c=c>60?c/Math.pow(10,String(c).length-2):c,r>360&&!s){const a=this.roundPrecision(r/100,0);s=r-a*100,r=a}n=r+s/60+c/3600,i==="W"&&(n=n*-1)}else n=Number(e);return d.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LAT");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,s,c]=o;if(c=c||0,s=s||0,s=s>60?s/Math.pow(10,String(s).length-2):s,c=c>60?c/Math.pow(10,String(c).length-2):c,r>90&&!s){const a=this.roundPrecision(r/100,0);s=r-a*100,r=a}if(n=r+s/60+c/3600,n>90)throw new Error(`latitude out of range: ${e}${i}`);i==="S"&&(n=n*-1)}else n=Number(e);return d.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=d.strReplace(e,n);const i=e[e.length-1].toUpperCase();return["N","S"].includes(i)?{lat:d.str2Lat(e,t)}:{lng:d.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),d.roundPrecision(e,t)}static roundPrecision(e,t=6){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}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(/([0-9]+)-([0-9]+\.[0-9]+)/g,"$1 $2").replace(/°/," ").replace(/(\d+)-(\d?)/g,"$1 $2").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 i=e,o=Number(i.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${i}E`:o<=-90?e=`${i}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${i}${o>0?"E":"W"}`:e=`${i}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const i=d.roundPrecision(e-Math.trunc(e),n),o=i>=1?Math.trunc(e+1).toString().padStart(t,"0"):Math.trunc(e).toString().padStart(t,"0");return i>=1?o:n>0?`${o}.${Math.trunc(i*Math.pow(10,n)).toString().padStart(n,"0")}`:o}}class B{static json2Str(e){const t=e.type?e.type[0].toUpperCase():"A";return`${e.lat}|${e.lng}|${e.positionTime}|${e.sog}|${e.cog}|${e.hdg}|${e.draught}|${t}|${JSON.stringify(e.meteo||{})}|${e.vendor}|${e.deleted}`}static str2Json(e){const[t,n,i,o,r,s,c,a,u,l,g]=e.split("|");return{lat:Number(t),lng:Number(n),positionTime:Number(i),sog:Number(o),cog:Number(r),hdg:Number(s),draught:isNaN(c)?null:Number(c),type:a,important:a!=="A",meteo:u?JSON.parse(u):void 0,vendor:l,deleted:g==="true"}}static inspectStoppages(e,t=1,n=!0){const i=e.at(0).positionTime<e.at(-1).positionTime;i||e.sort((c,a)=>c.positionTime-a.positionTime);const o=[];let r,s;for(let c=0;c<e.length-1;c++){const a=e[c];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let u=c+1;u<e.length;u++){const l=e[u-1],g=e[u];if(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))continue;const f=g.positionTime-l.positionTime;if(y.calculateDistance(g,l,!0,4)/(f/3600)<t)r||(r=a),u===e.length-1&&(s=g,c=u);else{r&&(s=e[u-1],c=u);break}}if((s==null?void 0:s.positionTime)>(r==null?void 0:r.positionTime)&&r){const u={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:b.unix(r.positionTime).utc().format()},end:{lat:s.lat,lng:s.lng,sog:s.sog,positionTime:s.positionTime,utc:b.unix(s.positionTime).utc().format()},duration:s.positionTime-r.positionTime},l=e.filter(f=>f.positionTime>=u.start.positionTime&&f.positionTime<=u.end.positionTime),g=y.divideAccordingToLng(l);u.distance=y.calculateRouteDistance(g),u.hours=Math.round(u.duration/3600*10)/10,u.avgSog=Math.round(u.distance/u.hours*10)/10,o.push(u)}r=void 0,s=void 0}}return i||e.sort((c,a)=>a.positionTime-c.positionTime),o}static inspectSummary(e,t,n){const i=b(t),o=b(n),r=e.filter(u=>u.positionTime>=i.unix()&&u.positionTime<=o.unix());let s=0,c=0;if(r.length>1)for(let u=0;u<r.length-1;u++){const l=r[u],g=r[u+1];s+=y.calculateDistance(l,g,!0,4),c+=Math.abs(g.positionTime-l.positionTime)}s=Math.round(s*100)/100,c=Math.round(c/3600*100)/100;const a=c?Math.round(s/c*100)/100:0;return{distance:s,interval:c,avgSpd:a}}}let A;try{A=F.getLogger("meteo")}catch{}finally{}class y{static calculateBearing(e,t,n=!0,i=4){const o=h.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=h.rhumbBearing(o.features[0],o.features[1]):r=h.bearing(o.features[0],o.features[1]),r<0&&(r+=360),d.roundPrecision(r,i)}static calculateDistance(e,t,n=!0,i=4,o="nauticalmiles"){e={...e},t={...t},e.lng=d.convertToStdLng(e.lng,i),t.lng=d.convertToStdLng(t.lng,i);const r=h.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=h.rhumbDistance(r.features[0],r.features[1],{units:o}):s=h.distance(r.features[0],r.features[1],{units:o}),d.roundPrecision(s,i)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let i=0,o;for(const r of e)for(let s=0;s<r.length-1;s++){const c={lng:r[s][0],lat:r[s][1]};s===0&&o&&(i+=this.calculateDistance(o,c,!0,t,n));const a={lng:r[s+1][0],lat:r[s+1][1]};i+=this.calculateDistance(c,a,!0,t,n),o=a}return d.roundPrecision(i,t)}static calculateCoordinate(e,t,n,i="nauticalmiles",o=!0){const r=h.point([e.lng,e.lat]);let s;o?s=h.rhumbDestination(r,n,t,{units:i}):s=h.destination(r,n,t,{units:i});const c=s.geometry.coordinates;return{lng:d.convertToStdLng(c[0],8),lat:d.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,i=!0,o=!0,r="nauticalmiles"){const s=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,r);i&&s.push({lng:e.lng,lat:e.lat});let u=0;for(;u<a;)u+=n,u<a&&s.push(this.calculateCoordinate(e,c,u,r,!1));return o&&s.push({lng:t.lng,lat:t.lat}),s}static divideAccordingToLng(e,t=!1,n=!0){if((e==null?void 0:e.length)<2)return[];e=n?this.deduplicateCoordinates(e):e;let i=[];const o=[];let r,s;for(let c=0;c<e.length-1;c++){r=d.convertToStdLng(e[c].lng,8),s=d.convertToStdLng(e[c+1].lng,8),e[c].lat=d.roundPrecision(e[c].lat,8),e[c+1].lat=d.roundPrecision(e[c+1].lat,8),i.push([r,e[c].lat]);const a=r-s;if(Math.abs(a)>180){const u=d.convertToMonotonicLng2([[r,e[c].lat],[s,e[c+1].lat]]);let l,g;t?(l=h.lineString(u),g=h.lineString([[a>0?180:-180,89],[a>0?180:-180,-89]])):(l=h.greatCircle(u[0],u[1]),g=h.greatCircle([a>0?180:-180,89],[a>0?180:-180,-89]));const f=h.lineIntersect(l,g);let T;if(f.features.length){const S=h.getCoord(f.features[0]);T=d.roundPrecision(S[1],8)}else T=e[c].lat;a>0?(i.push([180-1e-6,T]),o.push([...i]),i=[],i.push([-(180-1e-6),T])):(i.push([-(180-1e-6),T]),o.push([...i]),i=[],i.push([180-1e-6,T]))}c===e.length-2&&i.push([s,e[c+1].lat])}return o.push(i),o}static deduplicateRoute(e){const t=[];for(const n of e){const i=n.reduce((o,r)=>(o.findIndex(s=>s[0]===r[0]&&s[1]===r[1])===-1&&o.push(r),o),[]);t.push(i)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(i=>i.lat===n.lat&&i.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);for(const n of t)for(let i=n.length-1;i>=0;i--)d.roundPrecision(n[i][0],8)===e.lng&&d.roundPrecision(n[i][1],8)===d.roundPrecision(e.lat,8)&&n.splice(i,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=d.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)d.roundPrecision(t[n].lng,8)===e.lng&&d.roundPrecision(t[n].lat,8)===d.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,i=0,o=0,r,s;return t.forEach((c,a)=>{for(let u=0;u<c.length-1;u++){const l={lng:c[u][0],lat:c[u][1]},g={lng:c[u+1][0],lat:c[u+1][1]},f=this.calculatePointToLineDistance(e,l,g);n>f&&(n=f,o=u,i=a,r=this.calculateDistance(l,e),s=this.calculateDistance(g,e))}}),r!==0&&s!==0?t[i].splice(o+1,0,[e.lng,e.lat]):r===0?t[i].splice(o,1,[e.lng,e.lat]):s===0&&t[i].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);const n=y.convertRouteToCoordinates(t);return n.push(e),y.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=y.convertRouteToCoordinates(t);return n.unshift(e),y.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 i=[];let o=0;return n.forEach(r=>{if(o===2)return;const s=[];for(const c of r){if(d.roundPrecision(t.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(c[1],8)){s.push(c),o===0&&s.push([e.lng,e.lat]),o=2;break}o===1?s.push(c):d.roundPrecision(e.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(c[1],8)&&(o=1,s.push(c))}s.length&&i.push(s)}),i}static calculateRangeWaypoints(e,t,n,i=[]){const o=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([e,t],o.length?o:i),s=r.findIndex(u=>d.roundPrecision(e.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(u.lat,8)),c=r.findIndex(u=>d.roundPrecision(t.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(u.lat,8));return r.filter((u,l)=>l>=s&&l<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,i=0,o=0;return t.forEach((r,s)=>{for(let c=0;c<r.length-1;c++){const a={lng:r[c][0],lat:r[c][1]},u={lng:r[c+1][0],lat:r[c+1][1]},l=this.calculatePointToLineDistance(e,a,u);n>l&&(n=l,i=c,o=s)}}),{minDist:n,segIndex:o,minIndex:i}}static calculateSubRoute(e,t){const n=y.convertRouteToCoordinates(t);y.mergeCoordinateToWaypoints(e,n,!0),t=y.divideAccordingToLng(n);const{segIndex:i,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=d.convertToStdLng(e.lng);const r=[];let s=!0;for(let c=i;c<t.length;c++)if(s){const a=[];a.push([e.lng,e.lat]);for(let u=o+1;u<t[c].length;u++)e.lng===t[c][u][0]&&e.lat===t[c][u][1]||a.push(t[c][u]);r.push(a),s=!1}else r.push([...t[c]]);return r}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,i=0;for(let r=0;r<t.length-1;r++){const s=t[r],c=t[r+1];if(this.calculateDistance(e,s)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((u,l)=>l>0);const a=this.calculatePointToLineDistance(e,s,c);n>a&&(n=a,i=r)}e.lng=d.convertToStdLng(e.lng);const o=[e];for(let r=i+1;r<t.length;r++)o.push(t[r]);return o}static calculatePointToLineDistance(e,t,n,i={units:"nauticalmiles",method:"geodesic"}){e.lng=d.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=d.convertToStdLng(t.lng,8),n.lng=d.convertToStdLng(n.lng,8);const o=d.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const r=h.lineString([[t.lng,t.lat],[n.lng,n.lat]]),s=h.pointToLineDistance(h.point([e.lng,e.lat]),r,i),c=h.pointToLineDistance(h.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),r,i);return d.roundPrecision(Math.min(s,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const i=e[n],o=e[n+1],r=this.calculateRangeRoute(i,o,t);n===0&&(i.distanceFromPrevious=0,i.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(r),o.distanceFromStart=d.roundPrecision((i.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const i of e)this.mergeCoordinateToWaypoints(i,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=d.convertToStdLng(e.lng,8);let i=Number.MAX_VALUE,o=0,r=0,s=0;if(t.length<2)t.push(e);else{for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},u={lng:t[c+1].lng,lat:t[c+1].lat},l=this.calculatePointToLineDistance(e,a,u);i>=l&&(i=l,o=c,r=this.calculateDistance(a,e,!1,6),s=this.calculateDistance(u,e,!1,6))}r!==0&&s!==0?r<=i&&o===0?t.unshift(e):s<=i&&o===t.length-2?t.push(e):t.splice(o+1,0,e):r===0?n?t.splice(o,1,e):t.splice(o+1,0,e):s===0&&(n?t.splice(o+1,1,e):t.splice(o+1,0,e))}return t.map((c,a)=>{c.lng=d.convertToStdLng(c.lng);const u=t[a+1];if(u&&((c.bearing===null||c.bearing===void 0)&&((c.positionTime||0)>(u.positionTime||0)?c.bearing=this.calculateBearing(u,c,!0):c.bearing=this.calculateBearing(c,u,!0)),c.cog=c.cog||c.bearing,!c.sog&&c.positionTime&&u.positionTime)){const l=this.calculateDistance(c,u,!0),g=Math.abs(u.positionTime-c.positionTime)/3600;c.sog=d.roundPrecision(l/g,2)}return c})}static generateRouteAccordingToWaypoints(e,t=!0,n=!0){const i=[];for(let o=1;o<e.length;o++){const r=e[o-1],s=e[o];if(o===1&&i.push(r),s.gcToPrevious){const c=this.interpolateCoordinates(r,s,200,!1,!0,"nauticalmiles");i.push(...c)}else i.push(s)}return this.divideAccordingToLng(i,t,n)}static nearestCoordinateInRoute(e,t){const n=h.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),r=h.lineString(o),s=h.nearestPointOnLine(r,n),c=h.getCoord(s);return{lng:d.roundPrecision(c[0],8),lat:d.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let i=0;i<t.length-1;i++){const o=t[i],r=t[i+1];if(this.calculateDistance(e,o)===0){n=i;break}if(this.calculateDistance(e,r)===0){n=i+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,i="nauticalmiles"){var g;const o=e.speed||12,r=[];let s=[],c=!1,a=0,u=0,l;if(t&&n.length?(r.push(e),n.forEach((f,T)=>{if(c)s.push(f);else{const S=[];let p;for(let v=0;v<f.length;v++)if(l)S.push(f[v]);else{p={lng:f[v][0],lat:f[v][1]};const P=this.calculateDistance(e,p,!0,8,i);if(a+=P,a<t)u+=P,P&&r.push(p),e=p;else{if(u=t,a===t)l=p,S.push([l.lng,l.lat]);else{const M=a-t,m=this.calculateBearing(p,e);l=this.calculateCoordinate(p,m,M,i),S.push([l.lng,l.lat]),S.push([p.lng,p.lat])}c=!0}}S.length&&s.push(S),T===n.length-1&&!l&&(l=p)}})):(s=n,l={...e}),l)if(r.push(l),l.distanceFromPrevious=Math.round(u*1e4)/1e4,l.hourFromPrevious=Math.round(u/o*1e4)/1e4,((g=s[0])==null?void 0:g.length)>1){const f={lng:s[0][1][0],lat:s[0][1][1]};l.bearing=this.calculateBearing(l,f)}else l.bearing=0;return{coordinate:l,nextRoute:s,prevRoute:r}}static nearestCoordinateInLine(e,t,n){const i=d.convertToStdLng(e.lng,6),o=h.point([i,e.lat]),r=d.convertToStdLng(t.lng,6),s=d.convertToStdLng(n.lng,6),c=h.lineString([[r,t.lat],[s,n.lat]]),a=h.nearestPointOnLine(c,o),u=h.getCoord(a),l=d.roundPrecision(u[0],6),g=d.roundPrecision(u[1],6);return{lng:l,lat:g,inline:!(l===r&&g===t.lat)&&!(l===s&&g===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let i,o;return e.forEach(r=>{r.forEach(s=>{const c={lng:d.roundPrecision(s[0],8),lat:d.roundPrecision(s[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0||o.bearing===null)o.bearing=this.calculateBearing(o,c,!0);else{const a=this.calculateDistance(i,c,!0);a&&a>=t&&(i.bearing=this.calculateBearing(i,c,!0),n.push(i),o=i)}i=c})}),i&&n.push(i),n}static simplifyRouteToCoordinates(e,t,n=1){let i=this.convertRouteToCoordinates(e,n);return i=this.simplifyGCCoordinates(i,t),i}static simplifyGCCoordinates(e,t){t.forEach(i=>{this.mergeCoordinateToWaypoints(i,e,!0)});for(let i=1;i<t.length;i++){const o=t[i-1],r=t[i];if(r.gcToPrevious){const s=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=e.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=c-1;a>s;a--)e.splice(a,1)}}let n=0;for(let i=1;i<e.length;i++){const o=e[i-1],r=e[i];r.gcToPrevious?(o.bearing=this.calculateBearing(o,r,!1),r.distanceFromPrevious=this.calculateDistance(o,r,!1)):(o.bearing=this.calculateBearing(o,r,!0),r.distanceFromPrevious=this.calculateDistance(o,r,!0)),n=d.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return e.map(i=>(i.lng=d.convertToStdLng(i.lng),i))}static calculateCenter(e){const t=[];for(const s of e)for(const c of s)t.push(c);const n=h.featureCollection([]),i=d.convertToMonotonicLng2(t);for(const s of i)n.features.push(h.point(s));const r=h.center(n).geometry.coordinates;return{lng:d.convertToStdLng(r[0],8),lat:d.roundPrecision(r[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const r of o)t.push(r);const n=d.convertToMonotonicLng2(t),i=h.lineString(n);return h.bbox(i)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}static simplifyCoordinates(e,t=1,n=180){const i=[];for(let o=1;o<e.length;o++){const r=e[o-1],s=e[o],c=e[o+1];let a=!1,u=!1;if((r.velocity||r.suspend||r.important||r.pilot||o===1)&&(a=!0,i.push(r)),s.gcToPrevious&&(a||(a=!0,i.push(r)),u=!0,i.push(s),o++),c){const l=y.calculateDistance(r,s,!0),g=y.calculateDistance(s,c,!0),f=y.calculateDistance(r,c,!0),T=(Math.pow(l,2)+Math.pow(g,2)-Math.pow(f,2))/(2*l*g);Math.round(Math.acos(T)*180/Math.PI)<n&&f>t&&!u&&(i.push(s),o++)}if(o>=e.length-1){const l=e.at(-1);l&&i.push(l)}}return i}static nearestTSPointInWaypoints(e,t,n){const i=b.unix(e),o=n.filter(r=>i.clone().subtract(t,"hour").unix()<=(r.positionTime||0)&&i.clone().add(t,"h").unix()>=(r.positionTime||0));return o.sort((r,s)=>(r.positionTime||0)-(s.positionTime||0)),o.at(-1)}static deadReckoning(e,t){var o,r,s,c;e>1e12&&(e=Math.round(e/1e3));const n=b.unix(e);let i=t.find(a=>a.positionTime===n.unix());if(!i){const a=(r=(o=t.filter(l=>(l==null?void 0:l.positionTime)<n.unix()))==null?void 0:o.sort((l,g)=>(l.positionTime||0)-(g.positionTime||0)))==null?void 0:r.at(-1),u=(c=(s=t.filter(l=>(l==null?void 0:l.positionTime)>n.unix()))==null?void 0:s.sort((l,g)=>(l.positionTime||0)-(g.positionTime||0)))==null?void 0:c.at(0);if(a&&u){const l=y.calculateBearing(a,u,!0),g=y.calculateDistance(a,u),f=(n.unix()-a.positionTime)/(u.positionTime-a.positionTime);i=y.calculateCoordinate(a,l,g*f),i.positionTime=n.unix(),i.utc=n.utc().format(),i.cog=l,i.sog=Math.round(g/((u.positionTime-a.positionTime)/3600)*100)/100}else i=a||u,i&&(i.utc=b.unix(i==null?void 0:i.positionTime).utc().format())}return i}static deadReckoningTime(e,t){t=JSON.parse(JSON.stringify(t)),t.sort((a,u)=>(a.positionTime||0)-(u.positionTime||0));let n=Number.MAX_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER;for(let a=0;a<t.length-1;a++){const u=t[a],l=t[a+1],g=y.calculatePointToLineDistance(e,u,l);g<n&&(n=g,i=a)}const o=t[i],r=t[i+1],s=y.calculateDistance(o,e),c=y.calculateDistance(r,e);if(s===0)e=o;else if(c===0)e=r;else{const a=o.positionTime||0,u=r.positionTime||0,l=y.calculateDistance(o,r);e.positionTime=Math.round(a+(u-a)*(s/l))}return e.utc=e.positionTime?b.unix(e.positionTime).utc().format():void 0,e.positionTime?e:void 0}static reverseRoute(e){const t=[];for(const n of e)t.push(n.reverse());return t}static reverseCoordinates(e){return e.reverse()}static xmlEscape(e){return e==null?"":String(e).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(e,t){const i=[];return i.push('<?xml version="1.0" encoding="UTF-8"?>'),i.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'),i.push(` <routeInfo routeName="${y.xmlEscape(e)}"></routeInfo>`),i.push(...y.toRTZWaypoints(t,6)),i.push("</route>"),i.join(`
2
2
  `)}static waypoints2RTZ10(e,t,n=!0){const o=[];return o.push('<?xml version="1.0" encoding="UTF-8"?>'),o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'),o.push(` <routeInfo routeName="${y.xmlEscape(e)}"></routeInfo>`),o.push(...y.toRTZWaypoints(t,6,n)),o.push("</route>"),o.join(`
3
- `)}static toRTZWaypoints(e,t=6,n=!0){const i=[];i.push(" <waypoints>");for(let o=0;o<e.length;o++){const r=e[o],s=o+1,c=(r.lat??"").toFixed?r.lat.toFixed(t).padEnd(t+2,"0"):r.lat,a=(r.lng??"").toFixed?r.lng.toFixed(t).padEnd(t+2,"0"):r.lng,u=[`id="${s}"`,'revision="0"'];if(r.name&&u.push(`name="${y.xmlEscape(r.name)}"`),i.push(` <waypoint ${u.join(" ")}>`),i.push(` <position lat="${y.xmlEscape(c)}" lon="${y.xmlEscape(a)}" />`),o>0){const l=r.gcToPrevious?"Orthodrome":"Loxodrome";i.push(` <leg geometryType="${l}" />`)}if(n){const l=[];if(r.description&&l.push(` <description>${y.xmlEscape(r.description)}</description>`),r.utc)l.push(` <time>${y.xmlEscape(r.utc)}</time>`);else if(r.positionTime)try{l.push(` <time>${y.xmlEscape(b.unix(r.positionTime).utc().format())}</time>`)}catch{}r.cog!==void 0&&l.push(` <cog>${y.xmlEscape(r.cog)}</cog>`),r.sog!==void 0&&l.push(` <sog>${y.xmlEscape(r.sog)}</sog>`),l.length&&(i.push(" <extensions>"),i.push(...l),i.push(" </extensions>"))}i.push(" </waypoint>")}return i.push(" </waypoints>"),i}static waypoints2CSV(e,t,n){A.debug("keep name for waypoints2CSV for legacy compatibility only",e);const i=(n==null?void 0:n.precision)??6,o=t.some(p=>p.name),r=t.some(p=>p.description),s=t.some(p=>p.port!=null),c=t.some(p=>p.stbd!=null),a=t.some(p=>p.arrRad!=null),u=t.some(p=>p.speed!=null),l=t.some((p,v)=>v>0&&p.gcToPrevious!=null),g=t.some(p=>p.bearing!=null),h=t.some(p=>p.distanceFromPrevious!=null),m=["WPT No.","Latitude","Longitude"];o&&m.push("Name"),r&&m.push("Description"),l&&m.push("Leg"),g&&m.push("Bearing[deg]"),h&&m.push("Distance[NM]"),u&&m.push("Speed[kn]"),s&&m.push("PORT XTD[NM]"),c&&m.push("STBD XTD[NM]"),a&&m.push("Arr.Rad[NM]");const T=[];T.push(m.map(p=>y.csvEscapeField(p)).join(","));for(let p=0;p<t.length;p++){const v=t[p],P=[];P.push((p+1).toString()),P.push(v.lat.toFixed(i)),P.push(v.lng.toFixed(i)),o&&P.push(v.name??""),r&&P.push(v.description??""),l&&P.push(p===0?"":v.gcToPrevious?"GC":"RL"),g&&P.push(v.bearing!=null?String(v.bearing):""),h&&P.push(v.distanceFromPrevious!=null?String(v.distanceFromPrevious):""),u&&P.push(v.speed!=null?String(v.speed):""),s&&P.push(v.port!=null?String(v.port):""),c&&P.push(v.stbd!=null?String(v.stbd):""),a&&P.push(v.arrRad!=null?String(v.arrRad):""),T.push(P.map(M=>y.csvEscapeField(M)).join(","))}return T.join(`
3
+ `)}static toRTZWaypoints(e,t=6,n=!0){const i=[];i.push(" <waypoints>");for(let o=0;o<e.length;o++){const r=e[o],s=o+1,c=(r.lat??"").toFixed?r.lat.toFixed(t).padEnd(t+2,"0"):r.lat,a=(r.lng??"").toFixed?r.lng.toFixed(t).padEnd(t+2,"0"):r.lng,u=[`id="${s}"`,'revision="0"'];if(r.name&&u.push(`name="${y.xmlEscape(r.name)}"`),i.push(` <waypoint ${u.join(" ")}>`),i.push(` <position lat="${y.xmlEscape(c)}" lon="${y.xmlEscape(a)}" />`),o>0){const l=r.gcToPrevious?"Orthodrome":"Loxodrome";i.push(` <leg geometryType="${l}" />`)}if(n){const l=[];if(r.description&&l.push(` <description>${y.xmlEscape(r.description)}</description>`),r.utc)l.push(` <time>${y.xmlEscape(r.utc)}</time>`);else if(r.positionTime)try{l.push(` <time>${y.xmlEscape(b.unix(r.positionTime).utc().format())}</time>`)}catch{}r.cog!==void 0&&l.push(` <cog>${y.xmlEscape(r.cog)}</cog>`),r.sog!==void 0&&l.push(` <sog>${y.xmlEscape(r.sog)}</sog>`),l.length&&(i.push(" <extensions>"),i.push(...l),i.push(" </extensions>"))}i.push(" </waypoint>")}return i.push(" </waypoints>"),i}static waypoints2CSV(e,t,n){A.debug("keep name for waypoints2CSV for legacy compatibility only",e);const i=(n==null?void 0:n.precision)??6,o=t.some(p=>p.name),r=t.some(p=>p.description),s=t.some(p=>p.port!=null),c=t.some(p=>p.stbd!=null),a=t.some(p=>p.arrRad!=null),u=t.some(p=>p.speed!=null),l=t.some((p,v)=>v>0&&p.gcToPrevious!=null),g=t.some(p=>p.bearing!=null),f=t.some(p=>p.distanceFromPrevious!=null),T=["WPT No.","Latitude","Longitude"];o&&T.push("Name"),r&&T.push("Description"),l&&T.push("Leg"),g&&T.push("Bearing[deg]"),f&&T.push("Distance[NM]"),u&&T.push("Speed[kn]"),s&&T.push("PORT XTD[NM]"),c&&T.push("STBD XTD[NM]"),a&&T.push("Arr.Rad[NM]");const S=[];S.push(T.map(p=>y.csvEscapeField(p)).join(","));for(let p=0;p<t.length;p++){const v=t[p],P=[];P.push((p+1).toString()),P.push(v.lat.toFixed(i)),P.push(v.lng.toFixed(i)),o&&P.push(v.name??""),r&&P.push(v.description??""),l&&P.push(p===0?"":v.gcToPrevious?"GC":"RL"),g&&P.push(v.bearing!=null?String(v.bearing):""),f&&P.push(v.distanceFromPrevious!=null?String(v.distanceFromPrevious):""),u&&P.push(v.speed!=null?String(v.speed):""),s&&P.push(v.port!=null?String(v.port):""),c&&P.push(v.stbd!=null?String(v.stbd):""),a&&P.push(v.arrRad!=null?String(v.arrRad):""),S.push(P.map(M=>y.csvEscapeField(M)).join(","))}return S.join(`
4
4
  `)}static csvEscapeField(e){if(e==null)return"";const t=String(e);return t.includes(",")||t.includes('"')||t.includes(`
5
5
  `)||t.includes("\r")?`"${t.replace(/"/g,'""')}"`:t}static decimalToNmeaDm(e,t){const n=Math.abs(e),i=Math.floor(n),o=(n-i)*60,r=t?`${i.toString().padStart(2,"0")}${o.toFixed(2).padStart(5,"0")}`:`${i.toString().padStart(3,"0")}${o.toFixed(2).padStart(5,"0")}`,s=t?e>=0?"N":"S":e>=0?"E":"W";return{dm:r,dir:s}}static nmeaChecksum(e){let t=0;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n);return t.toString(16).toUpperCase().padStart(2,"0")}static waypoints2NMEA(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n],o=y.decimalToNmeaDm(i.lat,!0),r=y.decimalToNmeaDm(i.lng,!1),s=i.name?String(i.name).slice(0,6):`WPT${(n+1).toString().padStart(3,"0")}`,c=`GPWPL,${o.dm},${o.dir},${r.dm},${r.dir},${s}`,a=y.nmeaChecksum(c);t.push(`$${c}*${a}`)}return t.join(`\r
6
- `)}static coordinatesSummary(e,t=3){if(e.length>1){const n=e[0],i=e[e.length-1],o=(n==null?void 0:n.positionTime)<(i==null?void 0:i.positionTime)?b.unix(n==null?void 0:n.positionTime):b.unix(i==null?void 0:i.positionTime),r=(n==null?void 0:n.positionTime)>(i==null?void 0:i.positionTime)?b.unix(n==null?void 0:n.positionTime):b.unix(i==null?void 0:i.positionTime),s=Math.round(r.diff(o,"hours",!0)*100)/100,c=this.generateRouteAccordingToWaypoints(e,!0,!0),a=this.calculateRouteDistance(c),l=F.inspectStoppages(e,t).reduce((h,m)=>(h.duration+=m.duration,h.distance+=m.distance,h),{hours:0,distance:0,spd:0,duration:0});l.hours=Math.round(l.duration/3600*100)/100,l.distance=Math.round(l.distance*100)/100,l.spd=l.hours?Math.round(l.distance/l.hours*100)/100:0;const g=s?Math.round((a-l.distance)/(s-l.hours)*100)/100:0;return{begin:o.utc().format(),end:r.utc().format(),distance:Math.round((a-l.distance)*100)/100,hours:Math.round((s-l.hours)*100)/100,avgSpeed:g,stoppage:l}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(e,t){var u,l,g;if(!((l=(u=t==null?void 0:t.sample)==null?void 0:u.hours)!=null&&l.length))return{routes:[],hour:void 0};const n=t.sample.hours.at(0),i=b.utc(e),o=b.utc(t.eta),r=i.isAfter(o)?o:i;let s=t.sample.all.find(h=>h.eta===r.format());if(!s){const h=t.sample.all.filter(N=>b.utc(N.eta).isBefore(r)).at(-1),m=this.calculateSubRoute(h,t.route);s=(g=this.calculateNextCoordinateAlongRoute(h,h.speed*r.diff(b(h.etd),"hours",!0),m))==null?void 0:g.coordinate;const{cFactor:T,cog:p,wxFactor:v,meteo:P}=h,M=Math.round(s.distanceFromPrevious*1e4)/1e4,S=Math.round((M+h.distanceFromStart)*1e4)/1e4;s={...s,cFactor:T,cog:p,speed:h.speed,wxFactor:v,distanceFromStart:S,distanceFromPrevious:M,meteo:P,eta:r.format(),etd:r.format()}}s.distanceToGo=Math.round((t.distance-s.distanceFromStart)*100)/100,s.timeToGo=Math.round(o.diff(s.etd,"hours",!0)*100)/100;const c=this.calculateRangeWaypoints(n,s,t.route);return{routes:this.generateRouteAccordingToWaypoints(c),hour:s}}static pickUTCSampleFromRoute(e,t,n){var h;const i=this.calculateSubRoute(t,n),o=this.calculateRouteDistance(i),r=o/t.speed,s=b.utc(e),c=b(t.etd),a=(h=this.calculateNextCoordinateAlongRoute(t,t.speed*s.diff(b(t.etd),"hours",!0),i))==null?void 0:h.coordinate;a.speed=t.speed;const u=c.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(u.diff(s,"second"))<2?s.format():u.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((o-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(c.clone().add(r,"hour").diff(b(a.etd),"hour")*100)/100;const l=this.calculateRangeWaypoints(t,a,n);return{routes:this.generateRouteAccordingToWaypoints(l),hour:a}}static includedAngle(e,t){A==null||A.debug("calculate bearing via: %j",{bearing:e,degree:t});let n=Math.abs(e%360-(t%360||0));return n=n>180?360-n:n,n}}let D;try{D=B.getLogger("vessel")}catch{}finally{}class L{static convert2Geojson(e){var n,i,o;const t=f.featureCollection([]);for(const r of e){const s=(n=r.history)==null?void 0:n[0];if(r.forecasts){s&&s.wind&&(s.wind.kts=s.kts);for(const c of r.forecasts){let a;const u=[],l=[],g=b(c.date).utc(),h=`${r.name}-${c.model}`;for(const T in c==null?void 0:c.hours){const p=c.hours[T];a=a||p;const v=g.clone().add(Number(T),"hour"),P=f.point([p.lng,p.lat],{model:c.model,name:r.name,nameCn:r.nameCn,date:v.format(),hour:Number(T),format:v.format("MMM-DD/HHmm[Z]"),pressure:p.pressure>1e4?d.roundPrecision(p.pressure/100,0):d.roundPrecision(p.pressure,0),gusts:p.gusts,wind:p.wind||{},movement:p.movement,category:h,type:"forecast"});l.push(P),u.push(P.geometry.coordinates)}const m={kts:void 0,deg:void 0};if(s){const T=b(s.updated).utc();if(a){const v=y.calculateDistance(s,a),P=b(a.utc||a.updated).diff(T,"h",!0);m.kts=Math.round(v/P*100)/100,m.deg=y.calculateBearing(s,a,!0,0)}const p=f.point([s.lng,s.lat],{model:c.model,name:r.name,nameCn:r.nameCn,date:T.format(),hour:0,format:T.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?d.roundPrecision((s==null?void 0:s.pressure)/100,0):d.roundPrecision(s.pressure,0),wind:s.wind,movement:m,category:h,type:"forecast",important:!0});l.unshift(p),u.unshift(p.geometry.coordinates)}if(t.features.push(...l),(u==null?void 0:u.length)>1){const T=f.lineString(d.convertToMonotonicLng2(u),{date:(s==null?void 0:s.updated)||(g==null?void 0:g.format()),id:r.id||r.name,model:c.model,name:r.name,category:h,type:"forecast",movement:m});t.features.push(T)}}}if(t.features.sort((c,a)=>c.properties.type==="forecast"&&a.properties.type==="forecast"&&c.geometry.type==="Point"&&a.geometry.type==="Point"?b(c.properties.date).valueOf()-b(a.properties.date).valueOf():0),(i=r.history)!=null&&i.length){const c=[],a=b(s==null?void 0:s.updated).utc(),u=b((o=r.history)==null?void 0:o.at(-1).updated).utc(),l=a.diff(u,"h")%24>2?24:12;for(const g of r.history){const h=b(g.updated).utc(),m=h.isSameOrBefore(a)||h.isSame(u);m&&a.add(-l,"h");const T=f.point([g.lng,g.lat],{name:r.name,nameCn:r.nameCn,date:h.format(),format:h.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?d.roundPrecision(g.pressure/100,0):d.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${r.name}-history`,wind:g.wind,movement:g.movement,important:m});t.features.push(T),c.push(T.geometry.coordinates)}if(c.length===1&&c.push(c[0]),c.length>1){const g=f.lineString(d.convertToMonotonicLng2(c),{name:r.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?d.roundPrecision((s==null?void 0:s.pressure)/100,0):d.roundPrecision(s==null?void 0:s.pressure,0),kts:s==null?void 0:s.kts,level:s==null?void 0:s.type});t.features.push(g)}}}return t}static interpolate(e,t=3){var o,r,s,c;const n=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),i=[];for(const a of n){const u=a.properties.name,l=a.properties.model,g=a.properties.showCircle,h=a.properties.disabled,m=b(a.properties.date).utc();let T=t*60;const p=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(M=>M.geometry.type==="Point"&&M.properties.type==="forecast"&&M.properties.category===`${u}-${l}`);let v,P=m.clone().add(T,"minute").set({minute:0,second:0,millisecond:0});for(;v=this.pickIndex(p,P),v<=p.length-1;){if(v>0){const M=p[v],S=v===0?void 0:p[v-1],N=(T/60-((s=S==null?void 0:S.properties)==null?void 0:s.hour))/(M.properties.hour-((c=S==null?void 0:S.properties)==null?void 0:c.hour)),R=this.computeNumber(S==null?void 0:S.geometry.coordinates[0],M.geometry.coordinates[0],N),E=this.computeNumber(S==null?void 0:S.geometry.coordinates[1],M.geometry.coordinates[1],N),k=f.point([R,E],{name:u,model:l,category:M==null?void 0:M.properties.category,date:P.format(),format:P.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(S==null?void 0:S.properties.gusts,M.properties.gusts,N),hour:this.computeNumber(S==null?void 0:S.properties.hour,M.properties.hour,N),movement:this.computeNumber(S==null?void 0:S.properties.movement,M.properties.movement,N),pressure:this.computeNumber(S==null?void 0:S.properties.pressure,M.properties.pressure,N),wind:this.computeNumber(S==null?void 0:S.properties.wind,M.properties.wind,N),type:"forecast",disabled:h,showCircle:g});i.push(k)}T+=t*60,P=m.clone().add(T,"minute").set({minute:0,second:0,millisecond:0})}}return i}static accelPassageAt(e,t){const{t1:n,t2:i,hr:o,hours:r}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:i,hr:o,hours:r}}static diversionPassageAt(e,t,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(t,24,i);if(o&&r){if(!i.debug){const m=y.calculateDistance(e,o),T=y.calculateDistance(e,r);if(m>2*n&&T>2*n)return D==null||D.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",i.requestId,m,T,{from:e,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(e,o),u=y.calculateBearing(o,r),l=Math.abs(a-u);let g=0;l<180?g=l+90:l>=180&&(g=l-90);const h=y.calculateCoordinate(o,g,n);return D==null||D.info("[%s] the right tangent position: %j",i.requestId,{from:e,t1:o,t2:r,radius:n,bearing1:a,bearing2:u,right:h}),{at:h,t1:o,t2:r,hr:Number(s),hours:c}}return{}}static driftPassageAt(e,t,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(t,24,i);if(o&&r){if(!i.debug){const h=y.calculateDistance(e,o),m=y.calculateDistance(e,r);if(h>2*n&&m>2*n)return D==null||D.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",i.requestId,h,m,{from:e,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(e,o),u=y.calculateBearing(o,r),l=y.calculateDistance(e,o);return{at:y.calculateCoordinate(o,a-u+180,n<l?n:l),t1:o,t2:r,hr:Number(s),hours:c}}else return D==null||D.info("[%s] no need drift: %j",i.requestId,{from:e,t1:o,t2:r,hr:s}),{}}static tropicalCenterTwin(e,t=24,n={}){var u,l,g,h,m;let i={};(u=e.forecasts)==null||u.forEach(T=>{i={...T.hours,...i}});const o=((l=e==null?void 0:e.history)==null?void 0:l[0])||(i==null?void 0:i[(g=Object.keys(i))==null?void 0:g[0]]);D==null||D.info("[%s] the first tropical center: %j",n.requestId,o);let r=(h=Object.keys(i||{}).filter(T=>Number(T)<=(t<0?24:t)))==null?void 0:h.at(-1);r||(r=(m=Object.keys(i||{}).filter(T=>Number(T)<=(t<0?24:2*t)))==null?void 0:m.at(-1));const s=i==null?void 0:i[r||-1];D==null||D.info("[%s] the second tropical center: %j in %d hrs",n.requestId,s,r);const c=Object.keys(i||{}).filter(T=>Number(T)<=Number(r)),a={0:o};for(const T of c)a[T]=i[T];return{t1:o,t2:s,hr:Number(r),hours:a}}static pickIndex(e,t){let n=0;for(const i of e){if(b(i.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 i={};for(const o in e)i[o]=this.computeNumber(e[o],t[o],n);return i}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,e){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let x;try{x=B.getLogger("meteo")}catch{}finally{}function z(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:e}=new C("").window;return new e}class O{static toArrayBuffer(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}static drawCircle(e,t,n,i={}){const o=(i==null?void 0:i.steps)??64,r=(i==null?void 0:i.units)??"nauticalmiles",s=(i==null?void 0:i.properties)??{},c=f.point([e,t]),a=f.destination(c,n,90,{units:r}),u=b.utc();s.id=(i==null?void 0:i.id)||u.valueOf().toString();const l="circle";return s.name=(i==null?void 0:i.name)||`${l}_${u.format()}`,s.radius=n,s.center=[e,t],s.end=a.geometry.coordinates.map(g=>d.roundPrecision(g,9)),s.units=r,s.steps=o,s.shape="circle",x.info("[%s] draw circle with %j",i==null?void 0:i.requestId,s),f.circle(c,n,{steps:o,units:r,properties:s})}static drawRect(e,t,n={}){const i=(n==null?void 0:n.properties)??{},o=b.utc();i.id=(n==null?void 0:n.id)||o.valueOf().toString();const r="rect";i.name=(n==null?void 0:n.name)||`${r}_${o.format()}`,i.start=e.map(u=>d.roundPrecision(u,9)),i.end=t.map(u=>d.roundPrecision(u,9)),i.shape="rect",x.info("[%s] draw rect with %j",n==null?void 0:n.requestId,i);const[s,c]=d.convertToMonotonicLng2([e,t]),a=[Math.min(s[0],c[0]),Math.min(s[1],c[1]),Math.max(s[0],c[0]),Math.max(s[1],c[1])];return f.bboxPolygon(a,{properties:i})}static drawLine(e,t={}){const n=(t==null?void 0:t.properties)??{},i=b.utc();n.id=(t==null?void 0:t.id)||i.valueOf().toString();const o="line";n.name=(t==null?void 0:t.name)||`${o}_${i.format()}`,n.shape="line",x.info("[%s] draw line with %j",t==null?void 0:t.requestId,n);const r=d.convertToMonotonicLng2(e);return f.lineString(r,n)}static drawPolygon(e,t={}){const n=(t==null?void 0:t.properties)??{},i=b.utc();n.id=(t==null?void 0:t.id)||i.valueOf().toString();const o="polygon";n.name=(t==null?void 0:t.name)||`${o}_${i.format()}`,n.coordinates=e.map(s=>s.map(c=>d.roundPrecision(c,9))),n.shape="polygon",x.info("[%s] draw polygon with %j",t==null?void 0:t.requestId,n);const r=d.convertToMonotonicLng2(e);return f.polygon([r],n)}static drawPoint(e,t,n={}){const i=(n==null?void 0:n.properties)??{},o=b.utc();i.id=(n==null?void 0:n.id)||o.valueOf().toString();const r="point";return i.name=(n==null?void 0:n.name)||`${r}_${o.format()}`,i.shape="point",x.info("[%s] draw point with %j",n==null?void 0:n.requestId,i),f.point([t,e],i)}static parseCircle(e,t={}){var i,o;x.info("[%s] parse circle with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="circle"){const r=b.utc();n.id=(n==null?void 0:n.id)||r.valueOf().toString();const s=n==null?void 0:n.id,c=((i=n==null?void 0:n.center)==null?void 0:i.length)==2?f.point(n.center):f.centroid(e);let a="center";c.properties={id:`${a}_${s}`,parentId:s,name:a};const u=(n==null?void 0:n.units)||"nauticalmiles";let l=n==null?void 0:n.radius;if(!l){const m=f.polygonToLine(e);l=f.pointToLineDistance(c,m,{units:u})}a="end";const g=((o=n==null?void 0:n.end)==null?void 0:o.length)==2?f.point(n.end):f.destination(c,l,90,{units:u});g.properties={id:`${a}_${s}`,parentId:s,name:a,radius:l,units:u};const h=f.lineString([c.geometry.coordinates,g.geometry.coordinates]);return a="edge",h.properties={id:`${a}_${s}`,parentId:s,name:a,radius:l,units:u},f.featureCollection([c,g,h,e])}else return x.warn("[%s] not a orm-std circle, just return the original feature",t==null?void 0:t.requestId),f.featureCollection([e])}static parseRect(e,t={}){x.info("[%s] parse rect with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="rect"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,r=e.geometry.coordinates[0],c=["sw","nw","ne","se"].map((a,u)=>{const l=f.point(r[u]);return l.properties={id:`${a}_${o}`,parentId:o,name:a},l});return f.featureCollection([...c,e])}else return x.warn("[%s] not a orm-std rect, just return the original feature",t==null?void 0:t.requestId),f.featureCollection([e])}static parseLine(e,t={}){x.info("[%s] parse line with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="line"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,s=e.geometry.coordinates.map((c,a)=>{const u=`point_${a}`,l=f.point(c);return l.properties={id:`${u}_${o}`,parentId:o,name:u,index:a},l});return f.featureCollection([...s,e])}else return x.warn("[%s] not a orm-std line, just return the original feature",t==null?void 0:t.requestId),f.featureCollection([e])}static parsePolygon(e,t={}){x.info("[%s] parse polygon with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="polygon"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,s=e.geometry.coordinates[0].map((c,a)=>{const u=f.point(c),l=`corner_${a}`;return u.properties={id:`${l}_${o}`,parentId:o,name:l,index:a},u});return f.featureCollection([...s,e])}else return x.warn("[%s] not a orm-std polygon, just return the original feature",t==null?void 0:t.requestId),f.featureCollection([e])}static _inflateRawSync(e){var t;if(typeof process<"u"&&((t=process.versions)!=null&&t.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(e)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(e){var c;const t=new Uint8Array(e),n=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),i=new DataView(n),o=new Uint8Array(n),r=new Map;let s=0;for(;s+4<=n.byteLength&&i.getUint32(s,!0)===67324752;){const u=i.getUint16(s+8,!0),l=i.getUint32(s+18,!0),g=i.getUint16(s+26,!0),h=i.getUint16(s+28,!0),m=o.slice(s+30,s+30+g),T=new TextDecoder().decode(m),p=s+30+g+h,v=o.slice(p,p+l);if(u===0)r.set(T,v);else if(u===8){if(typeof DecompressionStream<"u"){const P=new DecompressionStream("deflate-raw"),M=P.writable.getWriter(),S=P.readable.getReader();M.write(v),M.close();const N=[];let R=0;for(;;){const{done:w,value:j}=await S.read();if(w)break;N.push(j),R+=j.length}const E=new Uint8Array(R);let k=0;for(const w of N)E.set(w,k),k+=w.length;r.set(T,E)}else if(typeof process<"u"&&((c=process.versions)!=null&&c.node))try{r.set(T,O._inflateRawSync(v))}catch{}}s=p+l}return r}static async convertKML2GeoJSON(e,t={}){var s,c;x.info("[%s] convert kml to geojson",t==null?void 0:t.requestId);const i=z().parseFromString(e,"application/xml"),o=Array.from(i.querySelectorAll("Placemark")),r=[];for(const a of o){const u={},l=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const S of l){const N=S.getAttribute("name"),R=(c=(s=S.querySelector("value"))==null?void 0:s.textContent)==null?void 0:c.trim();N&&R!==void 0&&R!==null&&(u[N]=R)}const g=b.utc(),h=Object.keys(u).find(S=>S.toLowerCase().indexOf("name")!==-1),m=h?u[h]:void 0,T=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,p=S=>S.trim().split(/[\s\n]+/).filter(N=>N.length>0).map(N=>{const R=N.split(",").map(Number);return[R[0],R[1]]}),v=a.querySelector("LineString > coordinates");if(v){const S=p(v.textContent||"");if(S.length>=2){const N=f.lineString(S,{...u,shape:"line",id:T,name:m});r.push(N)}continue}const P=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(P){const S=p(P.textContent||"");if(S.length>=4){const N=S[0][0]===S[S.length-1][0]&&S[0][1]===S[S.length-1][1]?S:[...S,S[0]],R=f.polygon([N],{...u,shape:"polygon",id:T,name:m});r.push(R)}continue}const M=a.querySelector("Point > coordinates");if(M){const S=p(M.textContent||"");if(S.length>=1){const N=f.point(S[0],{...u,shape:"point",id:T,name:m});r.push(N)}continue}}return f.featureCollection(r)}static async convertKMZ2GeoJSON(e,t={}){var r;x.info("[%s] convert kmz to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await O._parseZipEntries(e),i=n.get("doc.kml")??((r=[...n.entries()].find(([s])=>s.toLowerCase().endsWith(".kml")))==null?void 0:r[1]);if(!i)return x.warn("[%s] no .kml file found in kmz",t==null?void 0:t.requestId),f.featureCollection([]);const o=new TextDecoder().decode(i);return O.convertKML2GeoJSON(o,t)}static async convertZIP2GeoJSON(e,t={}){x.info("[%s] convert zip to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await O._parseZipEntries(e),i=[];for(const[o,r]of n){if(!o.toLowerCase().endsWith(".kml"))continue;const s=new TextDecoder().decode(r),c=await O.convertKML2GeoJSON(s,t);i.push(...c.features)}return i.length===0?(x.warn("[%s] no .kml files found in zip",t==null?void 0:t.requestId),this.convertSHP2GeoJSON(e,t)):f.featureCollection(i)}static async convertSHP2GeoJSON(e,t={}){x.info("[%s] convert shp zip to geojson",t==null?void 0:t.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await W(e);if(Array.isArray(n)){const i=n.flatMap(c=>c.features||[]),o=b.utc(),r=(t==null?void 0:t.id)||o.valueOf().toString(),s={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return i.forEach((c,a)=>{var m;const u=((m=c.geometry)==null?void 0:m.type)||"",l=s[u]||u.toLowerCase();c.properties=c.properties||{},c.properties.shape=l,c.properties.parentId=r,c.properties.id=`${r}_${a}`;const g=Object.keys(c.properties).find(T=>T.toLowerCase().indexOf("name")!==-1),h=g?c.properties[g]:void 0;c.properties.name=h||`${l}_${o.format()}_${a}`}),f.featureCollection(i)}return n}catch(n){return x.warn("[%s] failed to convert shp zip: %s",t==null?void 0:t.requestId,n),f.featureCollection([])}}}$.AisHelper=F,$.GeoJsonHelper=O,$.LaneHelper=y,$.LngLatHelper=d,$.TropicalHelper=L,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
6
+ `)}static coordinatesSummary(e,t=3){if(e.length>1){const n=e[0],i=e[e.length-1],o=(n==null?void 0:n.positionTime)<(i==null?void 0:i.positionTime)?b.unix(n==null?void 0:n.positionTime):b.unix(i==null?void 0:i.positionTime),r=(n==null?void 0:n.positionTime)>(i==null?void 0:i.positionTime)?b.unix(n==null?void 0:n.positionTime):b.unix(i==null?void 0:i.positionTime),s=Math.round(r.diff(o,"hours",!0)*100)/100,c=this.generateRouteAccordingToWaypoints(e,!0,!0),a=this.calculateRouteDistance(c),l=B.inspectStoppages(e,t).reduce((f,T)=>(f.duration+=T.duration,f.distance+=T.distance,f),{hours:0,distance:0,spd:0,duration:0});l.hours=Math.round(l.duration/3600*100)/100,l.distance=Math.round(l.distance*100)/100,l.spd=l.hours?Math.round(l.distance/l.hours*100)/100:0;const g=s?Math.round((a-l.distance)/(s-l.hours)*100)/100:0;return{begin:o.utc().format(),end:r.utc().format(),distance:Math.round((a-l.distance)*100)/100,hours:Math.round((s-l.hours)*100)/100,avgSpeed:g,stoppage:l}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(e,t){var u,l,g;if(!((l=(u=t==null?void 0:t.sample)==null?void 0:u.hours)!=null&&l.length))return{routes:[],hour:void 0};const n=t.sample.hours.at(0),i=b.utc(e),o=b.utc(t.eta),r=i.isAfter(o)?o:i;let s=t.sample.all.find(f=>f.eta===r.format());if(!s){const f=t.sample.all.filter(N=>b.utc(N.eta).isBefore(r)).at(-1),T=this.calculateSubRoute(f,t.route);s=(g=this.calculateNextCoordinateAlongRoute(f,f.speed*r.diff(b(f.etd),"hours",!0),T))==null?void 0:g.coordinate;const{cFactor:S,cog:p,wxFactor:v,meteo:P}=f,M=Math.round(s.distanceFromPrevious*1e4)/1e4,m=Math.round((M+f.distanceFromStart)*1e4)/1e4;s={...s,cFactor:S,cog:p,speed:f.speed,wxFactor:v,distanceFromStart:m,distanceFromPrevious:M,meteo:P,eta:r.format(),etd:r.format()}}s.distanceToGo=Math.round((t.distance-s.distanceFromStart)*100)/100,s.timeToGo=Math.round(o.diff(s.etd,"hours",!0)*100)/100;const c=this.calculateRangeWaypoints(n,s,t.route);return{routes:this.generateRouteAccordingToWaypoints(c),hour:s}}static pickUTCSampleFromRoute(e,t,n){var f;const i=this.calculateSubRoute(t,n),o=this.calculateRouteDistance(i),r=o/t.speed,s=b.utc(e),c=b(t.etd),a=(f=this.calculateNextCoordinateAlongRoute(t,t.speed*s.diff(b(t.etd),"hours",!0),i))==null?void 0:f.coordinate;a.speed=t.speed;const u=c.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(u.diff(s,"second"))<2?s.format():u.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((o-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(c.clone().add(r,"hour").diff(b(a.etd),"hour")*100)/100;const l=this.calculateRangeWaypoints(t,a,n);return{routes:this.generateRouteAccordingToWaypoints(l),hour:a}}static includedAngle(e,t){A==null||A.debug("calculate bearing via: %j",{bearing:e,degree:t});let n=Math.abs(e%360-(t%360||0));return n=n>180?360-n:n,n}}let D;try{D=F.getLogger("vessel")}catch{}finally{}class Z{static convert2Geojson(e){var n,i,o;const t=h.featureCollection([]);for(const r of e){const s=(n=r.history)==null?void 0:n[0];if(r.forecasts){s&&s.wind&&(s.wind.kts=s.kts);for(const c of r.forecasts){let a;const u=[],l=[],g=b(c.date).utc(),f=`${r.name}-${c.model}`;for(const S in c==null?void 0:c.hours){const p=c.hours[S];a=a||p;const v=g.clone().add(Number(S),"hour"),P=h.point([p.lng,p.lat],{model:c.model,name:r.name,nameCn:r.nameCn,date:v.format(),hour:Number(S),format:v.format("MMM-DD/HHmm[Z]"),pressure:p.pressure>1e4?d.roundPrecision(p.pressure/100,0):d.roundPrecision(p.pressure,0),gusts:p.gusts,wind:p.wind||{},movement:p.movement,category:f,type:"forecast"});l.push(P),u.push(P.geometry.coordinates)}const T={kts:void 0,deg:void 0};if(s){const S=b(s.updated).utc();if(a){const v=y.calculateDistance(s,a),P=b(a.utc||a.updated).diff(S,"h",!0);T.kts=Math.round(v/P*100)/100,T.deg=y.calculateBearing(s,a,!0,0)}const p=h.point([s.lng,s.lat],{model:c.model,name:r.name,nameCn:r.nameCn,date:S.format(),hour:0,format:S.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?d.roundPrecision((s==null?void 0:s.pressure)/100,0):d.roundPrecision(s.pressure,0),wind:s.wind,movement:T,category:f,type:"forecast",important:!0});l.unshift(p),u.unshift(p.geometry.coordinates)}if(t.features.push(...l),(u==null?void 0:u.length)>1){const S=h.lineString(d.convertToMonotonicLng2(u),{date:(s==null?void 0:s.updated)||(g==null?void 0:g.format()),id:r.id||r.name,model:c.model,name:r.name,category:f,type:"forecast",movement:T});t.features.push(S)}}}if(t.features.sort((c,a)=>c.properties.type==="forecast"&&a.properties.type==="forecast"&&c.geometry.type==="Point"&&a.geometry.type==="Point"?b(c.properties.date).valueOf()-b(a.properties.date).valueOf():0),(i=r.history)!=null&&i.length){const c=[],a=b(s==null?void 0:s.updated).utc(),u=b((o=r.history)==null?void 0:o.at(-1).updated).utc(),l=a.diff(u,"h")%24>2?24:12;for(const g of r.history){const f=b(g.updated).utc(),T=f.isSameOrBefore(a)||f.isSame(u);T&&a.add(-l,"h");const S=h.point([g.lng,g.lat],{name:r.name,nameCn:r.nameCn,date:f.format(),format:f.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?d.roundPrecision(g.pressure/100,0):d.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${r.name}-history`,wind:g.wind,movement:g.movement,important:T});t.features.push(S),c.push(S.geometry.coordinates)}if(c.length===1&&c.push(c[0]),c.length>1){const g=h.lineString(d.convertToMonotonicLng2(c),{name:r.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?d.roundPrecision((s==null?void 0:s.pressure)/100,0):d.roundPrecision(s==null?void 0:s.pressure,0),kts:s==null?void 0:s.kts,level:s==null?void 0:s.type});t.features.push(g)}}}return t}static interpolate(e,t=3){var o,r,s,c;const n=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),i=[];for(const a of n){const u=a.properties.name,l=a.properties.model,g=a.properties.showCircle,f=a.properties.disabled,T=b(a.properties.date).utc();let S=t*60;const p=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(M=>M.geometry.type==="Point"&&M.properties.type==="forecast"&&M.properties.category===`${u}-${l}`);let v,P=T.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;v=this.pickIndex(p,P),v<=p.length-1;){if(v>0){const M=p[v],m=v===0?void 0:p[v-1],N=(S/60-((s=m==null?void 0:m.properties)==null?void 0:s.hour))/(M.properties.hour-((c=m==null?void 0:m.properties)==null?void 0:c.hour)),R=this.computeNumber(m==null?void 0:m.geometry.coordinates[0],M.geometry.coordinates[0],N),E=this.computeNumber(m==null?void 0:m.geometry.coordinates[1],M.geometry.coordinates[1],N),k=h.point([R,E],{name:u,model:l,category:M==null?void 0:M.properties.category,date:P.format(),format:P.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(m==null?void 0:m.properties.gusts,M.properties.gusts,N),hour:this.computeNumber(m==null?void 0:m.properties.hour,M.properties.hour,N),movement:this.computeNumber(m==null?void 0:m.properties.movement,M.properties.movement,N),pressure:this.computeNumber(m==null?void 0:m.properties.pressure,M.properties.pressure,N),wind:this.computeNumber(m==null?void 0:m.properties.wind,M.properties.wind,N),type:"forecast",disabled:f,showCircle:g});i.push(k)}S+=t*60,P=T.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return i}static accelPassageAt(e,t){const{t1:n,t2:i,hr:o,hours:r}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:i,hr:o,hours:r}}static diversionPassageAt(e,t,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(t,24,i);if(o&&r){if(!i.debug){const T=y.calculateDistance(e,o),S=y.calculateDistance(e,r);if(T>2*n&&S>2*n)return D==null||D.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",i.requestId,T,S,{from:e,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(e,o),u=y.calculateBearing(o,r),l=Math.abs(a-u);let g=0;l<180?g=l+90:l>=180&&(g=l-90);const f=y.calculateCoordinate(o,g,n);return D==null||D.info("[%s] the right tangent position: %j",i.requestId,{from:e,t1:o,t2:r,radius:n,bearing1:a,bearing2:u,right:f}),{at:f,t1:o,t2:r,hr:Number(s),hours:c}}return{}}static driftPassageAt(e,t,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(t,24,i);if(o&&r){if(!i.debug){const f=y.calculateDistance(e,o),T=y.calculateDistance(e,r);if(f>2*n&&T>2*n)return D==null||D.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",i.requestId,f,T,{from:e,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(e,o),u=y.calculateBearing(o,r),l=y.calculateDistance(e,o);return{at:y.calculateCoordinate(o,a-u+180,n<l?n:l),t1:o,t2:r,hr:Number(s),hours:c}}else return D==null||D.info("[%s] no need drift: %j",i.requestId,{from:e,t1:o,t2:r,hr:s}),{}}static tropicalCenterTwin(e,t=24,n={}){var u,l,g,f,T;let i={};(u=e.forecasts)==null||u.forEach(S=>{i={...S.hours,...i}});const o=((l=e==null?void 0:e.history)==null?void 0:l[0])||(i==null?void 0:i[(g=Object.keys(i))==null?void 0:g[0]]);D==null||D.info("[%s] the first tropical center: %j",n.requestId,o);let r=(f=Object.keys(i||{}).filter(S=>Number(S)<=(t<0?24:t)))==null?void 0:f.at(-1);r||(r=(T=Object.keys(i||{}).filter(S=>Number(S)<=(t<0?24:2*t)))==null?void 0:T.at(-1));const s=i==null?void 0:i[r||-1];D==null||D.info("[%s] the second tropical center: %j in %d hrs",n.requestId,s,r);const c=Object.keys(i||{}).filter(S=>Number(S)<=Number(r)),a={0:o};for(const S of c)a[S]=i[S];return{t1:o,t2:s,hr:Number(r),hours:a}}static pickIndex(e,t){let n=0;for(const i of e){if(b(i.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 i={};for(const o in e)i[o]=this.computeNumber(e[o],t[o],n);return i}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,e){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let x;try{x=F.getLogger("meteo")}catch{}finally{}function G(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:e}=new C("").window;return new e}class O{static toArrayBuffer(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}static drawCircle(e,t,n,i={}){const o=(i==null?void 0:i.steps)??64,r=(i==null?void 0:i.units)??"nauticalmiles",s=(i==null?void 0:i.properties)??{},c=h.point([e,t]),a=h.destination(c,n,90,{units:r}),u=b.utc();s.id=(i==null?void 0:i.id)||u.valueOf().toString();const l="circle";return s.name=(i==null?void 0:i.name)||`${l}_${u.format()}`,s.radius=n,s.center=[e,t],s.end=a.geometry.coordinates.map(g=>d.roundPrecision(g,9)),s.units=r,s.steps=o,s.shape="circle",x.info("[%s] draw circle with %j",i==null?void 0:i.requestId,s),h.circle(c,n,{steps:o,units:r,properties:s})}static drawRect(e,t,n={}){const i=(n==null?void 0:n.properties)??{},o=b.utc();i.id=(n==null?void 0:n.id)||o.valueOf().toString();const r="rect";i.name=(n==null?void 0:n.name)||`${r}_${o.format()}`,i.start=e.map(u=>d.roundPrecision(u,9)),i.end=t.map(u=>d.roundPrecision(u,9)),i.shape="rect",x.info("[%s] draw rect with %j",n==null?void 0:n.requestId,i);const[s,c]=d.convertToMonotonicLng2([e,t]),a=[Math.min(s[0],c[0]),Math.min(s[1],c[1]),Math.max(s[0],c[0]),Math.max(s[1],c[1])];return h.bboxPolygon(a,{properties:i})}static drawLine(e,t={}){const n=(t==null?void 0:t.properties)??{},i=b.utc();n.id=(t==null?void 0:t.id)||i.valueOf().toString();const o="line";n.name=(t==null?void 0:t.name)||`${o}_${i.format()}`,n.shape="line",x.info("[%s] draw line with %j",t==null?void 0:t.requestId,n);const r=d.convertToMonotonicLng2(e);return h.lineString(r,n)}static drawPolygon(e,t={}){const n=(t==null?void 0:t.properties)??{},i=b.utc();n.id=(t==null?void 0:t.id)||i.valueOf().toString();const o="polygon";n.name=(t==null?void 0:t.name)||`${o}_${i.format()}`,n.coordinates=e.map(s=>s.map(c=>d.roundPrecision(c,9))),n.shape="polygon",x.info("[%s] draw polygon with %j",t==null?void 0:t.requestId,n);const r=d.convertToMonotonicLng2(e);return h.polygon([r],n)}static drawPoint(e,t,n={}){const i=(n==null?void 0:n.properties)??{},o=b.utc();i.id=(n==null?void 0:n.id)||o.valueOf().toString();const r="point";return i.name=(n==null?void 0:n.name)||`${r}_${o.format()}`,i.shape="point",x.info("[%s] draw point with %j",n==null?void 0:n.requestId,i),h.point([t,e],i)}static parseCircle(e,t={}){var i,o;x.info("[%s] parse circle with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="circle"){const r=b.utc();n.id=(n==null?void 0:n.id)||r.valueOf().toString();const s=n==null?void 0:n.id,c=((i=n==null?void 0:n.center)==null?void 0:i.length)==2?h.point(n.center):h.centroid(e);let a="center";c.properties={id:`${a}_${s}`,parentId:s,name:a};const u=(n==null?void 0:n.units)||"nauticalmiles";let l=n==null?void 0:n.radius;if(!l){const T=h.polygonToLine(e);l=h.pointToLineDistance(c,T,{units:u})}a="end";const g=((o=n==null?void 0:n.end)==null?void 0:o.length)==2?h.point(n.end):h.destination(c,l,90,{units:u});g.properties={id:`${a}_${s}`,parentId:s,name:a,radius:l,units:u};const f=h.lineString([c.geometry.coordinates,g.geometry.coordinates]);return a="edge",f.properties={id:`${a}_${s}`,parentId:s,name:a,radius:l,units:u},h.featureCollection([c,g,f,e])}else return x.warn("[%s] not a orm-std circle, just return the original feature",t==null?void 0:t.requestId),h.featureCollection([e])}static parseRect(e,t={}){x.info("[%s] parse rect with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="rect"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,r=e.geometry.coordinates[0],c=["sw","nw","ne","se"].map((a,u)=>{const l=h.point(r[u]);return l.properties={id:`${a}_${o}`,parentId:o,name:a},l});return h.featureCollection([...c,e])}else return x.warn("[%s] not a orm-std rect, just return the original feature",t==null?void 0:t.requestId),h.featureCollection([e])}static parseLine(e,t={}){x.info("[%s] parse line with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="line"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,s=e.geometry.coordinates.map((c,a)=>{const u=`point_${a}`,l=h.point(c);return l.properties={id:`${u}_${o}`,parentId:o,name:u,index:a},l});return h.featureCollection([...s,e])}else return x.warn("[%s] not a orm-std line, just return the original feature",t==null?void 0:t.requestId),h.featureCollection([e])}static parsePolygon(e,t={}){x.info("[%s] parse polygon with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="polygon"){const i=b.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const o=n==null?void 0:n.id,s=e.geometry.coordinates[0].map((c,a)=>{const u=h.point(c),l=`corner_${a}`;return u.properties={id:`${l}_${o}`,parentId:o,name:l,index:a},u});return h.featureCollection([...s,e])}else return x.warn("[%s] not a orm-std polygon, just return the original feature",t==null?void 0:t.requestId),h.featureCollection([e])}static _inflateRawSync(e){var t;if(typeof process<"u"&&((t=process.versions)!=null&&t.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(e)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(e){var c;const t=new Uint8Array(e),n=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),i=new DataView(n),o=new Uint8Array(n),r=new Map;let s=0;for(;s+4<=n.byteLength&&i.getUint32(s,!0)===67324752;){const u=i.getUint16(s+6,!0),l=i.getUint16(s+8,!0);let g=i.getUint32(s+18,!0);const f=i.getUint16(s+26,!0),T=i.getUint16(s+28,!0),S=o.slice(s+30,s+30+f),p=new TextDecoder().decode(S),v=s+30+f+T;if((u&8)!==0||g===0){let m=v;for(;m+4<=n.byteLength;){const N=i.getUint32(m,!0);if(N===67324752||N===33639248)break;m++}g=m-v}const M=o.slice(v,v+g);if(l===0)r.set(p,M);else if(l===8){if(typeof DecompressionStream<"u"){const m=new DecompressionStream("deflate-raw"),N=m.writable.getWriter(),R=m.readable.getReader();N.write(M),N.close();const E=[];let k=0;for(;;){const{done:w,value:W}=await R.read();if(w)break;E.push(W),k+=W.length}const j=new Uint8Array(k);let q=0;for(const w of E)j.set(w,q),q+=w.length;r.set(p,j)}else if(typeof process<"u"&&((c=process.versions)!=null&&c.node))try{r.set(p,O._inflateRawSync(M))}catch{}}s=v+g}return r}static async convertKML2GeoJSON(e,t={}){var s,c;x.info("[%s] convert kml to geojson",t==null?void 0:t.requestId);const i=G().parseFromString(e,"application/xml"),o=Array.from(i.querySelectorAll("Placemark")),r=[];for(const a of o){const u={},l=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const m of l){const N=m.getAttribute("name"),R=(c=(s=m.querySelector("value"))==null?void 0:s.textContent)==null?void 0:c.trim();N&&R!==void 0&&R!==null&&(u[N]=R)}const g=b.utc(),f=Object.keys(u).find(m=>m.toLowerCase().indexOf("name")!==-1),T=f?u[f]:void 0,S=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,p=m=>m.trim().split(/[\s\n]+/).filter(N=>N.length>0).map(N=>{const R=N.split(",").map(Number);return[R[0],R[1]]}),v=a.querySelector("LineString > coordinates");if(v){const m=p(v.textContent||"");if(m.length>=2){const N=h.lineString(m,{...u,shape:"line",id:S,name:T});r.push(N)}continue}const P=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(P){const m=p(P.textContent||"");if(m.length>=4){const N=m[0][0]===m[m.length-1][0]&&m[0][1]===m[m.length-1][1]?m:[...m,m[0]],R=h.polygon([N],{...u,shape:"polygon",id:S,name:T});r.push(R)}continue}const M=a.querySelector("Point > coordinates");if(M){const m=p(M.textContent||"");if(m.length>=1){const N=h.point(m[0],{...u,shape:"point",id:S,name:T});r.push(N)}continue}}return h.featureCollection(r)}static async convertKMZ2GeoJSON(e,t={}){var r;x.info("[%s] convert kmz to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await O._parseZipEntries(e),i=n.get("doc.kml")??((r=[...n.entries()].find(([s])=>s.toLowerCase().endsWith(".kml")))==null?void 0:r[1]);if(!i)return x.warn("[%s] no .kml file found in kmz",t==null?void 0:t.requestId),h.featureCollection([]);const o=new TextDecoder().decode(i);return O.convertKML2GeoJSON(o,t)}static async convertZIP2GeoJSON(e,t={}){x.info("[%s] convert zip to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await O._parseZipEntries(e),i=[];for(const[o,r]of n){if(!o.toLowerCase().endsWith(".kml"))continue;const s=new TextDecoder().decode(r),c=await O.convertKML2GeoJSON(s,t);i.push(...c.features)}return i.length===0?(x.warn("[%s] no .kml files found in zip",t==null?void 0:t.requestId),this.convertSHP2GeoJSON(e,t)):h.featureCollection(i)}static async convertSHP2GeoJSON(e,t={}){x.info("[%s] convert shp zip to geojson",t==null?void 0:t.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=O.toArrayBuffer(e));const n=await L(e);if(Array.isArray(n)){const i=n.flatMap(c=>c.features||[]),o=b.utc(),r=(t==null?void 0:t.id)||o.valueOf().toString(),s={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return i.forEach((c,a)=>{var T;const u=((T=c.geometry)==null?void 0:T.type)||"",l=s[u]||u.toLowerCase();c.properties=c.properties||{},c.properties.shape=l,c.properties.parentId=r,c.properties.id=`${r}_${a}`;const g=Object.keys(c.properties).find(S=>S.toLowerCase().indexOf("name")!==-1),f=g?c.properties[g]:void 0;c.properties.name=f||`${l}_${o.format()}_${a}`}),h.featureCollection(i)}return n}catch(n){return x.warn("[%s] failed to convert shp zip: %s",t==null?void 0:t.requestId,n),h.featureCollection([])}}}$.AisHelper=B,$.GeoJsonHelper=O,$.LaneHelper=y,$.LngLatHelper=d,$.TropicalHelper=Z,Object.defineProperty($,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": "2.1.9",
4
+ "version": "2.2.1",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [