@idm-plugin/geo 2.1.9 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as f from "@turf/turf";
2
2
  import b from "moment";
3
- import w from "@log4js-node/log4js-api";
3
+ import F from "@log4js-node/log4js-api";
4
4
  import "moment-timezone";
5
- import F from "tz-lookup";
6
- import k from "shpjs";
5
+ import G from "tz-lookup";
6
+ import z 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 = G(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}`;
@@ -253,7 +253,7 @@ class W {
253
253
  }
254
254
  let I;
255
255
  try {
256
- I = w.getLogger("meteo");
256
+ I = F.getLogger("meteo");
257
257
  } catch {
258
258
  } finally {
259
259
  }
@@ -376,8 +376,8 @@ class v {
376
376
  const h = f.lineIntersect(l, g);
377
377
  let p;
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
+ p = d.roundPrecision(S[1], 8);
381
381
  } else
382
382
  p = t[c].lat;
383
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]));
@@ -719,11 +719,11 @@ class v {
719
719
  if (c)
720
720
  s.push(h);
721
721
  else {
722
- const T = [];
722
+ const S = [];
723
723
  let m;
724
724
  for (let y = 0; y < h.length; y++)
725
725
  if (l)
726
- T.push(h[y]);
726
+ S.push(h[y]);
727
727
  else {
728
728
  m = { lng: h[y][0], lat: h[y][1] };
729
729
  const P = this.calculateDistance(t, m, !0, 8, i);
@@ -731,15 +731,15 @@ class v {
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, T = this.calculateBearing(m, t);
737
+ l = this.calculateCoordinate(m, T, 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), p === 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) {
@@ -1022,13 +1022,13 @@ class v {
1022
1022
  I.debug("keep name for waypoints2CSV for legacy compatibility only", t);
1023
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
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(","));
1025
+ const S = [];
1026
+ S.push(p.map((m) => v.csvEscapeField(m)).join(","));
1027
1027
  for (let m = 0; m < e.length; m++) {
1028
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(","));
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) : ""), S.push(P.map((M) => v.csvEscapeField(M)).join(","));
1030
1030
  }
1031
- return T.join(`
1031
+ return S.join(`
1032
1032
  `);
1033
1033
  }
1034
1034
  /**
@@ -1088,7 +1088,7 @@ 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(
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
1092
  (h, p) => (h.duration += p.duration, h.distance += p.distance, h),
1093
1093
  { hours: 0, distance: 0, spd: 0, duration: 0 }
1094
1094
  );
@@ -1129,14 +1129,14 @@ class v {
1129
1129
  if (!s) {
1130
1130
  const h = e.sample.all.filter((N) => b.utc(N.eta).isBefore(r)).at(-1), p = this.calculateSubRoute(h, e.route);
1131
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;
1132
+ const { cFactor: S, cog: m, wxFactor: y, meteo: P } = h, M = Math.round(s.distanceFromPrevious * 1e4) / 1e4, T = 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
1138
  wxFactor: y,
1139
- distanceFromStart: S,
1139
+ distanceFromStart: T,
1140
1140
  distanceFromPrevious: M,
1141
1141
  meteo: P,
1142
1142
  eta: r.format(),
@@ -1185,11 +1185,11 @@ class v {
1185
1185
  }
1186
1186
  let C;
1187
1187
  try {
1188
- C = w.getLogger("vessel");
1188
+ C = F.getLogger("vessel");
1189
1189
  } catch {
1190
1190
  } finally {
1191
1191
  }
1192
- class z {
1192
+ class H {
1193
1193
  /**
1194
1194
  * 将原始数据转换为geojson
1195
1195
  * @param raw
@@ -1204,15 +1204,15 @@ 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 y = 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
1214
  date: y.format(),
1215
- hour: Number(T),
1215
+ hour: Number(S),
1216
1216
  format: y.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,
@@ -1228,18 +1228,18 @@ class z {
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);
1233
+ const y = v.calculateDistance(s, a), P = b(a.utc || a.updated).diff(S, "h", !0);
1234
1234
  p.kts = Math.round(y / P * 100) / 100, p.deg = v.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
1245
  movement: p,
@@ -1251,7 +1251,7 @@ 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,
@@ -1260,7 +1260,7 @@ class z {
1260
1260
  type: "forecast",
1261
1261
  movement: p
1262
1262
  });
1263
- e.features.push(T);
1263
+ e.features.push(S);
1264
1264
  }
1265
1265
  }
1266
1266
  }
@@ -1269,7 +1269,7 @@ class z {
1269
1269
  for (const g of r.history) {
1270
1270
  const h = b(g.updated).utc(), p = h.isSameOrBefore(a) || h.isSame(u);
1271
1271
  p && a.add(-l, "h");
1272
- const T = f.point([g.lng, g.lat], {
1272
+ const S = f.point([g.lng, g.lat], {
1273
1273
  name: r.name,
1274
1274
  nameCn: r.nameCn,
1275
1275
  date: h.format(),
@@ -1283,7 +1283,7 @@ class z {
1283
1283
  movement: g.movement,
1284
1284
  important: p
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), {
@@ -1310,31 +1310,31 @@ class z {
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
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;
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 });
1317
+ let y, P = p.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1318
1318
  for (; y = this.pickIndex(m, P), y <= m.length - 1; ) {
1319
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], {
1320
+ const M = m[y], T = y === 0 ? void 0 : m[y - 1], N = (S / 60 - ((s = T == null ? void 0 : T.properties) == null ? void 0 : s.hour)) / (M.properties.hour - ((c = T == null ? void 0 : T.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(T == null ? void 0 : T.geometry.coordinates[0], M.geometry.coordinates[0], N), E = this.computeNumber(T == null ? void 0 : T.geometry.coordinates[1], M.geometry.coordinates[1], N), O = f.point([$, E], {
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(T == null ? void 0 : T.properties.gusts, M.properties.gusts, N),
1327
+ hour: this.computeNumber(T == null ? void 0 : T.properties.hour, M.properties.hour, N),
1328
+ movement: this.computeNumber(T == null ? void 0 : T.properties.movement, M.properties.movement, N),
1329
+ pressure: this.computeNumber(T == null ? void 0 : T.properties.pressure, M.properties.pressure, N),
1330
+ wind: this.computeNumber(T == null ? void 0 : T.properties.wind, M.properties.wind, N),
1331
1331
  type: "forecast",
1332
1332
  disabled: h,
1333
1333
  showCircle: g
1334
1334
  });
1335
- i.push(A);
1335
+ i.push(O);
1336
1336
  }
1337
- T += e * 60, P = p.clone().add(T, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1337
+ S += e * 60, P = p.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
1338
1338
  }
1339
1339
  }
1340
1340
  return i;
@@ -1364,9 +1364,9 @@ 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 p = v.calculateDistance(t, o), S = v.calculateDistance(t, r);
1368
+ if (p > 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, p, S, {
1370
1370
  from: t,
1371
1371
  t1: o,
1372
1372
  t2: r,
@@ -1428,18 +1428,18 @@ class z {
1428
1428
  static tropicalCenterTwin(t, e = 24, n = {}) {
1429
1429
  var u, l, g, h, p;
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 = (p = Object.keys(i || {}).filter((S) => Number(S) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : p.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) {
@@ -1483,11 +1483,11 @@ typeof globalThis < "u" && typeof globalThis.Buffer > "u" && (globalThis.Buffer
1483
1483
  });
1484
1484
  let x;
1485
1485
  try {
1486
- x = w.getLogger("meteo");
1486
+ x = F.getLogger("meteo");
1487
1487
  } catch {
1488
1488
  } finally {
1489
1489
  }
1490
- function q() {
1490
+ function X() {
1491
1491
  if (typeof DOMParser < "u")
1492
1492
  return new DOMParser();
1493
1493
  const { JSDOM: D } = require("jsdom"), { DOMParser: t } = new D("").window;
@@ -1684,39 +1684,53 @@ class R {
1684
1684
  }
1685
1685
  /**
1686
1686
  * 从 ZIP ArrayBuffer 中异步解析所有文件条目(浏览器 DecompressionStream)。
1687
+ * 使用 Central Directory 解析,避免 Data Descriptor 导致的大小不准问题。
1687
1688
  */
1688
1689
  static async _parseZipEntries(t) {
1689
- var c;
1690
+ var g;
1690
1691
  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
- let s = 0;
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) {
1692
+ let s = -1;
1693
+ for (let h = n.byteLength - 22; h >= 0; h--)
1694
+ if (i.getUint32(h, !0) === 101010256) {
1695
+ s = h;
1696
+ break;
1697
+ }
1698
+ if (s < 0)
1699
+ throw new Error("Invalid ZIP file: EOCD not found");
1700
+ i.getUint16(s + 8, !0);
1701
+ const c = i.getUint32(s + 12, !0), a = i.getUint32(s + 16, !0);
1702
+ let u = a;
1703
+ const l = a + c;
1704
+ for (; u < l; ) {
1705
+ if (i.getUint32(u, !0) !== 33639248)
1706
+ throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${u}`);
1707
+ const p = i.getUint16(u + 10, !0), S = i.getUint32(u + 20, !0), m = i.getUint16(u + 28, !0), y = i.getUint16(u + 30, !0), P = i.getUint16(u + 32, !0), M = i.getUint32(u + 42, !0), T = o.slice(u + 46, u + 46 + m), N = new TextDecoder().decode(T), $ = i.getUint16(M + 26, !0), E = i.getUint16(M + 28, !0), O = M + 30 + $ + E, w = o.slice(O, O + S);
1708
+ if (p === 0)
1709
+ r.set(N, w);
1710
+ else if (p === 8) {
1697
1711
  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;
1712
+ const B = new DecompressionStream("deflate-raw"), k = B.writable.getWriter(), Z = B.readable.getReader();
1713
+ k.write(w), k.close();
1714
+ const W = [];
1715
+ let U = 0;
1702
1716
  for (; ; ) {
1703
- const { done: E, value: B } = await S.read();
1704
- if (E)
1717
+ const { done: A, value: L } = await Z.read();
1718
+ if (A)
1705
1719
  break;
1706
- N.push(B), $ += B.length;
1720
+ W.push(L), U += L.length;
1707
1721
  }
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);
1713
- } else if (typeof process < "u" && ((c = process.versions) != null && c.node))
1722
+ const q = new Uint8Array(U);
1723
+ let j = 0;
1724
+ for (const A of W)
1725
+ q.set(A, j), j += A.length;
1726
+ r.set(N, q);
1727
+ } else if (typeof process < "u" && ((g = process.versions) != null && g.node))
1714
1728
  try {
1715
- r.set(T, R._inflateRawSync(y));
1729
+ r.set(N, R._inflateRawSync(w));
1716
1730
  } catch {
1717
1731
  }
1718
1732
  }
1719
- s = m + l;
1733
+ u += 46 + m + y + P;
1720
1734
  }
1721
1735
  return r;
1722
1736
  }
@@ -1732,39 +1746,39 @@ class R {
1732
1746
  static async convertKML2GeoJSON(t, e = {}) {
1733
1747
  var s, c;
1734
1748
  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 = [];
1749
+ const i = X().parseFromString(t, "application/xml"), o = Array.from(i.querySelectorAll("Placemark")), r = [];
1736
1750
  for (const a of o) {
1737
1751
  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();
1752
+ for (const T of l) {
1753
+ const N = T.getAttribute("name"), $ = (c = (s = T.querySelector("value")) == null ? void 0 : s.textContent) == null ? void 0 : c.trim();
1740
1754
  N && $ !== void 0 && $ !== null && (u[N] = $);
1741
1755
  }
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) => {
1756
+ const g = b.utc(), h = Object.keys(u).find((T) => T.toLowerCase().indexOf("name") !== -1), p = h ? u[h] : void 0, S = `${g.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, m = (T) => T.trim().split(/[\s\n]+/).filter((N) => N.length > 0).map((N) => {
1743
1757
  const $ = N.split(",").map(Number);
1744
1758
  return [$[0], $[1]];
1745
1759
  }), y = a.querySelector("LineString > coordinates");
1746
1760
  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 });
1761
+ const T = m(y.textContent || "");
1762
+ if (T.length >= 2) {
1763
+ const N = f.lineString(T, { ...u, shape: "line", id: S, name: p });
1750
1764
  r.push(N);
1751
1765
  }
1752
1766
  continue;
1753
1767
  }
1754
1768
  const P = a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");
1755
1769
  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 });
1770
+ const T = m(P.textContent || "");
1771
+ if (T.length >= 4) {
1772
+ const N = T[0][0] === T[T.length - 1][0] && T[0][1] === T[T.length - 1][1] ? T : [...T, T[0]], $ = f.polygon([N], { ...u, shape: "polygon", id: S, name: p });
1759
1773
  r.push($);
1760
1774
  }
1761
1775
  continue;
1762
1776
  }
1763
1777
  const M = a.querySelector("Point > coordinates");
1764
1778
  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 });
1779
+ const T = m(M.textContent || "");
1780
+ if (T.length >= 1) {
1781
+ const N = f.point(T[0], { ...u, shape: "point", id: S, name: p });
1768
1782
  r.push(N);
1769
1783
  }
1770
1784
  continue;
@@ -1822,7 +1836,7 @@ class R {
1822
1836
  x.info("[%s] convert shp zip to geojson", e == null ? void 0 : e.requestId);
1823
1837
  try {
1824
1838
  typeof Buffer < "u" && Buffer.isBuffer(t) && (t = R.toArrayBuffer(t));
1825
- const n = await k(t);
1839
+ const n = await z(t);
1826
1840
  if (Array.isArray(n)) {
1827
1841
  const i = n.flatMap((c) => c.features || []), o = b.utc(), r = (e == null ? void 0 : e.id) || o.valueOf().toString(), s = {
1828
1842
  Point: "point",
@@ -1836,7 +1850,7 @@ class R {
1836
1850
  var p;
1837
1851
  const u = ((p = c.geometry) == null ? void 0 : p.type) || "", l = s[u] || u.toLowerCase();
1838
1852
  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;
1853
+ const g = Object.keys(c.properties).find((S) => S.toLowerCase().indexOf("name") !== -1), h = g ? c.properties[g] : void 0;
1840
1854
  c.properties.name = h || `${l}_${o.format()}_${a}`;
1841
1855
  }), f.featureCollection(i);
1842
1856
  }
@@ -1847,9 +1861,9 @@ class R {
1847
1861
  }
1848
1862
  }
1849
1863
  export {
1850
- W as AisHelper,
1864
+ J as AisHelper,
1851
1865
  R as GeoJsonHelper,
1852
1866
  v as LaneHelper,
1853
1867
  d as LngLatHelper,
1854
- z as TropicalHelper
1868
+ H as TropicalHelper
1855
1869
  };
@@ -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(`
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(`
4
- `)}static csvEscapeField(e){if(e==null)return"";const t=String(e);return t.includes(",")||t.includes('"')||t.includes(`
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"})});
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,k,_,J,X){"use strict";function V(C){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(C){for(const e in C)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(C,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>C[e]})}}return t.default=C,Object.freeze(t)}const h=V(I);class d{static guessTimeZoneOffset(t,e){t=d.convertToStdLng(t);const n=J(e,t),i=b().tz(n).utcOffset();return d.roundPrecision(i/60,1)}static prettyTimeZoneOffset(t){let e=Math.floor(Math.abs(t)),n=Math.round((Math.abs(t)-e)*60);return n=n>9?n:`0${n}`,e=e>9?e:`0${e}`,t>0?`+${e}:${n}`:`-${e}:${n}`}static lng2pretty(t,e=6,n="H°M′"){t=d.convertToStdLng(t,e);let i="E";t<0&&(i="W"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,e).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,e).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,e),minute:d.roundPrecision(c,e),second:d.roundPrecision(r,e),pretty:g,S:s,M:a,H:l}}static lat2pretty(t,e=6,n="H°M′"){t=t%180;let i="N";t<0&&(i="S"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,e).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,e).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,e),minute:d.roundPrecision(c,e),second:d.roundPrecision(r,e),pretty:g,S:s,M:a,H:l}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=d.strReplace(t,"LNG");const i=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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(t);return d.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=d.strReplace(t,"LAT");const i=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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: ${t}${i}`);i==="S"&&(n=n*-1)}else n=Number(t);return d.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=d.strReplace(t,n);const i=t[t.length-1].toUpperCase();return["N","S"].includes(i)?{lat:d.str2Lat(t,e)}:{lng:d.str2Lng(t,e)}}static convertToStdLng(t,e=6){return t>180?(t=t%360,t=t>180?t-360:t):t<-180&&(t=t%360,t=t<-180?t+360:t),d.roundPrecision(t,e)}static roundPrecision(t,e=6){const n=Number("1".padEnd(e+1,"0"));return Math.round(t*n)/n}static convertToMonotonicLng2(t){for(let e=1;e<t.length;e++)t[e][0]+=Math.round((t[e-1][0]-t[e][0])/360)*360;return t}static convertToMonotonicLng(t){for(let e=1;e<t.length;e++)t[e].lng+=Math.round((t[e-1].lng-t[e].lng)/360)*360;return t}static strReplace(t,e="LAT"){t=t.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=t[t.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const i=t,o=Number(i.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${t}`);o>=90?t=`${i}E`:o<=-90?t=`${i}W`:["LAN","LNG"].includes(e==null?void 0:e.toUpperCase())?t=`${i}${o>0?"E":"W"}`:t=`${i}${o>0?"N":"S"}`}return t}static padNumber(t,e=2,n=2){const i=d.roundPrecision(t-Math.trunc(t),n),o=i>=1?Math.trunc(t+1).toString().padStart(e,"0"):Math.trunc(t).toString().padStart(e,"0");return i>=1?o:n>0?`${o}.${Math.trunc(i*Math.pow(10,n)).toString().padStart(n,"0")}`:o}}class j{static json2Str(t){const e=t.type?t.type[0].toUpperCase():"A";return`${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo||{})}|${t.vendor}|${t.deleted}`}static str2Json(t){const[e,n,i,o,r,s,c,a,u,l,g]=t.split("|");return{lat:Number(e),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(t,e=1,n=!0){const i=t.at(0).positionTime<t.at(-1).positionTime;i||t.sort((c,a)=>c.positionTime-a.positionTime);const o=[];let r,s;for(let c=0;c<t.length-1;c++){const a=t[c];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let u=c+1;u<t.length;u++){const l=t[u-1],g=t[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)<e)r||(r=a),u===t.length-1&&(s=g,c=u);else{r&&(s=t[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=t.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||t.sort((c,a)=>a.positionTime-c.positionTime),o}static inspectSummary(t,e,n){const i=b(e),o=b(n),r=t.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=k.getLogger("meteo")}catch{}finally{}class y{static calculateBearing(t,e,n=!0,i=4){const o=h.points([[t.lng,t.lat],[e.lng,e.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(t,e,n=!0,i=4,o="nauticalmiles"){t={...t},e={...e},t.lng=d.convertToStdLng(t.lng,i),e.lng=d.convertToStdLng(e.lng,i);const r=h.points([[t.lng,t.lat],[e.lng,e.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(t,e=4,n="nauticalmiles"){let i=0,o;for(const r of t)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,e,n));const a={lng:r[s+1][0],lat:r[s+1][1]};i+=this.calculateDistance(c,a,!0,e,n),o=a}return d.roundPrecision(i,e)}static calculateCoordinate(t,e,n,i="nauticalmiles",o=!0){const r=h.point([t.lng,t.lat]);let s;o?s=h.rhumbDestination(r,n,e,{units:i}):s=h.destination(r,n,e,{units:i});const c=s.geometry.coordinates;return{lng:d.convertToStdLng(c[0],8),lat:d.roundPrecision(c[1],8)}}static interpolateCoordinates(t,e,n,i=!0,o=!0,r="nauticalmiles"){const s=[],c=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,r);i&&s.push({lng:t.lng,lat:t.lat});let u=0;for(;u<a;)u+=n,u<a&&s.push(this.calculateCoordinate(t,c,u,r,!1));return o&&s.push({lng:e.lng,lat:e.lat}),s}static divideAccordingToLng(t,e=!1,n=!0){if((t==null?void 0:t.length)<2)return[];t=n?this.deduplicateCoordinates(t):t;let i=[];const o=[];let r,s;for(let c=0;c<t.length-1;c++){r=d.convertToStdLng(t[c].lng,8),s=d.convertToStdLng(t[c+1].lng,8),t[c].lat=d.roundPrecision(t[c].lat,8),t[c+1].lat=d.roundPrecision(t[c+1].lat,8),i.push([r,t[c].lat]);const a=r-s;if(Math.abs(a)>180){const u=d.convertToMonotonicLng2([[r,t[c].lat],[s,t[c+1].lat]]);let l,g;e?(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 m;if(f.features.length){const S=h.getCoord(f.features[0]);m=d.roundPrecision(S[1],8)}else m=t[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===t.length-2&&i.push([s,t[c+1].lat])}return o.push(i),o}static deduplicateRoute(t){const e=[];for(const n of t){const i=n.reduce((o,r)=>(o.findIndex(s=>s[0]===r[0]&&s[1]===r[1])===-1&&o.push(r),o),[]);e.push(i)}return e}static deduplicateCoordinates(t){return t.reduce((e,n)=>(e.findIndex(i=>i.lat===n.lat&&i.lng===n.lng)===-1&&e.push(n),e),[])}static removeCoordinateFromRoute(t,e){t.lng=d.convertToStdLng(t.lng,8);for(const n of e)for(let i=n.length-1;i>=0;i--)d.roundPrecision(n[i][0],8)===t.lng&&d.roundPrecision(n[i][1],8)===d.roundPrecision(t.lat,8)&&n.splice(i,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=d.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)d.roundPrecision(e[n].lng,8)===t.lng&&d.roundPrecision(e[n].lat,8)===d.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=d.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,i=0,o=0,r,s;return e.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(t,l,g);n>f&&(n=f,o=u,i=a,r=this.calculateDistance(l,t),s=this.calculateDistance(g,t))}}),r!==0&&s!==0?e[i].splice(o+1,0,[t.lng,t.lat]):r===0?e[i].splice(o,1,[t.lng,t.lat]):s===0&&e[i].splice(o+1,1,[t.lng,t.lat]),e}static appendCoordinateToRoute(t,e){t.lng=d.convertToStdLng(t.lng,8);const n=y.convertRouteToCoordinates(e);return n.push(t),y.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=y.convertRouteToCoordinates(e);return n.unshift(t),y.divideAccordingToLng(n)}static mergeWaypointsToRoute(t,e){for(const n of t)e=this.mergeCoordinateToRoute(n,e);return e}static calculateRangeRoute(t,e,n){n=this.mergeWaypointsToRoute([t,e],n);const i=[];let o=0;return n.forEach(r=>{if(o===2)return;const s=[];for(const c of r){if(d.roundPrecision(e.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(c[1],8)){s.push(c),o===0&&s.push([t.lng,t.lat]),o=2;break}o===1?s.push(c):d.roundPrecision(t.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(c[1],8)&&(o=1,s.push(c))}s.length&&i.push(s)}),i}static calculateRangeWaypoints(t,e,n,i=[]){const o=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([t,e],o.length?o:i),s=r.findIndex(u=>d.roundPrecision(t.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(u.lat,8)),c=r.findIndex(u=>d.roundPrecision(e.lng,8)===d.roundPrecision(u.lng,8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(u.lat,8));return r.filter((u,l)=>l>=s&&l<=c)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,i=0,o=0;return e.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(t,a,u);n>l&&(n=l,i=c,o=s)}}),{minDist:n,segIndex:o,minIndex:i}}static calculateSubRoute(t,e){const n=y.convertRouteToCoordinates(e);y.mergeCoordinateToWaypoints(t,n,!0),e=y.divideAccordingToLng(n);const{segIndex:i,minIndex:o}=this.calculateMinDistanceToRoute({...t},e);t.lng=d.convertToStdLng(t.lng);const r=[];let s=!0;for(let c=i;c<e.length;c++)if(s){const a=[];a.push([t.lng,t.lat]);for(let u=o+1;u<e[c].length;u++)t.lng===e[c][u][0]&&t.lat===e[c][u][1]||a.push(e[c][u]);r.push(a),s=!1}else r.push([...e[c]]);return r}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,i=0;for(let r=0;r<e.length-1;r++){const s=e[r],c=e[r+1];if(this.calculateDistance(t,s)===0)return e;if(this.calculateDistance(t,c)===0)return e.filter((u,l)=>l>0);const a=this.calculatePointToLineDistance(t,s,c);n>a&&(n=a,i=r)}t.lng=d.convertToStdLng(t.lng);const o=[t];for(let r=i+1;r<e.length;r++)o.push(e[r]);return o}static calculatePointToLineDistance(t,e,n,i={units:"nauticalmiles",method:"geodesic"}){t.lng=d.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=d.convertToStdLng(e.lng,8),n.lng=d.convertToStdLng(n.lng,8);const o=d.convertToMonotonicLng([e,n]);e=o[0],n=o[1];const r=h.lineString([[e.lng,e.lat],[n.lng,n.lat]]),s=h.pointToLineDistance(h.point([t.lng,t.lat]),r,i),c=h.pointToLineDistance(h.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),r,i);return d.roundPrecision(Math.min(s,c),6)}static calculateWaypointsPropInRoute(t,e){e=this.mergeWaypointsToRoute(t,e);for(let n=0;n<t.length-1;n++){const i=t[n],o=t[n+1],r=this.calculateRangeRoute(i,o,e);n===0&&(i.distanceFromPrevious=0,i.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(r),o.distanceFromStart=d.roundPrecision((i.distanceFromStart||0)+o.distanceFromPrevious)}return t}static mergeCoordinatesToWaypoints(t,e,n=!0){for(const i of t)this.mergeCoordinateToWaypoints(i,e,n);return e}static mergeCoordinateToWaypoints(t,e,n=!0){t.lng=d.convertToStdLng(t.lng,8);let i=Number.MAX_VALUE,o=0,r=0,s=0;if(e.length<2)e.push(t);else{for(let c=0;c<e.length-1;c++){const a={lng:e[c].lng,lat:e[c].lat},u={lng:e[c+1].lng,lat:e[c+1].lat},l=this.calculatePointToLineDistance(t,a,u);i>=l&&(i=l,o=c,r=this.calculateDistance(a,t,!1,6),s=this.calculateDistance(u,t,!1,6))}r!==0&&s!==0?r<=i&&o===0?e.unshift(t):s<=i&&o===e.length-2?e.push(t):e.splice(o+1,0,t):r===0?n?e.splice(o,1,t):e.splice(o+1,0,t):s===0&&(n?e.splice(o+1,1,t):e.splice(o+1,0,t))}return e.map((c,a)=>{c.lng=d.convertToStdLng(c.lng);const u=e[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(t,e=!0,n=!0){const i=[];for(let o=1;o<t.length;o++){const r=t[o-1],s=t[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,e,n)}static nearestCoordinateInRoute(t,e){const n=h.point([t.lng,t.lat]),o=this.convertRouteToCoordinates(e).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(t,e){let n=0;this.mergeCoordinateToWaypoints(t,e);for(let i=0;i<e.length-1;i++){const o=e[i],r=e[i+1];if(this.calculateDistance(t,o)===0){n=i;break}if(this.calculateDistance(t,r)===0){n=i+1;break}}return e[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(t,e,n,i="nauticalmiles"){var g;const o=t.speed||12,r=[];let s=[],c=!1,a=0,u=0,l;if(e&&n.length?(r.push(t),n.forEach((f,m)=>{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(t,p,!0,8,i);if(a+=P,a<e)u+=P,P&&r.push(p),t=p;else{if(u=e,a===e)l=p,S.push([l.lng,l.lat]);else{const M=a-e,T=this.calculateBearing(p,t);l=this.calculateCoordinate(p,T,M,i),S.push([l.lng,l.lat]),S.push([p.lng,p.lat])}c=!0}}S.length&&s.push(S),m===n.length-1&&!l&&(l=p)}})):(s=n,l={...t}),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(t,e,n){const i=d.convertToStdLng(t.lng,6),o=h.point([i,t.lat]),r=d.convertToStdLng(e.lng,6),s=d.convertToStdLng(n.lng,6),c=h.lineString([[r,e.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===e.lat)&&!(l===s&&g===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let i,o;return t.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>=e&&(i.bearing=this.calculateBearing(i,c,!0),n.push(i),o=i)}i=c})}),i&&n.push(i),n}static simplifyRouteToCoordinates(t,e,n=1){let i=this.convertRouteToCoordinates(t,n);return i=this.simplifyGCCoordinates(i,e),i}static simplifyGCCoordinates(t,e){e.forEach(i=>{this.mergeCoordinateToWaypoints(i,t,!0)});for(let i=1;i<e.length;i++){const o=e[i-1],r=e[i];if(r.gcToPrevious){const s=t.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=t.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=c-1;a>s;a--)t.splice(a,1)}}let n=0;for(let i=1;i<t.length;i++){const o=t[i-1],r=t[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 t.map(i=>(i.lng=d.convertToStdLng(i.lng),i))}static calculateCenter(t){const e=[];for(const s of t)for(const c of s)e.push(c);const n=h.featureCollection([]),i=d.convertToMonotonicLng2(e);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(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateCenter(e)}static calculateBBox(t){const e=[];for(const o of t)for(const r of o)e.push(r);const n=d.convertToMonotonicLng2(e),i=h.lineString(n);return h.bbox(i)}static calculateBBox2(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateBBox(e)}static simplifyCoordinates(t,e=1,n=180){const i=[];for(let o=1;o<t.length;o++){const r=t[o-1],s=t[o],c=t[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),m=(Math.pow(l,2)+Math.pow(g,2)-Math.pow(f,2))/(2*l*g);Math.round(Math.acos(m)*180/Math.PI)<n&&f>e&&!u&&(i.push(s),o++)}if(o>=t.length-1){const l=t.at(-1);l&&i.push(l)}}return i}static nearestTSPointInWaypoints(t,e,n){const i=b.unix(t),o=n.filter(r=>i.clone().subtract(e,"hour").unix()<=(r.positionTime||0)&&i.clone().add(e,"h").unix()>=(r.positionTime||0));return o.sort((r,s)=>(r.positionTime||0)-(s.positionTime||0)),o.at(-1)}static deadReckoning(t,e){var o,r,s,c;t>1e12&&(t=Math.round(t/1e3));const n=b.unix(t);let i=e.find(a=>a.positionTime===n.unix());if(!i){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);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(t,e){e=JSON.parse(JSON.stringify(e)),e.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<e.length-1;a++){const u=e[a],l=e[a+1],g=y.calculatePointToLineDistance(t,u,l);g<n&&(n=g,i=a)}const o=e[i],r=e[i+1],s=y.calculateDistance(o,t),c=y.calculateDistance(r,t);if(s===0)t=o;else if(c===0)t=r;else{const a=o.positionTime||0,u=r.positionTime||0,l=y.calculateDistance(o,r);t.positionTime=Math.round(a+(u-a)*(s/l))}return t.utc=t.positionTime?b.unix(t.positionTime).utc().format():void 0,t.positionTime?t:void 0}static reverseRoute(t){const e=[];for(const n of t)e.push(n.reverse());return e}static reverseCoordinates(t){return t.reverse()}static xmlEscape(t){return t==null?"":String(t).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(t,e){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(t)}"></routeInfo>`),i.push(...y.toRTZWaypoints(e,6)),i.push("</route>"),i.join(`
2
+ `)}static waypoints2RTZ10(t,e,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(t)}"></routeInfo>`),o.push(...y.toRTZWaypoints(e,6,n)),o.push("</route>"),o.join(`
3
+ `)}static toRTZWaypoints(t,e=6,n=!0){const i=[];i.push(" <waypoints>");for(let o=0;o<t.length;o++){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"'];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(t,e,n){A.debug("keep name for waypoints2CSV for legacy compatibility only",t);const i=(n==null?void 0:n.precision)??6,o=e.some(p=>p.name),r=e.some(p=>p.description),s=e.some(p=>p.port!=null),c=e.some(p=>p.stbd!=null),a=e.some(p=>p.arrRad!=null),u=e.some(p=>p.speed!=null),l=e.some((p,v)=>v>0&&p.gcToPrevious!=null),g=e.some(p=>p.bearing!=null),f=e.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]"),f&&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 S=[];S.push(m.map(p=>y.csvEscapeField(p)).join(","));for(let p=0;p<e.length;p++){const v=e[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
+ `)}static csvEscapeField(t){if(t==null)return"";const e=String(t);return e.includes(",")||e.includes('"')||e.includes(`
5
+ `)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}static decimalToNmeaDm(t,e){const n=Math.abs(t),i=Math.floor(n),o=(n-i)*60,r=e?`${i.toString().padStart(2,"0")}${o.toFixed(2).padStart(5,"0")}`:`${i.toString().padStart(3,"0")}${o.toFixed(2).padStart(5,"0")}`,s=e?t>=0?"N":"S":t>=0?"E":"W";return{dm:r,dir:s}}static nmeaChecksum(t){let e=0;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n);return e.toString(16).toUpperCase().padStart(2,"0")}static waypoints2NMEA(t){const e=[];for(let n=0;n<t.length;n++){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);e.push(`$${c}*${a}`)}return e.join(`\r
6
+ `)}static coordinatesSummary(t,e=3){if(t.length>1){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((f,m)=>(f.duration+=m.duration,f.distance+=m.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(t,e){var u,l,g;if(!((l=(u=e==null?void 0:e.sample)==null?void 0:u.hours)!=null&&l.length))return{routes:[],hour:void 0};const n=e.sample.hours.at(0),i=b.utc(t),o=b.utc(e.eta),r=i.isAfter(o)?o:i;let s=e.sample.all.find(f=>f.eta===r.format());if(!s){const f=e.sample.all.filter(N=>b.utc(N.eta).isBefore(r)).at(-1),m=this.calculateSubRoute(f,e.route);s=(g=this.calculateNextCoordinateAlongRoute(f,f.speed*r.diff(b(f.etd),"hours",!0),m))==null?void 0:g.coordinate;const{cFactor:S,cog:p,wxFactor:v,meteo:P}=f,M=Math.round(s.distanceFromPrevious*1e4)/1e4,T=Math.round((M+f.distanceFromStart)*1e4)/1e4;s={...s,cFactor:S,cog:p,speed:f.speed,wxFactor:v,distanceFromStart:T,distanceFromPrevious:M,meteo:P,eta:r.format(),etd:r.format()}}s.distanceToGo=Math.round((e.distance-s.distanceFromStart)*100)/100,s.timeToGo=Math.round(o.diff(s.etd,"hours",!0)*100)/100;const c=this.calculateRangeWaypoints(n,s,e.route);return{routes:this.generateRouteAccordingToWaypoints(c),hour:s}}static pickUTCSampleFromRoute(t,e,n){var f;const i=this.calculateSubRoute(e,n),o=this.calculateRouteDistance(i),r=o/e.speed,s=b.utc(t),c=b(e.etd),a=(f=this.calculateNextCoordinateAlongRoute(e,e.speed*s.diff(b(e.etd),"hours",!0),i))==null?void 0:f.coordinate;a.speed=e.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(e,a,n);return{routes:this.generateRouteAccordingToWaypoints(l),hour:a}}static includedAngle(t,e){A==null||A.debug("calculate bearing via: %j",{bearing:t,degree:e});let n=Math.abs(t%360-(e%360||0));return n=n>180?360-n:n,n}}let D;try{D=k.getLogger("vessel")}catch{}finally{}class K{static convert2Geojson(t){var n,i,o;const e=h.featureCollection([]);for(const r of t){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 m={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);m.kts=Math.round(v/P*100)/100,m.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:m,category:f,type:"forecast",important:!0});l.unshift(p),u.unshift(p.geometry.coordinates)}if(e.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:m});e.features.push(S)}}}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){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(),m=f.isSameOrBefore(a)||f.isSame(u);m&&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:m});e.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});e.features.push(g)}}}return e}static interpolate(t,e=3){var o,r,s,c;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=[];for(const a of n){const u=a.properties.name,l=a.properties.model,g=a.properties.showCircle,f=a.properties.disabled,m=b(a.properties.date).utc();let S=e*60;const p=(r=t==null?void 0:t.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(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],T=v===0?void 0:p[v-1],N=(S/60-((s=T==null?void 0:T.properties)==null?void 0:s.hour))/(M.properties.hour-((c=T==null?void 0:T.properties)==null?void 0:c.hour)),R=this.computeNumber(T==null?void 0:T.geometry.coordinates[0],M.geometry.coordinates[0],N),F=this.computeNumber(T==null?void 0:T.geometry.coordinates[1],M.geometry.coordinates[1],N),E=h.point([R,F],{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(T==null?void 0:T.properties.gusts,M.properties.gusts,N),hour:this.computeNumber(T==null?void 0:T.properties.hour,M.properties.hour,N),movement:this.computeNumber(T==null?void 0:T.properties.movement,M.properties.movement,N),pressure:this.computeNumber(T==null?void 0:T.properties.pressure,M.properties.pressure,N),wind:this.computeNumber(T==null?void 0:T.properties.wind,M.properties.wind,N),type:"forecast",disabled:f,showCircle:g});i.push(E)}S+=e*60,P=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return i}static accelPassageAt(t,e){const{t1:n,t2:i,hr:o,hours:r}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:i,hr:o,hours:r}}static diversionPassageAt(t,e,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(e,24,i);if(o&&r){if(!i.debug){const m=y.calculateDistance(t,o),S=y.calculateDistance(t,r);if(m>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,m,S,{from:t,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(t,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:t,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(t,e,n,i={}){const{t1:o,t2:r,hr:s,hours:c}=this.tropicalCenterTwin(e,24,i);if(o&&r){if(!i.debug){const f=y.calculateDistance(t,o),m=y.calculateDistance(t,r);if(f>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,f,m,{from:t,t1:o,t2:r,hr:s}),{}}const a=y.calculateBearing(t,o),u=y.calculateBearing(o,r),l=y.calculateDistance(t,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:t,t1:o,t2:r,hr:s}),{}}static tropicalCenterTwin(t,e=24,n={}){var u,l,g,f,m;let i={};(u=t.forecasts)==null||u.forEach(S=>{i={...S.hours,...i}});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]]);D==null||D.info("[%s] the first tropical center: %j",n.requestId,o);let r=(f=Object.keys(i||{}).filter(S=>Number(S)<=(e<0?24:e)))==null?void 0:f.at(-1);r||(r=(m=Object.keys(i||{}).filter(S=>Number(S)<=(e<0?24:2*e)))==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(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(t,e){let n=0;for(const i of t){if(b(i.properties.date).isAfter(e))return n===0?-1:n;n++}return n}static computeNumber(t,e,n){if(t)if(e){if(isNaN(t)&&isNaN(e)&&typeof t!="string"&&typeof e!="string"){const i={};for(const o in t)i[o]=this.computeNumber(t[o],e[o],n);return i}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,t){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=k.getLogger("meteo")}catch{}finally{}function Q(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:t}=new C("").window;return new t}class O{static toArrayBuffer(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}static drawCircle(t,e,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([t,e]),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=[t,e],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(t,e,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=t.map(u=>d.roundPrecision(u,9)),i.end=e.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([t,e]),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(t,e={}){const n=(e==null?void 0:e.properties)??{},i=b.utc();n.id=(e==null?void 0:e.id)||i.valueOf().toString();const o="line";n.name=(e==null?void 0:e.name)||`${o}_${i.format()}`,n.shape="line",x.info("[%s] draw line with %j",e==null?void 0:e.requestId,n);const r=d.convertToMonotonicLng2(t);return h.lineString(r,n)}static drawPolygon(t,e={}){const n=(e==null?void 0:e.properties)??{},i=b.utc();n.id=(e==null?void 0:e.id)||i.valueOf().toString();const o="polygon";n.name=(e==null?void 0:e.name)||`${o}_${i.format()}`,n.coordinates=t.map(s=>s.map(c=>d.roundPrecision(c,9))),n.shape="polygon",x.info("[%s] draw polygon with %j",e==null?void 0:e.requestId,n);const r=d.convertToMonotonicLng2(t);return h.polygon([r],n)}static drawPoint(t,e,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([e,t],i)}static parseCircle(t,e={}){var i,o;x.info("[%s] parse circle with %j",e==null?void 0:e.requestId,t.properties);const n=t.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(t);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=h.polygonToLine(t);l=h.pointToLineDistance(c,m,{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,t])}else return x.warn("[%s] not a orm-std circle, just return the original feature",e==null?void 0:e.requestId),h.featureCollection([t])}static parseRect(t,e={}){x.info("[%s] parse rect with %j",e==null?void 0:e.requestId,t.properties);const n=t.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=t.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,t])}else return x.warn("[%s] not a orm-std rect, just return the original feature",e==null?void 0:e.requestId),h.featureCollection([t])}static parseLine(t,e={}){x.info("[%s] parse line with %j",e==null?void 0:e.requestId,t.properties);const n=t.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=t.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,t])}else return x.warn("[%s] not a orm-std line, just return the original feature",e==null?void 0:e.requestId),h.featureCollection([t])}static parsePolygon(t,e={}){x.info("[%s] parse polygon with %j",e==null?void 0:e.requestId,t.properties);const n=t.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=t.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,t])}else return x.warn("[%s] not a orm-std polygon, just return the original feature",e==null?void 0:e.requestId),h.featureCollection([t])}static _inflateRawSync(t){var e;if(typeof process<"u"&&((e=process.versions)!=null&&e.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(t)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(t){var g;const e=new Uint8Array(t),n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),i=new DataView(n),o=new Uint8Array(n),r=new Map;let s=-1;for(let f=n.byteLength-22;f>=0;f--)if(i.getUint32(f,!0)===101010256){s=f;break}if(s<0)throw new Error("Invalid ZIP file: EOCD not found");i.getUint16(s+8,!0);const c=i.getUint32(s+12,!0),a=i.getUint32(s+16,!0);let u=a;const l=a+c;for(;u<l;){if(i.getUint32(u,!0)!==33639248)throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${u}`);const m=i.getUint16(u+10,!0),S=i.getUint32(u+20,!0),p=i.getUint16(u+28,!0),v=i.getUint16(u+30,!0),P=i.getUint16(u+32,!0),M=i.getUint32(u+42,!0),T=o.slice(u+46,u+46+p),N=new TextDecoder().decode(T),R=i.getUint16(M+26,!0),F=i.getUint16(M+28,!0),E=M+30+R+F,B=o.slice(E,E+S);if(m===0)r.set(N,B);else if(m===8){if(typeof DecompressionStream<"u"){const q=new DecompressionStream("deflate-raw"),W=q.writable.getWriter(),Y=q.readable.getReader();W.write(B),W.close();const U=[];let L=0;for(;;){const{done:w,value:G}=await Y.read();if(w)break;U.push(G),L+=G.length}const Z=new Uint8Array(L);let z=0;for(const w of U)Z.set(w,z),z+=w.length;r.set(N,Z)}else if(typeof process<"u"&&((g=process.versions)!=null&&g.node))try{r.set(N,O._inflateRawSync(B))}catch{}}u+=46+p+v+P}return r}static async convertKML2GeoJSON(t,e={}){var s,c;x.info("[%s] convert kml to geojson",e==null?void 0:e.requestId);const i=Q().parseFromString(t,"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 T of l){const N=T.getAttribute("name"),R=(c=(s=T.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(T=>T.toLowerCase().indexOf("name")!==-1),m=f?u[f]:void 0,S=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,p=T=>T.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 T=p(v.textContent||"");if(T.length>=2){const N=h.lineString(T,{...u,shape:"line",id:S,name:m});r.push(N)}continue}const P=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(P){const T=p(P.textContent||"");if(T.length>=4){const N=T[0][0]===T[T.length-1][0]&&T[0][1]===T[T.length-1][1]?T:[...T,T[0]],R=h.polygon([N],{...u,shape:"polygon",id:S,name:m});r.push(R)}continue}const M=a.querySelector("Point > coordinates");if(M){const T=p(M.textContent||"");if(T.length>=1){const N=h.point(T[0],{...u,shape:"point",id:S,name:m});r.push(N)}continue}}return h.featureCollection(r)}static async convertKMZ2GeoJSON(t,e={}){var r;x.info("[%s] convert kmz to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=O.toArrayBuffer(t));const n=await O._parseZipEntries(t),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",e==null?void 0:e.requestId),h.featureCollection([]);const o=new TextDecoder().decode(i);return O.convertKML2GeoJSON(o,e)}static async convertZIP2GeoJSON(t,e={}){x.info("[%s] convert zip to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=O.toArrayBuffer(t));const n=await O._parseZipEntries(t),i=[];for(const[o,r]of n){if(!o.toLowerCase().endsWith(".kml"))continue;const s=new TextDecoder().decode(r),c=await O.convertKML2GeoJSON(s,e);i.push(...c.features)}return i.length===0?(x.warn("[%s] no .kml files found in zip",e==null?void 0:e.requestId),this.convertSHP2GeoJSON(t,e)):h.featureCollection(i)}static async convertSHP2GeoJSON(t,e={}){x.info("[%s] convert shp zip to geojson",e==null?void 0:e.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=O.toArrayBuffer(t));const n=await X(t);if(Array.isArray(n)){const i=n.flatMap(c=>c.features||[]),o=b.utc(),r=(e==null?void 0:e.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(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",e==null?void 0:e.requestId,n),h.featureCollection([])}}}$.AisHelper=j,$.GeoJsonHelper=O,$.LaneHelper=y,$.LngLatHelper=d,$.TropicalHelper=K,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
@@ -101,6 +101,7 @@ export declare class GeoJsonHelper {
101
101
  private static _inflateRawSync;
102
102
  /**
103
103
  * 从 ZIP ArrayBuffer 中异步解析所有文件条目(浏览器 DecompressionStream)。
104
+ * 使用 Central Directory 解析,避免 Data Descriptor 导致的大小不准问题。
104
105
  */
105
106
  private static _parseZipEntries;
106
107
  /**
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.2",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [