@idm-plugin/geo 1.4.1 → 1.4.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 +161 -161
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as g from "@turf/turf";
|
|
2
|
-
import
|
|
2
|
+
import R from "moment";
|
|
3
3
|
import "moment-timezone";
|
|
4
|
-
import
|
|
5
|
-
function
|
|
6
|
-
return
|
|
4
|
+
import A from "tz-lookup";
|
|
5
|
+
function E(M) {
|
|
6
|
+
return M && M.__esModule && Object.prototype.hasOwnProperty.call(M, "default") ? M.default : M;
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class y {
|
|
9
9
|
log() {
|
|
10
10
|
}
|
|
11
11
|
isLevelEnabled() {
|
|
@@ -18,21 +18,21 @@ class x {
|
|
|
18
18
|
clearContext() {
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((
|
|
22
|
-
|
|
23
|
-
},
|
|
21
|
+
["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((M) => {
|
|
22
|
+
y.prototype[M.toLowerCase()] = () => {
|
|
23
|
+
}, y.prototype[`is${M}Enabled`] = () => !1;
|
|
24
24
|
});
|
|
25
|
-
const
|
|
25
|
+
const k = () => {
|
|
26
26
|
try {
|
|
27
27
|
return require("log4js");
|
|
28
28
|
} catch {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
var
|
|
33
|
-
getLogger:
|
|
31
|
+
}, I = k(), F = I ? I.getLogger : () => new y();
|
|
32
|
+
var L = {
|
|
33
|
+
getLogger: F
|
|
34
34
|
};
|
|
35
|
-
const
|
|
35
|
+
const O = /* @__PURE__ */ E(L);
|
|
36
36
|
class l {
|
|
37
37
|
/**
|
|
38
38
|
* 基于输入的经度,计算出时区
|
|
@@ -40,7 +40,7 @@ class l {
|
|
|
40
40
|
* @param lat
|
|
41
41
|
*/
|
|
42
42
|
static guessTimeZoneOffset(t, e) {
|
|
43
|
-
const n =
|
|
43
|
+
const n = A(e, t), s = R().tz(n).utcOffset();
|
|
44
44
|
return this.roundPrecision(s / 60, 1);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -56,12 +56,12 @@ class l {
|
|
|
56
56
|
t = l.convertToStdLng(t, e);
|
|
57
57
|
let s = "E";
|
|
58
58
|
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
59
|
-
let o = t * 3600, i, r, c,
|
|
60
|
-
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ?
|
|
61
|
-
const p = `${n.replace(/S+/gi, r).replace(/M+/gi,
|
|
59
|
+
let o = t * 3600, i, r, c, a, d, u;
|
|
60
|
+
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = l.roundPrecision(c, e).toString().padStart(2, "0") : a = l.padNumber(c, 2, 2), o = o - c * 60), d = o / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(3, "0") : u = l.padNumber(d, 3, 2);
|
|
61
|
+
const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
62
62
|
return {
|
|
63
63
|
direction: s,
|
|
64
|
-
degree: l.roundPrecision(
|
|
64
|
+
degree: l.roundPrecision(d, e),
|
|
65
65
|
minute: l.roundPrecision(c, e),
|
|
66
66
|
second: l.roundPrecision(i, e),
|
|
67
67
|
pretty: p
|
|
@@ -77,12 +77,12 @@ class l {
|
|
|
77
77
|
t = t % 180;
|
|
78
78
|
let s = "N";
|
|
79
79
|
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
80
|
-
let o = t * 3600, i, r, c,
|
|
81
|
-
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ?
|
|
82
|
-
const p = `${n.replace(/S+/gi, r).replace(/M+/gi,
|
|
80
|
+
let o = t * 3600, i, r, c, a, d, u;
|
|
81
|
+
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = l.roundPrecision(c, e).toString().padStart(2, "0") : a = l.padNumber(c, 2, 2), o = o - c * 60), d = o / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(2, "0") : u = l.padNumber(d, 2, 2);
|
|
82
|
+
const p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
83
83
|
return {
|
|
84
84
|
direction: s,
|
|
85
|
-
degree: l.roundPrecision(
|
|
85
|
+
degree: l.roundPrecision(d, e),
|
|
86
86
|
minute: l.roundPrecision(c, e),
|
|
87
87
|
second: l.roundPrecision(i, e),
|
|
88
88
|
pretty: p
|
|
@@ -182,7 +182,7 @@ class l {
|
|
|
182
182
|
return `${s}.${o}`;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
class
|
|
185
|
+
class T {
|
|
186
186
|
/**
|
|
187
187
|
* 计算方位角
|
|
188
188
|
* @param from 坐标 {lng, lat}
|
|
@@ -229,8 +229,8 @@ class P {
|
|
|
229
229
|
for (let r = 0; r < i.length - 1; r++) {
|
|
230
230
|
const c = { lng: i[r][0], lat: i[r][1] };
|
|
231
231
|
r === 0 && o && (s += this.calculateDistance(o, c, !0, e, n));
|
|
232
|
-
const
|
|
233
|
-
s += this.calculateDistance(c,
|
|
232
|
+
const a = { lng: i[r + 1][0], lat: i[r + 1][1] };
|
|
233
|
+
s += this.calculateDistance(c, a, !0, e, n), o = a;
|
|
234
234
|
}
|
|
235
235
|
return l.roundPrecision(s, e);
|
|
236
236
|
}
|
|
@@ -259,11 +259,11 @@ class P {
|
|
|
259
259
|
* @param units 单位,默认 nm(海里)
|
|
260
260
|
*/
|
|
261
261
|
static interpolateCoordinates(t, e, n, s = !0, o = !0, i = "nauticalmiles") {
|
|
262
|
-
const r = [], c = this.calculateBearing(t, e, !1),
|
|
262
|
+
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, i);
|
|
263
263
|
s && r.push({ lng: t.lng, lat: t.lat });
|
|
264
|
-
let
|
|
265
|
-
for (;
|
|
266
|
-
|
|
264
|
+
let d = 0;
|
|
265
|
+
for (; d < a; )
|
|
266
|
+
d += n, d < a && r.push(this.calculateCoordinate(t, c, d, i, !1));
|
|
267
267
|
return o && r.push({ lng: e.lng, lat: e.lat }), r;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
@@ -288,23 +288,23 @@ class P {
|
|
|
288
288
|
o = l.convertToStdLng(t[r].lng, 8), i = l.convertToStdLng(t[r + 1].lng, 8), t[r].lat = l.roundPrecision(t[r].lat, 8), t[r + 1].lat = l.roundPrecision(t[r + 1].lat, 8), n.push([o, t[r].lat]);
|
|
289
289
|
const c = o - i;
|
|
290
290
|
if (Math.abs(c) > 180) {
|
|
291
|
-
const
|
|
291
|
+
const a = l.convertToMonotonicLng2([
|
|
292
292
|
[o, t[r].lat],
|
|
293
293
|
[i, t[r + 1].lat]
|
|
294
294
|
]);
|
|
295
|
-
let
|
|
296
|
-
e ? (
|
|
295
|
+
let d, u;
|
|
296
|
+
e ? (d = g.lineString(a), u = g.lineString([
|
|
297
297
|
[c > 0 ? 180 : -180, 89],
|
|
298
298
|
[c > 0 ? 180 : -180, -89]
|
|
299
|
-
])) : (
|
|
300
|
-
const p = g.lineIntersect(
|
|
301
|
-
let
|
|
299
|
+
])) : (d = g.greatCircle(a[0], a[1]), u = g.greatCircle([c > 0 ? 180 : -180, 89], [c > 0 ? 180 : -180, -89]));
|
|
300
|
+
const p = g.lineIntersect(d, u);
|
|
301
|
+
let f;
|
|
302
302
|
if (p.features.length) {
|
|
303
|
-
const
|
|
304
|
-
|
|
303
|
+
const v = g.getCoord(p.features[0]);
|
|
304
|
+
f = l.roundPrecision(v[1], 8);
|
|
305
305
|
} else
|
|
306
|
-
|
|
307
|
-
c > 0 ? (n.push([180 - 1e-6,
|
|
306
|
+
f = t[r].lat;
|
|
307
|
+
c > 0 ? (n.push([180 - 1e-6, f]), s.push([...n]), n = [], n.push([-(180 - 1e-6), f])) : (n.push([-(180 - 1e-6), f]), s.push([...n]), n = [], n.push([180 - 1e-6, f]));
|
|
308
308
|
}
|
|
309
309
|
r === t.length - 2 && n.push([i, t[r + 1].lat]);
|
|
310
310
|
}
|
|
@@ -366,10 +366,10 @@ class P {
|
|
|
366
366
|
static mergeCoordinateToRoute(t, e) {
|
|
367
367
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
368
368
|
let n = Number.MAX_VALUE, s = 0, o = 0, i, r;
|
|
369
|
-
return e.forEach((c,
|
|
370
|
-
for (let
|
|
371
|
-
const u = { lng: c[
|
|
372
|
-
n >
|
|
369
|
+
return e.forEach((c, a) => {
|
|
370
|
+
for (let d = 0; d < c.length - 1; d++) {
|
|
371
|
+
const u = { lng: c[d][0], lat: c[d][1] }, p = { lng: c[d + 1][0], lat: c[d + 1][1] }, f = this.calculatePointToLineDistance(t, u, p);
|
|
372
|
+
n > f && (n = f, o = d, s = a, i = this.calculateDistance(u, t), r = this.calculateDistance(p, t));
|
|
373
373
|
}
|
|
374
374
|
}), i !== 0 && r !== 0 ? e[s].splice(o + 1, 0, [t.lng, t.lat]) : i === 0 ? e[s].splice(o, 1, [t.lng, t.lat]) : r === 0 && e[s].splice(o + 1, 1, [t.lng, t.lat]), e;
|
|
375
375
|
}
|
|
@@ -380,8 +380,8 @@ class P {
|
|
|
380
380
|
*/
|
|
381
381
|
static appendCoordinateToRoute(t, e) {
|
|
382
382
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
383
|
-
const n =
|
|
384
|
-
return n.push(t),
|
|
383
|
+
const n = T.convertRouteToCoordinates(e);
|
|
384
|
+
return n.push(t), T.divideAccordingToLng(n);
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
387
387
|
* 向route头加1个坐标
|
|
@@ -389,8 +389,8 @@ class P {
|
|
|
389
389
|
* @param route
|
|
390
390
|
*/
|
|
391
391
|
static unshiftCoordinateToRoute(t, e) {
|
|
392
|
-
const n =
|
|
393
|
-
return n.unshift(t),
|
|
392
|
+
const n = T.convertRouteToCoordinates(e);
|
|
393
|
+
return n.unshift(t), T.divideAccordingToLng(n);
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
396
|
* 合并多个waypoints进航线
|
|
@@ -437,11 +437,11 @@ class P {
|
|
|
437
437
|
*/
|
|
438
438
|
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
439
439
|
const o = this.convertRouteToCoordinates(n, 0), i = this.mergeCoordinatesToWaypoints([t, e, ...s], o), r = i.findIndex(
|
|
440
|
-
(
|
|
440
|
+
(d) => l.roundPrecision(t.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(t.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
441
441
|
), c = i.findIndex(
|
|
442
|
-
(
|
|
442
|
+
(d) => l.roundPrecision(e.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
443
443
|
);
|
|
444
|
-
return i.filter((
|
|
444
|
+
return i.filter((d, u) => u >= r && u <= c);
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
447
|
* 计算坐标到航路上的最短距离
|
|
@@ -452,7 +452,7 @@ class P {
|
|
|
452
452
|
let n = Number.MAX_VALUE, s = 0, o = 0;
|
|
453
453
|
return e.forEach((i, r) => {
|
|
454
454
|
for (let c = 0; c < i.length - 1; c++) {
|
|
455
|
-
const
|
|
455
|
+
const a = { lng: i[c][0], lat: i[c][1] }, d = { lng: i[c + 1][0], lat: i[c + 1][1] }, u = this.calculatePointToLineDistance(t, a, d);
|
|
456
456
|
n > u && (n = u, s = c, o = r);
|
|
457
457
|
}
|
|
458
458
|
}), { minDist: n, segIndex: o, minIndex: s };
|
|
@@ -464,19 +464,19 @@ class P {
|
|
|
464
464
|
* @return [[[lng, lat]]]
|
|
465
465
|
*/
|
|
466
466
|
static calculateSubRoute(t, e) {
|
|
467
|
-
const n =
|
|
468
|
-
|
|
467
|
+
const n = T.convertRouteToCoordinates(e);
|
|
468
|
+
T.mergeCoordinateToWaypoints(t, n, !0), e = T.divideAccordingToLng(n);
|
|
469
469
|
const { segIndex: s, minIndex: o } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
470
470
|
t.lng = l.convertToStdLng(t.lng);
|
|
471
471
|
const i = [];
|
|
472
472
|
let r = !0;
|
|
473
473
|
for (let c = s; c < e.length; c++)
|
|
474
474
|
if (r) {
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
for (let
|
|
478
|
-
t.lng === e[c][
|
|
479
|
-
i.push(
|
|
475
|
+
const a = [];
|
|
476
|
+
a.push([t.lng, t.lat]);
|
|
477
|
+
for (let d = o + 1; d < e[c].length; d++)
|
|
478
|
+
t.lng === e[c][d][0] && t.lat === e[c][d][1] || a.push(e[c][d]);
|
|
479
|
+
i.push(a), r = !1;
|
|
480
480
|
} else
|
|
481
481
|
i.push([...e[c]]);
|
|
482
482
|
return i;
|
|
@@ -494,9 +494,9 @@ class P {
|
|
|
494
494
|
if (this.calculateDistance(t, r) === 0)
|
|
495
495
|
return e;
|
|
496
496
|
if (this.calculateDistance(t, c) === 0)
|
|
497
|
-
return e.filter((
|
|
498
|
-
const
|
|
499
|
-
n >
|
|
497
|
+
return e.filter((d, u) => u > 0);
|
|
498
|
+
const a = this.calculatePointToLineDistance(t, r, c);
|
|
499
|
+
n > a && (n = a, s = i);
|
|
500
500
|
}
|
|
501
501
|
t.lng = l.convertToStdLng(t.lng);
|
|
502
502
|
const o = [t];
|
|
@@ -560,8 +560,8 @@ class P {
|
|
|
560
560
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
561
561
|
let s = Number.MAX_VALUE, o = 0, i = 0, r = 0;
|
|
562
562
|
for (let c = 0; c < e.length - 1; c++) {
|
|
563
|
-
const
|
|
564
|
-
s >= u && (s = u, o = c, i = this.calculateDistance(
|
|
563
|
+
const a = { lng: e[c].lng, lat: e[c].lat }, d = { lng: e[c + 1].lng, lat: e[c + 1].lat }, u = this.calculatePointToLineDistance(t, a, d);
|
|
564
|
+
s >= u && (s = u, o = c, i = this.calculateDistance(a, t, !1, 6), r = this.calculateDistance(d, t, !1, 6));
|
|
565
565
|
}
|
|
566
566
|
return i !== 0 && r !== 0 ? i < s || i === s && o === 0 ? e.unshift(t) : r < s || r === s && o === e.length - 2 ? e.push(t) : e.splice(o + 1, 0, t) : i === 0 ? n && e.splice(o, 1, t) : r === 0 && n && e.splice(o + 1, 1, t), e.map((c) => (c.lng = l.convertToStdLng(c.lng), c));
|
|
567
567
|
}
|
|
@@ -588,7 +588,7 @@ class P {
|
|
|
588
588
|
* @param route [[[lng, lat]]]
|
|
589
589
|
*/
|
|
590
590
|
static nearestCoordinateInRoute(t, e) {
|
|
591
|
-
const n = g.point([t.lng, t.lat]), o = this.convertRouteToCoordinates(e).map((
|
|
591
|
+
const n = g.point([t.lng, t.lat]), o = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]), i = g.lineString(o), r = g.nearestPointOnLine(i, n), c = g.getCoord(r);
|
|
592
592
|
return { lng: l.roundPrecision(c[0], 8), lat: l.roundPrecision(c[1], 8) };
|
|
593
593
|
}
|
|
594
594
|
/**
|
|
@@ -623,37 +623,37 @@ class P {
|
|
|
623
623
|
static calculateNextCoordinateAlongRoute(t, e, n, s = "nauticalmiles") {
|
|
624
624
|
var p;
|
|
625
625
|
const o = t.speed || 12, i = [];
|
|
626
|
-
let r = [], c = !1,
|
|
627
|
-
if (e && n.length ? (i.push(t), n.forEach((
|
|
626
|
+
let r = [], c = !1, a = 0, d = 0, u;
|
|
627
|
+
if (e && n.length ? (i.push(t), n.forEach((f, v) => {
|
|
628
628
|
if (c)
|
|
629
|
-
r.push(
|
|
629
|
+
r.push(f);
|
|
630
630
|
else {
|
|
631
631
|
const m = [];
|
|
632
|
-
let
|
|
633
|
-
for (let
|
|
632
|
+
let S;
|
|
633
|
+
for (let C = 0; C < f.length; C++)
|
|
634
634
|
if (u)
|
|
635
|
-
m.push(
|
|
635
|
+
m.push(f[C]);
|
|
636
636
|
else {
|
|
637
|
-
|
|
638
|
-
const D = this.calculateDistance(t,
|
|
639
|
-
if (
|
|
640
|
-
|
|
637
|
+
S = { lng: f[C][0], lat: f[C][1] };
|
|
638
|
+
const D = this.calculateDistance(t, S, !0, 8, s);
|
|
639
|
+
if (a += D, a < e)
|
|
640
|
+
d += D, i.push(S), t = S;
|
|
641
641
|
else {
|
|
642
|
-
if (
|
|
643
|
-
u =
|
|
642
|
+
if (d = e, a === e)
|
|
643
|
+
u = S, m.push([u.lng, u.lat]);
|
|
644
644
|
else {
|
|
645
|
-
const
|
|
646
|
-
u = this.calculateCoordinate(
|
|
645
|
+
const b = a - e, h = this.calculateBearing(S, t);
|
|
646
|
+
u = this.calculateCoordinate(S, h, b, s), m.push([u.lng, u.lat]), m.push([S.lng, S.lat]);
|
|
647
647
|
}
|
|
648
648
|
c = !0;
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
|
-
m.length && r.push(m),
|
|
651
|
+
m.length && r.push(m), v === n.length - 1 && !u && (u = S);
|
|
652
652
|
}
|
|
653
653
|
})) : (r = n, u = { ...t }), u)
|
|
654
|
-
if (i.push(u), u.distanceFromPrevious =
|
|
655
|
-
const
|
|
656
|
-
u.bearing = this.calculateBearing(u,
|
|
654
|
+
if (i.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / o * 1e4) / 1e4, ((p = r[0]) == null ? void 0 : p.length) > 1) {
|
|
655
|
+
const f = { lng: r[0][1][0], lat: r[0][1][1] };
|
|
656
|
+
u.bearing = this.calculateBearing(u, f);
|
|
657
657
|
} else
|
|
658
658
|
u.bearing = 0;
|
|
659
659
|
return { coordinate: u, nextRoute: r, prevRoute: i };
|
|
@@ -668,7 +668,7 @@ class P {
|
|
|
668
668
|
const s = l.convertToStdLng(t.lng, 6), o = g.point([s, t.lat]), i = l.convertToStdLng(e.lng, 6), r = l.convertToStdLng(n.lng, 6), c = g.lineString([
|
|
669
669
|
[i, e.lat],
|
|
670
670
|
[r, n.lat]
|
|
671
|
-
]),
|
|
671
|
+
]), a = g.nearestPointOnLine(c, o), d = g.getCoord(a), u = l.roundPrecision(d[0], 6), p = l.roundPrecision(d[1], 6);
|
|
672
672
|
return { lng: u, lat: p, inline: !(u === i && p === e.lat) && !(u === r && p === n.lat) };
|
|
673
673
|
}
|
|
674
674
|
/**
|
|
@@ -687,8 +687,8 @@ class P {
|
|
|
687
687
|
else if (o.bearing === void 0)
|
|
688
688
|
o.bearing = this.calculateBearing(o, c, !0);
|
|
689
689
|
else {
|
|
690
|
-
const
|
|
691
|
-
|
|
690
|
+
const a = this.calculateDistance(s, c, !0);
|
|
691
|
+
a && a >= e && (s.bearing = this.calculateBearing(s, c, !0), n.push(s), o = s);
|
|
692
692
|
}
|
|
693
693
|
s = c;
|
|
694
694
|
});
|
|
@@ -716,9 +716,9 @@ class P {
|
|
|
716
716
|
for (let s = 1; s < e.length; s++) {
|
|
717
717
|
const o = e[s - 1], i = e[s];
|
|
718
718
|
if (i.gcToPrevious) {
|
|
719
|
-
const r = t.findIndex((
|
|
720
|
-
for (let
|
|
721
|
-
t.splice(
|
|
719
|
+
const r = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng === i.lng && a.lat === i.lat);
|
|
720
|
+
for (let a = c - 1; a > r; a--)
|
|
721
|
+
t.splice(a, 1);
|
|
722
722
|
}
|
|
723
723
|
}
|
|
724
724
|
let n = 0;
|
|
@@ -772,13 +772,13 @@ class P {
|
|
|
772
772
|
return this.calculateBBox(e);
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
-
let
|
|
775
|
+
let P;
|
|
776
776
|
try {
|
|
777
|
-
|
|
777
|
+
P = O.getLogger("vessel");
|
|
778
778
|
} catch {
|
|
779
779
|
} finally {
|
|
780
780
|
}
|
|
781
|
-
class
|
|
781
|
+
class q {
|
|
782
782
|
/**
|
|
783
783
|
* 将原始数据转换为geojson
|
|
784
784
|
* @param raw
|
|
@@ -790,56 +790,56 @@ class Z {
|
|
|
790
790
|
if (s.forecasts) {
|
|
791
791
|
const o = (n = s.history) == null ? void 0 : n[0];
|
|
792
792
|
for (const i of s.forecasts) {
|
|
793
|
-
const r = [], c =
|
|
793
|
+
const r = [], c = R(i.date).utc(), a = `${s.name}-${i.model}`;
|
|
794
794
|
if (o) {
|
|
795
|
-
const
|
|
795
|
+
const d = R(o.updated).utc(), u = g.point([o.lng, o.lat], {
|
|
796
796
|
model: i.model,
|
|
797
797
|
name: s.name,
|
|
798
|
-
date:
|
|
798
|
+
date: d.format(),
|
|
799
799
|
hour: 0,
|
|
800
|
-
format:
|
|
800
|
+
format: d.format("MMM-DD/HHmm[Z]"),
|
|
801
801
|
pressure: o.pressure > 1e4 ? l.roundPrecision(o.pressure / 100, 0) : l.roundPrecision(o.pressure, 0),
|
|
802
|
-
wind:
|
|
803
|
-
category:
|
|
802
|
+
wind: o == null ? void 0 : o.wind,
|
|
803
|
+
category: a,
|
|
804
804
|
type: "forecast"
|
|
805
805
|
});
|
|
806
806
|
e.features.push(u), r.push(u.geometry.coordinates);
|
|
807
807
|
}
|
|
808
|
-
for (const
|
|
809
|
-
const u = i.hours[
|
|
808
|
+
for (const d in i == null ? void 0 : i.hours) {
|
|
809
|
+
const u = i.hours[d];
|
|
810
810
|
u.wind.spd = u.wind.spd || u.wind.speed;
|
|
811
|
-
const p = c.clone().add(Number(
|
|
811
|
+
const p = c.clone().add(Number(d), "hour"), f = g.point([u.lng, u.lat], {
|
|
812
812
|
model: i.model,
|
|
813
813
|
name: s.name,
|
|
814
814
|
date: p.format(),
|
|
815
|
-
hour: Number(
|
|
815
|
+
hour: Number(d),
|
|
816
816
|
format: p.format("MMM-DD/HHmm[Z]"),
|
|
817
817
|
pressure: u.pressure > 1e4 ? l.roundPrecision(u.pressure / 100, 0) : l.roundPrecision(u.pressure, 0),
|
|
818
818
|
gusts: u.gusts,
|
|
819
819
|
wind: u.wind || {},
|
|
820
820
|
movement: u.movement,
|
|
821
|
-
category:
|
|
821
|
+
category: a,
|
|
822
822
|
type: "forecast"
|
|
823
823
|
});
|
|
824
|
-
e.features.push(
|
|
824
|
+
e.features.push(f), r.push(f.geometry.coordinates);
|
|
825
825
|
}
|
|
826
826
|
if ((r == null ? void 0 : r.length) > 1) {
|
|
827
|
-
const
|
|
827
|
+
const d = g.lineString(l.convertToMonotonicLng2(r), {
|
|
828
828
|
date: i.date,
|
|
829
829
|
id: s.id || s.name,
|
|
830
830
|
model: i.model,
|
|
831
831
|
name: s.name,
|
|
832
|
-
category:
|
|
832
|
+
category: a,
|
|
833
833
|
type: "forecast"
|
|
834
834
|
});
|
|
835
|
-
e.features.push(
|
|
835
|
+
e.features.push(d);
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
839
|
if (s.history) {
|
|
840
840
|
const o = [];
|
|
841
841
|
for (const r of s.history) {
|
|
842
|
-
const c =
|
|
842
|
+
const c = R(r.updated).utc(), a = g.point([r.lng, r.lat], {
|
|
843
843
|
name: s.name,
|
|
844
844
|
date: c.format(),
|
|
845
845
|
format: c.format("MMM-DD/HHmm[Z]"),
|
|
@@ -852,7 +852,7 @@ class Z {
|
|
|
852
852
|
category: `${s.name}-history`,
|
|
853
853
|
wind: r.wind
|
|
854
854
|
});
|
|
855
|
-
e.features.push(
|
|
855
|
+
e.features.push(a), o.push(a.geometry.coordinates);
|
|
856
856
|
}
|
|
857
857
|
const i = s.history[0];
|
|
858
858
|
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
@@ -878,37 +878,37 @@ class Z {
|
|
|
878
878
|
* @param step
|
|
879
879
|
*/
|
|
880
880
|
static interpolate(t, e = 3) {
|
|
881
|
-
var o, i, r, c
|
|
881
|
+
var o, i, r, c;
|
|
882
882
|
const n = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
|
|
883
883
|
for (const a of n) {
|
|
884
|
-
const
|
|
885
|
-
let
|
|
886
|
-
const
|
|
887
|
-
(b) => b.geometry.type === "Point" && b.properties.type === "forecast" && b.properties.category === `${
|
|
888
|
-
)
|
|
889
|
-
let
|
|
890
|
-
for (;
|
|
891
|
-
if (
|
|
892
|
-
const b =
|
|
893
|
-
|
|
894
|
-
const
|
|
895
|
-
name:
|
|
896
|
-
model:
|
|
884
|
+
const d = a.properties.name, u = a.properties.model, p = a.properties.showCircle, f = a.properties.disabled, v = R(a.properties.date).utc();
|
|
885
|
+
let m = e * 60 - (v.get("hour") * 60 + v.get("minute")) % (e * 60);
|
|
886
|
+
const S = (i = t == null ? void 0 : t.data) == null ? void 0 : i.features.filter(
|
|
887
|
+
(b) => b.geometry.type === "Point" && b.properties.type === "forecast" && b.properties.category === `${d}-${u}`
|
|
888
|
+
);
|
|
889
|
+
let C, D = v.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
890
|
+
for (; C = this.pickIndex(S, D), C <= S.length - 1; ) {
|
|
891
|
+
if (C > 0) {
|
|
892
|
+
const b = S[C], h = C === 0 ? void 0 : S[C - 1];
|
|
893
|
+
C === this.pickIndex(S, D) && (b == null ? void 0 : b.properties.category) === "yagi-cma" && console.log(D.format(), h, h == null ? void 0 : h.properties.wind, b, b.properties.wind);
|
|
894
|
+
const N = (m / 60 - ((r = h == null ? void 0 : h.properties) == null ? void 0 : r.hour)) / (b.properties.hour - ((c = h == null ? void 0 : h.properties) == null ? void 0 : c.hour)), x = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[0], b.geometry.coordinates[0], N), $ = this.computeNumber(h == null ? void 0 : h.geometry.coordinates[1], b.geometry.coordinates[1], N), W = g.point([x, $], {
|
|
895
|
+
name: d,
|
|
896
|
+
model: u,
|
|
897
897
|
category: b == null ? void 0 : b.properties.category,
|
|
898
|
-
date:
|
|
899
|
-
format:
|
|
900
|
-
gusts: this.computeNumber(
|
|
901
|
-
hour: this.computeNumber(
|
|
902
|
-
movement: this.computeNumber(
|
|
903
|
-
pressure: this.computeNumber(
|
|
904
|
-
wind: this.computeNumber(
|
|
898
|
+
date: D.format(),
|
|
899
|
+
format: D.format("MMM-DD/HHmm[Z]"),
|
|
900
|
+
gusts: this.computeNumber(h == null ? void 0 : h.properties.gusts, b.properties.gusts, N),
|
|
901
|
+
hour: this.computeNumber(h == null ? void 0 : h.properties.hour, b.properties.hour, N),
|
|
902
|
+
movement: this.computeNumber(h == null ? void 0 : h.properties.movement, b.properties.movement, N),
|
|
903
|
+
pressure: this.computeNumber(h == null ? void 0 : h.properties.pressure, b.properties.pressure, N),
|
|
904
|
+
wind: this.computeNumber(h == null ? void 0 : h.properties.wind, b.properties.wind, N),
|
|
905
905
|
type: "forecast",
|
|
906
|
-
disabled:
|
|
907
|
-
showCircle:
|
|
906
|
+
disabled: f,
|
|
907
|
+
showCircle: p
|
|
908
908
|
});
|
|
909
|
-
s.push(
|
|
909
|
+
s.push(W);
|
|
910
910
|
}
|
|
911
|
-
|
|
911
|
+
m += e * 60, D = v.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
912
912
|
}
|
|
913
913
|
}
|
|
914
914
|
return s;
|
|
@@ -938,28 +938,28 @@ class Z {
|
|
|
938
938
|
const { t1: o, t2: i, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
939
939
|
if (o && i) {
|
|
940
940
|
if (!s.debug) {
|
|
941
|
-
const
|
|
942
|
-
if (
|
|
943
|
-
return
|
|
941
|
+
const v = T.calculateDistance(t, o), m = T.calculateDistance(t, i);
|
|
942
|
+
if (v > 2 * n && m > 2 * n)
|
|
943
|
+
return P == null || P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, v, m, {
|
|
944
944
|
from: t,
|
|
945
945
|
t1: o,
|
|
946
946
|
t2: i,
|
|
947
947
|
hr: r
|
|
948
948
|
}), {};
|
|
949
949
|
}
|
|
950
|
-
const
|
|
950
|
+
const a = T.calculateBearing(t, o), d = T.calculateBearing(o, i), u = Math.abs(a - d);
|
|
951
951
|
let p = 0;
|
|
952
952
|
u < 180 ? p = u + 90 : u >= 180 && (p = u - 90);
|
|
953
|
-
const
|
|
954
|
-
return
|
|
953
|
+
const f = T.calculateCoordinate(o, p, n);
|
|
954
|
+
return P == null || P.info("[%s] the right tangent position: %j", s.requestId, {
|
|
955
955
|
from: t,
|
|
956
956
|
t1: o,
|
|
957
957
|
t2: i,
|
|
958
958
|
radius: n,
|
|
959
|
-
bearing1:
|
|
960
|
-
bearing2:
|
|
961
|
-
right:
|
|
962
|
-
}), { at:
|
|
959
|
+
bearing1: a,
|
|
960
|
+
bearing2: d,
|
|
961
|
+
right: f
|
|
962
|
+
}), { at: f, t1: o, t2: i, hr: Number(r), hours: c };
|
|
963
963
|
}
|
|
964
964
|
return {};
|
|
965
965
|
}
|
|
@@ -977,19 +977,19 @@ class Z {
|
|
|
977
977
|
const { t1: o, t2: i, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
978
978
|
if (o && i) {
|
|
979
979
|
if (!s.debug) {
|
|
980
|
-
const
|
|
981
|
-
if (
|
|
982
|
-
return
|
|
980
|
+
const f = T.calculateDistance(t, o), v = T.calculateDistance(t, i);
|
|
981
|
+
if (f > 2 * n && v > 2 * n)
|
|
982
|
+
return P == null || P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", s.requestId, f, v, {
|
|
983
983
|
from: t,
|
|
984
984
|
t1: o,
|
|
985
985
|
t2: i,
|
|
986
986
|
hr: r
|
|
987
987
|
}), {};
|
|
988
988
|
}
|
|
989
|
-
const
|
|
990
|
-
return { at:
|
|
989
|
+
const a = T.calculateBearing(t, o), d = T.calculateBearing(o, i), u = T.calculateDistance(t, o);
|
|
990
|
+
return { at: T.calculateCoordinate(o, a - d + 180, n < u ? n : u), t1: o, t2: i, hr: Number(r), hours: c };
|
|
991
991
|
} else
|
|
992
|
-
return
|
|
992
|
+
return P == null || P.info("[%s] no need drift: %j", s.requestId, { from: t, t1: o, t2: i, hr: r }), {};
|
|
993
993
|
}
|
|
994
994
|
/**
|
|
995
995
|
* 获取台风中心点对
|
|
@@ -1000,26 +1000,26 @@ class Z {
|
|
|
1000
1000
|
* @private
|
|
1001
1001
|
*/
|
|
1002
1002
|
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
1003
|
-
var
|
|
1003
|
+
var d, u, p, f, v;
|
|
1004
1004
|
let s = {};
|
|
1005
|
-
(
|
|
1005
|
+
(d = t.forecasts) == null || d.forEach((m) => {
|
|
1006
1006
|
s = { ...m.hours, ...s };
|
|
1007
1007
|
});
|
|
1008
1008
|
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (s == null ? void 0 : s[(p = Object.keys(s)) == null ? void 0 : p[0]]);
|
|
1009
|
-
|
|
1010
|
-
let i = (
|
|
1011
|
-
i || (i = (
|
|
1009
|
+
P == null || P.info("[%s] the first tropical center: %j", n.requestId, o);
|
|
1010
|
+
let i = (f = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : f.at(-1);
|
|
1011
|
+
i || (i = (v = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : v.at(-1));
|
|
1012
1012
|
const r = s == null ? void 0 : s[i || -1];
|
|
1013
|
-
|
|
1014
|
-
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(i)),
|
|
1013
|
+
P == null || P.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, i);
|
|
1014
|
+
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(i)), a = { 0: o };
|
|
1015
1015
|
for (const m of c)
|
|
1016
|
-
|
|
1017
|
-
return { t1: o, t2: r, hr: Number(i), hours:
|
|
1016
|
+
a[m] = s[m];
|
|
1017
|
+
return { t1: o, t2: r, hr: Number(i), hours: a };
|
|
1018
1018
|
}
|
|
1019
1019
|
static pickIndex(t, e) {
|
|
1020
1020
|
let n = 0;
|
|
1021
1021
|
for (const s of t) {
|
|
1022
|
-
if (
|
|
1022
|
+
if (R(s.properties.date).isAfter(e))
|
|
1023
1023
|
return n === 0 ? -1 : n;
|
|
1024
1024
|
n++;
|
|
1025
1025
|
}
|
|
@@ -1042,7 +1042,7 @@ class Z {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
}
|
|
1044
1044
|
export {
|
|
1045
|
-
|
|
1045
|
+
T as LaneHelper,
|
|
1046
1046
|
l as LngLatHelper,
|
|
1047
|
-
|
|
1047
|
+
q as TropicalHelper
|
|
1048
1048
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(M,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],$):(M=typeof globalThis<"u"?globalThis:M||self,$(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,$,x,z,O){"use strict";function W(v){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const t in v)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(v,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>v[t]})}}return e.default=v,Object.freeze(e)}const g=W($);function L(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}class k{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(v=>{k.prototype[v.toLowerCase()]=()=>{},k.prototype[`is${v}Enabled`]=()=>!1});const j=(()=>{try{return require("log4js")}catch{return null}})();var A={getLogger:j?j.getLogger:()=>new k};const E=L(A);class l{static guessTimeZoneOffset(e,t){const n=O(t,e),s=x().tz(n).utcOffset();return this.roundPrecision(s/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(3,"0"):u=l.padNumber(a,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let s="N";e<0&&(s="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(2,"0"):u=l.padNumber(a,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const s=e,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${s}E`:o<=-90?e=`${s}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${s}${o>0?"E":"W"}`:e=`${s}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const s=Math.trunc(e).toString().padStart(t,"0"),o=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class T{static calculateBearing(e,t,n=!0,s=4){const o=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(o.features[0],o.features[1]):i=g.bearing(o.features[0],o.features[1]),i<0&&(i+=360),l.roundPrecision(i,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,s),t.lng=l.convertToStdLng(t.lng,s);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:o}):r=g.distance(i.features[0],i.features[1],{units:o}),l.roundPrecision(r,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const d={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,d,!0,t,n),o=d}return l.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const i=g.point([e.lng,e.lat]);let r;o?r=g.rhumbDestination(i,n,t,{units:s}):r=g.destination(i,n,t,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),d=this.calculateDistance(e,t,!1,8,i);s&&r.push({lng:e.lng,lat:e.lat});let a=0;for(;a<d;)a+=n,a<d&&r.push(this.calculateCoordinate(e,c,a,i,!1));return o&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const s=[];let o,i;for(let r=0;r<e.length-1;r++){o=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([o,e[r].lat]);const c=o-i;if(Math.abs(c)>180){const d=l.convertToMonotonicLng2([[o,e[r].lat],[i,e[r+1].lat]]);let a,u;t?(a=g.lineString(d),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(a=g.greatCircle(d[0],d[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(a,u);let f;if(p.features.length){const C=g.getCoord(p.features[0]);f=l.roundPrecision(C[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),s.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),s.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return s.push(n),s}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);t.push(s)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(s=>s.lat===n.lat&&s.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===e.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(e.lat,8)&&n.splice(s,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,s=0,o=0,i,r;return t.forEach((c,d)=>{for(let a=0;a<c.length-1;a++){const u={lng:c[a][0],lat:c[a][1]},p={lng:c[a+1][0],lat:c[a+1][1]},f=this.calculatePointToLineDistance(e,u,p);n>f&&(n=f,o=a,s=d,i=this.calculateDistance(u,e),r=this.calculateDistance(p,e))}}),i!==0&&r!==0?t[s].splice(o+1,0,[e.lng,e.lat]):i===0?t[s].splice(o,1,[e.lng,e.lat]):r===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=T.convertRouteToCoordinates(t);return n.push(e),T.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=T.convertRouteToCoordinates(t);return n.unshift(e),T.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([e.lng,e.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...s],o),r=i.findIndex(a=>l.roundPrecision(e.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(a.lat,8)),c=i.findIndex(a=>l.roundPrecision(t.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(a.lat,8));return i.filter((a,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const d={lng:i[c][0],lat:i[c][1]},a={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,d,a);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(e,t){const n=T.convertRouteToCoordinates(t);T.mergeCoordinateToWaypoints(e,n,!0),t=T.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let r=!0;for(let c=s;c<t.length;c++)if(r){const d=[];d.push([e.lng,e.lat]);for(let a=o+1;a<t[c].length;a++)e.lng===t[c][a][0]&&e.lat===t[c][a][1]||d.push(t[c][a]);i.push(d),r=!1}else i.push([...t[c]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((a,u)=>u>0);const d=this.calculatePointToLineDistance(e,r,c);n>d&&(n=d,s=i)}e.lng=l.convertToStdLng(e.lng);const o=[e];for(let i=s+1;i<t.length;i++)o.push(t[i]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,s),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,s);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const s=e[n],o=e[n+1],i=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const s of e)this.mergeCoordinateToWaypoints(s,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const d={lng:t[c].lng,lat:t[c].lat},a={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,d,a);s>=u&&(s=u,o=c,i=this.calculateDistance(d,e,!1,6),r=this.calculateDistance(a,e,!1,6))}return i!==0&&r!==0?i<s||i===s&&o===0?t.unshift(e):r<s||r===s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):i===0?n&&t.splice(o,1,e):r===0&&n&&t.splice(o+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const s=e[n-1],o=e[n];if(n===1&&t.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(o)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(d=>[d.lng,d.lat]),i=g.lineString(o),r=g.nearestPointOnLine(i,n),c=g.getCoord(r);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let s=0;s<t.length-1;s++){const o=t[s],i=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,i)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var p;const o=e.speed||12,i=[];let r=[],c=!1,d=0,a=0,u;if(t&&n.length?(i.push(e),n.forEach((f,C)=>{if(c)r.push(f);else{const m=[];let S;for(let D=0;D<f.length;D++)if(u)m.push(f[D]);else{S={lng:f[D][0],lat:f[D][1]};const N=this.calculateDistance(e,S,!0,8,s);if(d+=N,d<t)a+=N,i.push(S),e=S;else{if(a=t,d===t)u=S,m.push([u.lng,u.lat]);else{const y=d-t,R=this.calculateBearing(S,e);u=this.calculateCoordinate(S,R,y,s),m.push([u.lng,u.lat]),m.push([S.lng,S.lat])}c=!0}}m.length&&r.push(m),C===n.length-1&&!u&&(u=S)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=a,u.hourFromPrevious=Math.round(a/o*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const s=l.convertToStdLng(e.lng,6),o=g.point([s,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),d=g.nearestPointOnLine(c,o),a=g.getCoord(d),u=l.roundPrecision(a[0],6),p=l.roundPrecision(a[1],6);return{lng:u,lat:p,inline:!(u===i&&p===t.lat)&&!(u===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0)o.bearing=this.calculateBearing(o,c,!0);else{const d=this.calculateDistance(s,c,!0);d&&d>=t&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(e,t,n=1){let s=this.convertRouteToCoordinates(e,n);return s=this.simplifyGCCoordinates(s,t),s}static simplifyGCCoordinates(e,t){t.forEach(s=>{this.mergeCoordinateToWaypoints(s,e,!0)});for(let s=1;s<t.length;s++){const o=t[s-1],i=t[s];if(i.gcToPrevious){const r=e.findIndex(d=>d.lng===o.lng&&d.lat===o.lat),c=e.findIndex(d=>d.lng===i.lng&&d.lat===i.lat);for(let d=c-1;d>r;d--)e.splice(d,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];i.gcToPrevious?(o.bearing=this.calculateBearing(o,i,!1),i.distanceFromPrevious=this.calculateDistance(o,i,!1)):(o.bearing=this.calculateBearing(o,i,!0),i.distanceFromPrevious=this.calculateDistance(o,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(t);for(const r of s)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const i of o)t.push(i);const n=l.convertToMonotonicLng2(t),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let P;try{P=E.getLogger("vessel")}catch{}finally{}class F{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const s of e){if(s.forecasts){const o=(n=s.history)==null?void 0:n[0];for(const i of s.forecasts){const r=[],c=x(i.date).utc(),d=`${s.name}-${i.model}`;if(o){const a=x(o.updated).utc(),u=g.point([o.lng,o.lat],{model:i.model,name:s.name,date:a.format(),hour:0,format:a.format("MMM-DD/HHmm[Z]"),pressure:o.pressure>1e4?l.roundPrecision(o.pressure/100,0):l.roundPrecision(o.pressure,0),wind:{kts:o.kts,spd:o.speed||o.spd},category:d,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const a in i==null?void 0:i.hours){const u=i.hours[a];u.wind.spd=u.wind.spd||u.wind.speed;const p=c.clone().add(Number(a),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:p.format(),hour:Number(a),format:p.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:d,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const a=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:s.id||s.name,model:i.model,name:s.name,category:d,type:"forecast"});t.features.push(a)}}}if(s.history){const o=[];for(const r of s.history){const c=x(r.updated).utc(),d=g.point([r.lng,r.lat],{name:s.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${s.name}-history`,wind:r.wind});t.features.push(d),o.push(d.geometry.coordinates)}const i=s.history[0];if(o.length===1&&o.push(o[0]),o.length>1){const r=g.lineString(l.convertToMonotonicLng2(o),{name:s.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var o,i,r,c,d;const n=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const u=a.properties.name,p=a.properties.model,f=a.properties.showCircle,C=a.properties.disabled,m=x(a.properties.date).utc();let S=t*60-(m.get("hour")*60+m.get("minute"))%(t*60);const D=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(b=>b.geometry.type==="Point"&&b.properties.type==="forecast"&&b.properties.category===`${u}-${p}`),N=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(b=>b.geometry.type==="Point"&&b.properties.type==="history"&&b.properties.category===`${u}-history`);let y,R=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;y=this.pickIndex(D,R),y<=D.length-1;){if(y>0){const b=D[y],h=y===0?N==null?void 0:N[0]:D[y-1];y===this.pickIndex(D,R)&&(b==null?void 0:b.properties.category)==="yagi-cma"&&console.log(R.format(),N==null?void 0:N[0],h,h==null?void 0:h.properties.wind,b,b.properties.wind);const I=(S/60-((c=h==null?void 0:h.properties)==null?void 0:c.hour))/(b.properties.hour-((d=h==null?void 0:h.properties)==null?void 0:d.hour)),B=this.computeNumber(h==null?void 0:h.geometry.coordinates[0],b.geometry.coordinates[0],I),q=this.computeNumber(h==null?void 0:h.geometry.coordinates[1],b.geometry.coordinates[1],I),U=g.point([B,q],{name:u,model:p,category:b==null?void 0:b.properties.category,date:R.format(),format:R.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(h==null?void 0:h.properties.gusts,b.properties.gusts,I),hour:this.computeNumber(h==null?void 0:h.properties.hour,b.properties.hour,I),movement:this.computeNumber(h==null?void 0:h.properties.movement,b.properties.movement,I),pressure:this.computeNumber(h==null?void 0:h.properties.pressure,b.properties.pressure,I),wind:this.computeNumber(h==null?void 0:h.properties.wind,b.properties.wind,I),type:"forecast",disabled:C,showCircle:f});s.push(U)}S+=t*60,R=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(e,t){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const C=T.calculateDistance(e,o),m=T.calculateDistance(e,i);if(C>2*n&&m>2*n)return P==null||P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,C,m,{from:e,t1:o,t2:i,hr:r}),{}}const d=T.calculateBearing(e,o),a=T.calculateBearing(o,i),u=Math.abs(d-a);let p=0;u<180?p=u+90:u>=180&&(p=u-90);const f=T.calculateCoordinate(o,p,n);return P==null||P.info("[%s] the right tangent position: %j",s.requestId,{from:e,t1:o,t2:i,radius:n,bearing1:d,bearing2:a,right:f}),{at:f,t1:o,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const f=T.calculateDistance(e,o),C=T.calculateDistance(e,i);if(f>2*n&&C>2*n)return P==null||P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,f,C,{from:e,t1:o,t2:i,hr:r}),{}}const d=T.calculateBearing(e,o),a=T.calculateBearing(o,i),u=T.calculateDistance(e,o);return{at:T.calculateCoordinate(o,d-a+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return P==null||P.info("[%s] no need drift: %j",s.requestId,{from:e,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var a,u,p,f,C;let s={};(a=e.forecasts)==null||a.forEach(m=>{s={...m.hours,...s}});const o=((u=e==null?void 0:e.history)==null?void 0:u[0])||(s==null?void 0:s[(p=Object.keys(s))==null?void 0:p[0]]);P==null||P.info("[%s] the first tropical center: %j",n.requestId,o);let i=(f=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);i||(i=(C=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:C.at(-1));const r=s==null?void 0:s[i||-1];P==null||P.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(s||{}).filter(m=>Number(m)<=Number(i)),d={0:o};for(const m of c)d[m]=s[m];return{t1:o,t2:r,hr:Number(i),hours:d}}static pickIndex(e,t){let n=0;for(const s of e){if(x(s.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 s={};for(const o in e)s[o]=this.computeNumber(e[o],t[o],n);return s}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}M.LaneHelper=T,M.LngLatHelper=l,M.TropicalHelper=F,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,I){typeof exports=="object"&&typeof module<"u"?I(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],I):(D=typeof globalThis<"u"?globalThis:D||self,I(D["idm-plugin-rabbitmq"]={},D["@turf/turf"],D.moment,D["moment-timezone"],D["tz-lookup"]))})(this,function(D,I,R,q,j){"use strict";function k(v){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const t in v)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(v,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>v[t]})}}return e.default=v,Object.freeze(e)}const g=k(I);function O(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}class x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(v=>{x.prototype[v.toLowerCase()]=()=>{},x.prototype[`is${v}Enabled`]=()=>!1});const $=(()=>{try{return require("log4js")}catch{return null}})();var W={getLogger:$?$.getLogger:()=>new x};const L=O(W);class l{static guessTimeZoneOffset(e,t){const n=j(t,e),s=R().tz(n).utcOffset();return this.roundPrecision(s/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,a,d,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),o=o-c*60),d=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let s="N";e<0&&(s="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,a,d,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),o=o-c*60),d=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const s=e,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${s}E`:o<=-90?e=`${s}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${s}${o>0?"E":"W"}`:e=`${s}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const s=Math.trunc(e).toString().padStart(t,"0"),o=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class T{static calculateBearing(e,t,n=!0,s=4){const o=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(o.features[0],o.features[1]):i=g.bearing(o.features[0],o.features[1]),i<0&&(i+=360),l.roundPrecision(i,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,s),t.lng=l.convertToStdLng(t.lng,s);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:o}):r=g.distance(i.features[0],i.features[1],{units:o}),l.roundPrecision(r,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,a,!0,t,n),o=a}return l.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const i=g.point([e.lng,e.lat]);let r;o?r=g.rhumbDestination(i,n,t,{units:s}):r=g.destination(i,n,t,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);s&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return o&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const s=[];let o,i;for(let r=0;r<e.length-1;r++){o=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([o,e[r].lat]);const c=o-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[o,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(d,u);let h;if(p.features.length){const S=g.getCoord(p.features[0]);h=l.roundPrecision(S[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),s.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),s.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([i,e[r+1].lat])}return s.push(n),s}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);t.push(s)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(s=>s.lat===n.lat&&s.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===e.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(e.lat,8)&&n.splice(s,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,s=0,o=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},p={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(e,u,p);n>h&&(n=h,o=d,s=a,i=this.calculateDistance(u,e),r=this.calculateDistance(p,e))}}),i!==0&&r!==0?t[s].splice(o+1,0,[e.lng,e.lat]):i===0?t[s].splice(o,1,[e.lng,e.lat]):r===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=T.convertRouteToCoordinates(t);return n.push(e),T.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=T.convertRouteToCoordinates(t);return n.unshift(e),T.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([e.lng,e.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...s],o),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(e,t){const n=T.convertRouteToCoordinates(t);T.mergeCoordinateToWaypoints(e,n,!0),t=T.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let r=!0;for(let c=s;c<t.length;c++)if(r){const a=[];a.push([e.lng,e.lat]);for(let d=o+1;d<t[c].length;d++)e.lng===t[c][d][0]&&e.lat===t[c][d][1]||a.push(t[c][d]);i.push(a),r=!1}else i.push([...t[c]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,s=i)}e.lng=l.convertToStdLng(e.lng);const o=[e];for(let i=s+1;i<t.length;i++)o.push(t[i]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,s),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,s);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const s=e[n],o=e[n+1],i=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const s of e)this.mergeCoordinateToWaypoints(s,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,d);s>=u&&(s=u,o=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<s||i===s&&o===0?t.unshift(e):r<s||r===s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):i===0?n&&t.splice(o,1,e):r===0&&n&&t.splice(o+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const s=e[n-1],o=e[n];if(n===1&&t.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(o)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),i=g.lineString(o),r=g.nearestPointOnLine(i,n),c=g.getCoord(r);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let s=0;s<t.length-1;s++){const o=t[s],i=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,i)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var p;const o=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((h,S)=>{if(c)r.push(h);else{const m=[];let C;for(let M=0;M<h.length;M++)if(u)m.push(h[M]);else{C={lng:h[M][0],lat:h[M][1]};const N=this.calculateDistance(e,C,!0,8,s);if(a+=N,a<t)d+=N,i.push(C),e=C;else{if(d=t,a===t)u=C,m.push([u.lng,u.lat]);else{const b=a-t,f=this.calculateBearing(C,e);u=this.calculateCoordinate(C,f,b,s),m.push([u.lng,u.lat]),m.push([C.lng,C.lat])}c=!0}}m.length&&r.push(m),S===n.length-1&&!u&&(u=C)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/o*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,h)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const s=l.convertToStdLng(e.lng,6),o=g.point([s,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,o),d=g.getCoord(a),u=l.roundPrecision(d[0],6),p=l.roundPrecision(d[1],6);return{lng:u,lat:p,inline:!(u===i&&p===t.lat)&&!(u===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0)o.bearing=this.calculateBearing(o,c,!0);else{const a=this.calculateDistance(s,c,!0);a&&a>=t&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(e,t,n=1){let s=this.convertRouteToCoordinates(e,n);return s=this.simplifyGCCoordinates(s,t),s}static simplifyGCCoordinates(e,t){t.forEach(s=>{this.mergeCoordinateToWaypoints(s,e,!0)});for(let s=1;s<t.length;s++){const o=t[s-1],i=t[s];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];i.gcToPrevious?(o.bearing=this.calculateBearing(o,i,!1),i.distanceFromPrevious=this.calculateDistance(o,i,!1)):(o.bearing=this.calculateBearing(o,i,!0),i.distanceFromPrevious=this.calculateDistance(o,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(t);for(const r of s)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const i of o)t.push(i);const n=l.convertToMonotonicLng2(t),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let P;try{P=L.getLogger("vessel")}catch{}finally{}class A{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const s of e){if(s.forecasts){const o=(n=s.history)==null?void 0:n[0];for(const i of s.forecasts){const r=[],c=R(i.date).utc(),a=`${s.name}-${i.model}`;if(o){const d=R(o.updated).utc(),u=g.point([o.lng,o.lat],{model:i.model,name:s.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:o.pressure>1e4?l.roundPrecision(o.pressure/100,0):l.roundPrecision(o.pressure,0),wind:o==null?void 0:o.wind,category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const p=c.clone().add(Number(d),"hour"),h=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:p.format(),hour:Number(d),format:p.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:s.id||s.name,model:i.model,name:s.name,category:a,type:"forecast"});t.features.push(d)}}}if(s.history){const o=[];for(const r of s.history){const c=R(r.updated).utc(),a=g.point([r.lng,r.lat],{name:s.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${s.name}-history`,wind:r.wind});t.features.push(a),o.push(a.geometry.coordinates)}const i=s.history[0];if(o.length===1&&o.push(o[0]),o.length>1){const r=g.lineString(l.convertToMonotonicLng2(o),{name:s.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var o,i,r,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"),s=[];for(const a of n){const d=a.properties.name,u=a.properties.model,p=a.properties.showCircle,h=a.properties.disabled,S=R(a.properties.date).utc();let m=t*60-(S.get("hour")*60+S.get("minute"))%(t*60);const C=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(b=>b.geometry.type==="Point"&&b.properties.type==="forecast"&&b.properties.category===`${d}-${u}`);let M,N=S.clone().add(m,"minute").set({minute:0,second:0,millisecond:0});for(;M=this.pickIndex(C,N),M<=C.length-1;){if(M>0){const b=C[M],f=M===0?void 0:C[M-1];M===this.pickIndex(C,N)&&(b==null?void 0:b.properties.category)==="yagi-cma"&&console.log(N.format(),f,f==null?void 0:f.properties.wind,b,b.properties.wind);const y=(m/60-((r=f==null?void 0:f.properties)==null?void 0:r.hour))/(b.properties.hour-((c=f==null?void 0:f.properties)==null?void 0:c.hour)),E=this.computeNumber(f==null?void 0:f.geometry.coordinates[0],b.geometry.coordinates[0],y),F=this.computeNumber(f==null?void 0:f.geometry.coordinates[1],b.geometry.coordinates[1],y),B=g.point([E,F],{name:d,model:u,category:b==null?void 0:b.properties.category,date:N.format(),format:N.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(f==null?void 0:f.properties.gusts,b.properties.gusts,y),hour:this.computeNumber(f==null?void 0:f.properties.hour,b.properties.hour,y),movement:this.computeNumber(f==null?void 0:f.properties.movement,b.properties.movement,y),pressure:this.computeNumber(f==null?void 0:f.properties.pressure,b.properties.pressure,y),wind:this.computeNumber(f==null?void 0:f.properties.wind,b.properties.wind,y),type:"forecast",disabled:h,showCircle:p});s.push(B)}m+=t*60,N=S.clone().add(m,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(e,t){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const S=T.calculateDistance(e,o),m=T.calculateDistance(e,i);if(S>2*n&&m>2*n)return P==null||P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,S,m,{from:e,t1:o,t2:i,hr:r}),{}}const a=T.calculateBearing(e,o),d=T.calculateBearing(o,i),u=Math.abs(a-d);let p=0;u<180?p=u+90:u>=180&&(p=u-90);const h=T.calculateCoordinate(o,p,n);return P==null||P.info("[%s] the right tangent position: %j",s.requestId,{from:e,t1:o,t2:i,radius:n,bearing1:a,bearing2:d,right:h}),{at:h,t1:o,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const h=T.calculateDistance(e,o),S=T.calculateDistance(e,i);if(h>2*n&&S>2*n)return P==null||P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,h,S,{from:e,t1:o,t2:i,hr:r}),{}}const a=T.calculateBearing(e,o),d=T.calculateBearing(o,i),u=T.calculateDistance(e,o);return{at:T.calculateCoordinate(o,a-d+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return P==null||P.info("[%s] no need drift: %j",s.requestId,{from:e,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var d,u,p,h,S;let s={};(d=e.forecasts)==null||d.forEach(m=>{s={...m.hours,...s}});const o=((u=e==null?void 0:e.history)==null?void 0:u[0])||(s==null?void 0:s[(p=Object.keys(s))==null?void 0:p[0]]);P==null||P.info("[%s] the first tropical center: %j",n.requestId,o);let i=(h=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:h.at(-1);i||(i=(S=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:S.at(-1));const r=s==null?void 0:s[i||-1];P==null||P.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(s||{}).filter(m=>Number(m)<=Number(i)),a={0:o};for(const m of c)a[m]=s[m];return{t1:o,t2:r,hr:Number(i),hours:a}}static pickIndex(e,t){let n=0;for(const s of e){if(R(s.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 s={};for(const o in e)s[o]=this.computeNumber(e[o],t[o],n);return s}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}D.LaneHelper=T,D.LngLatHelper=l,D.TropicalHelper=A,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|