@idm-plugin/geo 1.4.4 → 1.4.5
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 +266 -254
- package/dist/index.umd.cjs +1 -1
- package/dist/lane/src/index.d.ts +8 -0
- 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 y from "moment";
|
|
3
3
|
import "moment-timezone";
|
|
4
4
|
import A from "tz-lookup";
|
|
5
5
|
function E(C) {
|
|
6
6
|
return C && C.__esModule && Object.prototype.hasOwnProperty.call(C, "default") ? C.default : C;
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class R {
|
|
9
9
|
log() {
|
|
10
10
|
}
|
|
11
11
|
isLevelEnabled() {
|
|
@@ -19,8 +19,8 @@ class y {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((C) => {
|
|
22
|
-
|
|
23
|
-
},
|
|
22
|
+
R.prototype[C.toLowerCase()] = () => {
|
|
23
|
+
}, R.prototype[`is${C}Enabled`] = () => !1;
|
|
24
24
|
});
|
|
25
25
|
const F = () => {
|
|
26
26
|
try {
|
|
@@ -28,7 +28,7 @@ const F = () => {
|
|
|
28
28
|
} catch {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
}, x = F(), k = x ? x.getLogger : () => new
|
|
31
|
+
}, x = F(), k = x ? x.getLogger : () => new R();
|
|
32
32
|
var B = {
|
|
33
33
|
getLogger: k
|
|
34
34
|
};
|
|
@@ -40,7 +40,7 @@ class l {
|
|
|
40
40
|
* @param lat
|
|
41
41
|
*/
|
|
42
42
|
static guessTimeZoneOffset(t, e) {
|
|
43
|
-
const
|
|
43
|
+
const i = A(e, t), s = y().tz(i).utcOffset();
|
|
44
44
|
return this.roundPrecision(s / 60, 1);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -49,21 +49,21 @@ class l {
|
|
|
49
49
|
* @return timezone => +08:30
|
|
50
50
|
*/
|
|
51
51
|
static prettyTimeZoneOffset(t) {
|
|
52
|
-
let e = Math.floor(Math.abs(t)),
|
|
53
|
-
return
|
|
52
|
+
let e = Math.floor(Math.abs(t)), i = Math.round((Math.abs(t) - e) * 60);
|
|
53
|
+
return i = i > 9 ? i : `0${i}`, e = e > 9 ? e : `0${e}`, t > 0 ? `+${e}:${i}` : `-${e}:${i}`;
|
|
54
54
|
}
|
|
55
|
-
static lng2pretty(t, e = 6,
|
|
55
|
+
static lng2pretty(t, e = 6, i = "H°M′") {
|
|
56
56
|
t = l.convertToStdLng(t, e);
|
|
57
57
|
let s = "E";
|
|
58
|
-
t < 0 && (s = "W"), t = Math.abs(t),
|
|
59
|
-
let o = t * 3600,
|
|
60
|
-
|
|
61
|
-
const f = `${
|
|
58
|
+
t < 0 && (s = "W"), t = Math.abs(t), i = i.toUpperCase();
|
|
59
|
+
let o = t * 3600, n, r, c, a, d, u;
|
|
60
|
+
n = o % 3600 % 60, i.indexOf("S") !== -1 && (o = o - n, r = l.padNumber(n, 2, 2)), c = o / 60 % 60, i.indexOf("M") !== -1 && (i.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, i.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(3, "0") : u = l.padNumber(d, 3, 2);
|
|
61
|
+
const f = `${i.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
62
62
|
return {
|
|
63
63
|
direction: s,
|
|
64
64
|
degree: l.roundPrecision(d, e),
|
|
65
65
|
minute: l.roundPrecision(c, e),
|
|
66
|
-
second: l.roundPrecision(
|
|
66
|
+
second: l.roundPrecision(n, e),
|
|
67
67
|
pretty: f
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -73,57 +73,57 @@ class l {
|
|
|
73
73
|
* @param precision 精确度
|
|
74
74
|
* @param format 格式化
|
|
75
75
|
*/
|
|
76
|
-
static lat2pretty(t, e = 6,
|
|
76
|
+
static lat2pretty(t, e = 6, i = "H°M′") {
|
|
77
77
|
t = t % 180;
|
|
78
78
|
let s = "N";
|
|
79
|
-
t < 0 && (s = "S"), t = Math.abs(t),
|
|
80
|
-
let o = t * 3600,
|
|
81
|
-
|
|
82
|
-
const f = `${
|
|
79
|
+
t < 0 && (s = "S"), t = Math.abs(t), i = i.toUpperCase();
|
|
80
|
+
let o = t * 3600, n, r, c, a, d, u;
|
|
81
|
+
n = o % 3600 % 60, i.indexOf("S") !== -1 && (o = o - n, r = l.padNumber(n, 2, 2)), c = o / 60 % 60, i.indexOf("M") !== -1 && (i.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, i.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(2, "0") : u = l.padNumber(d, 2, 2);
|
|
82
|
+
const f = `${i.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
83
83
|
return {
|
|
84
84
|
direction: s,
|
|
85
85
|
degree: l.roundPrecision(d, e),
|
|
86
86
|
minute: l.roundPrecision(c, e),
|
|
87
|
-
second: l.roundPrecision(
|
|
87
|
+
second: l.roundPrecision(n, e),
|
|
88
88
|
pretty: f
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
static str2Lng(t, e = 6) {
|
|
92
|
-
let
|
|
92
|
+
let i;
|
|
93
93
|
if (isNaN(t)) {
|
|
94
94
|
t = l.strReplace(t, "LNG");
|
|
95
95
|
const s = t[t.length - 1].toUpperCase();
|
|
96
96
|
t = t.substring(0, t.length - 1).trim();
|
|
97
97
|
const o = t.split(" ").filter((c) => c !== "").map((c) => Number(c));
|
|
98
|
-
let [
|
|
99
|
-
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r,
|
|
100
|
-
const c = this.roundPrecision(
|
|
101
|
-
r =
|
|
98
|
+
let [n, r] = o;
|
|
99
|
+
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, n > 360 && !r) {
|
|
100
|
+
const c = this.roundPrecision(n / 100, 0);
|
|
101
|
+
r = n - c * 100, n = c;
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
i = n + (r ?? 0) / 60, s === "W" && (i = i * -1);
|
|
104
104
|
} else
|
|
105
|
-
|
|
106
|
-
return l.convertToStdLng(
|
|
105
|
+
i = Number(t);
|
|
106
|
+
return l.convertToStdLng(i, e);
|
|
107
107
|
}
|
|
108
108
|
static str2Lat(t, e = 6) {
|
|
109
|
-
let
|
|
109
|
+
let i;
|
|
110
110
|
if (isNaN(t)) {
|
|
111
111
|
t = l.strReplace(t, "LAT");
|
|
112
112
|
const s = t[t.length - 1].toUpperCase();
|
|
113
113
|
t = t.substring(0, t.length - 1).trim();
|
|
114
114
|
const o = t.split(" ").filter((c) => c !== "").map((c) => Number(c));
|
|
115
|
-
let [
|
|
116
|
-
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r,
|
|
117
|
-
const c = this.roundPrecision(
|
|
118
|
-
r =
|
|
115
|
+
let [n, r] = o;
|
|
116
|
+
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, n > 90 && !r) {
|
|
117
|
+
const c = this.roundPrecision(n / 100, 0);
|
|
118
|
+
r = n - c * 100, n = c;
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
i = n + (r ?? 0) / 60, s === "S" && (i = i * -1);
|
|
121
121
|
} else
|
|
122
|
-
|
|
123
|
-
return l.roundPrecision(
|
|
122
|
+
i = Number(t);
|
|
123
|
+
return l.roundPrecision(i, e);
|
|
124
124
|
}
|
|
125
|
-
static str2LngOrLat(t, e = 6,
|
|
126
|
-
t = l.strReplace(t,
|
|
125
|
+
static str2LngOrLat(t, e = 6, i = "LAT") {
|
|
126
|
+
t = l.strReplace(t, i);
|
|
127
127
|
const s = t[t.length - 1].toUpperCase();
|
|
128
128
|
return ["N", "S"].includes(s) ? {
|
|
129
129
|
lat: l.str2Lat(t, e)
|
|
@@ -136,8 +136,8 @@ class l {
|
|
|
136
136
|
}
|
|
137
137
|
static roundPrecision(t, e = 4) {
|
|
138
138
|
if (typeof t == "number") {
|
|
139
|
-
const
|
|
140
|
-
return Math.round(t *
|
|
139
|
+
const i = Number("1".padEnd(e + 1, "0"));
|
|
140
|
+
return Math.round(t * i) / i;
|
|
141
141
|
}
|
|
142
142
|
return t;
|
|
143
143
|
}
|
|
@@ -161,8 +161,8 @@ class l {
|
|
|
161
161
|
}
|
|
162
162
|
static strReplace(t, e = "LAT") {
|
|
163
163
|
t = t.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();
|
|
164
|
-
const
|
|
165
|
-
if (!["N", "S", "E", "W"].includes(
|
|
164
|
+
const i = t[t.length - 1].toUpperCase();
|
|
165
|
+
if (!["N", "S", "E", "W"].includes(i)) {
|
|
166
166
|
const s = t, o = Number(s.split(" ")[0]);
|
|
167
167
|
if (isNaN(o))
|
|
168
168
|
throw new Error(`invalid Lat/Lng: ${t}`);
|
|
@@ -177,8 +177,8 @@ class l {
|
|
|
177
177
|
* @param intPrecision 整数位数
|
|
178
178
|
* @param dcmPrecision 小数位数
|
|
179
179
|
*/
|
|
180
|
-
static padNumber(t, e = 2,
|
|
181
|
-
const s = Math.trunc(t).toString().padStart(e, "0"), o = Math.trunc(l.roundPrecision(t - Math.trunc(t),
|
|
180
|
+
static padNumber(t, e = 2, i = 2) {
|
|
181
|
+
const s = Math.trunc(t).toString().padStart(e, "0"), o = Math.trunc(l.roundPrecision(t - Math.trunc(t), i) * Math.pow(10, i)).toString().padStart(i, "0");
|
|
182
182
|
return `${s}.${o}`;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -191,13 +191,13 @@ class b {
|
|
|
191
191
|
* @param precision
|
|
192
192
|
* @returns {number} 单位度
|
|
193
193
|
*/
|
|
194
|
-
static calculateBearing(t, e,
|
|
194
|
+
static calculateBearing(t, e, i = !0, s = 4) {
|
|
195
195
|
const o = g.points([
|
|
196
196
|
[t.lng, t.lat],
|
|
197
197
|
[e.lng, e.lat]
|
|
198
198
|
]);
|
|
199
|
-
let
|
|
200
|
-
return
|
|
199
|
+
let n;
|
|
200
|
+
return i ? n = g.rhumbBearing(o.features[0], o.features[1]) : n = g.bearing(o.features[0], o.features[1]), n < 0 && (n += 360), l.roundPrecision(n, s);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* 计算两点间距离
|
|
@@ -208,14 +208,14 @@ class b {
|
|
|
208
208
|
* @param units 单位,默认 nm(海里)
|
|
209
209
|
* @returns {number}
|
|
210
210
|
*/
|
|
211
|
-
static calculateDistance(t, e,
|
|
211
|
+
static calculateDistance(t, e, i = !0, s = 4, o = "nauticalmiles") {
|
|
212
212
|
t = { ...t }, e = { ...e }, t.lng = l.convertToStdLng(t.lng, s), e.lng = l.convertToStdLng(e.lng, s);
|
|
213
|
-
const
|
|
213
|
+
const n = g.points([
|
|
214
214
|
[t.lng, t.lat],
|
|
215
215
|
[e.lng, e.lat]
|
|
216
216
|
]);
|
|
217
217
|
let r;
|
|
218
|
-
return
|
|
218
|
+
return i ? r = g.rhumbDistance(n.features[0], n.features[1], { units: o }) : r = g.distance(n.features[0], n.features[1], { units: o }), l.roundPrecision(r, s);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* 计算航线距离
|
|
@@ -223,14 +223,14 @@ class b {
|
|
|
223
223
|
* @param precision
|
|
224
224
|
* @param units
|
|
225
225
|
*/
|
|
226
|
-
static calculateRouteDistance(t, e = 4,
|
|
226
|
+
static calculateRouteDistance(t, e = 4, i = "nauticalmiles") {
|
|
227
227
|
let s = 0, o;
|
|
228
|
-
for (const
|
|
229
|
-
for (let r = 0; r <
|
|
230
|
-
const c = { lng:
|
|
231
|
-
r === 0 && o && (s += this.calculateDistance(o, c, !0, e,
|
|
232
|
-
const a = { lng:
|
|
233
|
-
s += this.calculateDistance(c, a, !0, e,
|
|
228
|
+
for (const n of t)
|
|
229
|
+
for (let r = 0; r < n.length - 1; r++) {
|
|
230
|
+
const c = { lng: n[r][0], lat: n[r][1] };
|
|
231
|
+
r === 0 && o && (s += this.calculateDistance(o, c, !0, e, i));
|
|
232
|
+
const a = { lng: n[r + 1][0], lat: n[r + 1][1] };
|
|
233
|
+
s += this.calculateDistance(c, a, !0, e, i), o = a;
|
|
234
234
|
}
|
|
235
235
|
return l.roundPrecision(s, e);
|
|
236
236
|
}
|
|
@@ -242,10 +242,10 @@ class b {
|
|
|
242
242
|
* @param units 单位,默认 nm(海里)
|
|
243
243
|
* @param rhumb
|
|
244
244
|
*/
|
|
245
|
-
static calculateCoordinate(t, e,
|
|
246
|
-
const
|
|
245
|
+
static calculateCoordinate(t, e, i, s = "nauticalmiles", o = !0) {
|
|
246
|
+
const n = g.point([t.lng, t.lat]);
|
|
247
247
|
let r;
|
|
248
|
-
o ? r = g.rhumbDestination(
|
|
248
|
+
o ? r = g.rhumbDestination(n, i, e, { units: s }) : r = g.destination(n, i, e, { units: s });
|
|
249
249
|
const c = r.geometry.coordinates;
|
|
250
250
|
return { lng: l.convertToStdLng(c[0], 8), lat: l.roundPrecision(c[1], 8) };
|
|
251
251
|
}
|
|
@@ -258,12 +258,12 @@ class b {
|
|
|
258
258
|
* @param includeTail true 包含终点 to
|
|
259
259
|
* @param units 单位,默认 nm(海里)
|
|
260
260
|
*/
|
|
261
|
-
static interpolateCoordinates(t, e,
|
|
262
|
-
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8,
|
|
261
|
+
static interpolateCoordinates(t, e, i, s = !0, o = !0, n = "nauticalmiles") {
|
|
262
|
+
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, n);
|
|
263
263
|
s && r.push({ lng: t.lng, lat: t.lat });
|
|
264
264
|
let d = 0;
|
|
265
265
|
for (; d < a; )
|
|
266
|
-
d +=
|
|
266
|
+
d += i, d < a && r.push(this.calculateCoordinate(t, c, d, n, !1));
|
|
267
267
|
return o && r.push({ lng: e.lng, lat: e.lat }), r;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
@@ -281,16 +281,16 @@ class b {
|
|
|
281
281
|
if ((t == null ? void 0 : t.length) < 2)
|
|
282
282
|
return [];
|
|
283
283
|
t = this.deduplicateCoordinates(t);
|
|
284
|
-
let
|
|
284
|
+
let i = [];
|
|
285
285
|
const s = [];
|
|
286
|
-
let o,
|
|
286
|
+
let o, n;
|
|
287
287
|
for (let r = 0; r < t.length - 1; r++) {
|
|
288
|
-
o = l.convertToStdLng(t[r].lng, 8),
|
|
289
|
-
const c = o -
|
|
288
|
+
o = l.convertToStdLng(t[r].lng, 8), n = 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), i.push([o, t[r].lat]);
|
|
289
|
+
const c = o - n;
|
|
290
290
|
if (Math.abs(c) > 180) {
|
|
291
291
|
const a = l.convertToMonotonicLng2([
|
|
292
292
|
[o, t[r].lat],
|
|
293
|
-
[
|
|
293
|
+
[n, t[r + 1].lat]
|
|
294
294
|
]);
|
|
295
295
|
let d, u;
|
|
296
296
|
e ? (d = g.lineString(a), u = g.lineString([
|
|
@@ -300,15 +300,15 @@ class b {
|
|
|
300
300
|
const f = g.lineIntersect(d, u);
|
|
301
301
|
let h;
|
|
302
302
|
if (f.features.length) {
|
|
303
|
-
const
|
|
304
|
-
h = l.roundPrecision(
|
|
303
|
+
const T = g.getCoord(f.features[0]);
|
|
304
|
+
h = l.roundPrecision(T[1], 8);
|
|
305
305
|
} else
|
|
306
306
|
h = t[r].lat;
|
|
307
|
-
c > 0 ? (
|
|
307
|
+
c > 0 ? (i.push([180 - 1e-6, h]), s.push([...i]), i = [], i.push([-(180 - 1e-6), h])) : (i.push([-(180 - 1e-6), h]), s.push([...i]), i = [], i.push([180 - 1e-6, h]));
|
|
308
308
|
}
|
|
309
|
-
r === t.length - 2 &&
|
|
309
|
+
r === t.length - 2 && i.push([n, t[r + 1].lat]);
|
|
310
310
|
}
|
|
311
|
-
return s.push(
|
|
311
|
+
return s.push(i), s;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* 去除重复坐标
|
|
@@ -316,8 +316,8 @@ class b {
|
|
|
316
316
|
*/
|
|
317
317
|
static deduplicateRoute(t) {
|
|
318
318
|
const e = [];
|
|
319
|
-
for (const
|
|
320
|
-
const s =
|
|
319
|
+
for (const i of t) {
|
|
320
|
+
const s = i.reduce((o, n) => (o.findIndex((r) => r[0] === n[0] && r[1] === n[1]) === -1 && o.push(n), o), []);
|
|
321
321
|
e.push(s);
|
|
322
322
|
}
|
|
323
323
|
return e;
|
|
@@ -327,7 +327,7 @@ class b {
|
|
|
327
327
|
* @param coordinates
|
|
328
328
|
*/
|
|
329
329
|
static deduplicateCoordinates(t) {
|
|
330
|
-
return t.reduce((e,
|
|
330
|
+
return t.reduce((e, i) => (e.findIndex((s) => s.lat === i.lat && s.lng === i.lng) === -1 && e.push(i), e), []);
|
|
331
331
|
}
|
|
332
332
|
/**
|
|
333
333
|
* 移出坐标
|
|
@@ -336,9 +336,9 @@ class b {
|
|
|
336
336
|
*/
|
|
337
337
|
static removeCoordinateFromRoute(t, e) {
|
|
338
338
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
339
|
-
for (const
|
|
340
|
-
for (let s =
|
|
341
|
-
l.roundPrecision(
|
|
339
|
+
for (const i of e)
|
|
340
|
+
for (let s = i.length - 1; s >= 0; s--)
|
|
341
|
+
l.roundPrecision(i[s][0], 8) === t.lng && l.roundPrecision(i[s][1], 8) === l.roundPrecision(t.lat, 8) && i.splice(s, 1);
|
|
342
342
|
return e;
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
@@ -348,8 +348,8 @@ class b {
|
|
|
348
348
|
*/
|
|
349
349
|
static removeCoordinateFromWaypoints(t, e) {
|
|
350
350
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
351
|
-
for (let
|
|
352
|
-
l.roundPrecision(e[
|
|
351
|
+
for (let i = e.length - 1; i >= 0; i--)
|
|
352
|
+
l.roundPrecision(e[i].lng, 8) === t.lng && l.roundPrecision(e[i].lat, 8) === l.roundPrecision(t.lat, 8) && e.splice(i, 1);
|
|
353
353
|
return e;
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
@@ -365,13 +365,13 @@ class b {
|
|
|
365
365
|
*/
|
|
366
366
|
static mergeCoordinateToRoute(t, e) {
|
|
367
367
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
368
|
-
let
|
|
368
|
+
let i = Number.MAX_VALUE, s = 0, o = 0, n, r;
|
|
369
369
|
return e.forEach((c, a) => {
|
|
370
370
|
for (let d = 0; d < c.length - 1; d++) {
|
|
371
371
|
const u = { lng: c[d][0], lat: c[d][1] }, f = { lng: c[d + 1][0], lat: c[d + 1][1] }, h = this.calculatePointToLineDistance(t, u, f);
|
|
372
|
-
|
|
372
|
+
i > h && (i = h, o = d, s = a, n = this.calculateDistance(u, t), r = this.calculateDistance(f, t));
|
|
373
373
|
}
|
|
374
|
-
}),
|
|
374
|
+
}), n !== 0 && r !== 0 ? e[s].splice(o + 1, 0, [t.lng, t.lat]) : n === 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
|
}
|
|
376
376
|
/**
|
|
377
377
|
* 向Route尾加1个坐标
|
|
@@ -380,8 +380,8 @@ class b {
|
|
|
380
380
|
*/
|
|
381
381
|
static appendCoordinateToRoute(t, e) {
|
|
382
382
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
383
|
-
const
|
|
384
|
-
return
|
|
383
|
+
const i = b.convertRouteToCoordinates(e);
|
|
384
|
+
return i.push(t), b.divideAccordingToLng(i);
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
387
387
|
* 向route头加1个坐标
|
|
@@ -389,8 +389,8 @@ class b {
|
|
|
389
389
|
* @param route
|
|
390
390
|
*/
|
|
391
391
|
static unshiftCoordinateToRoute(t, e) {
|
|
392
|
-
const
|
|
393
|
-
return
|
|
392
|
+
const i = b.convertRouteToCoordinates(e);
|
|
393
|
+
return i.unshift(t), b.divideAccordingToLng(i);
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
396
|
* 合并多个waypoints进航线
|
|
@@ -398,8 +398,8 @@ class b {
|
|
|
398
398
|
* @param route 航线 [[[lng, lat],[lng, lat]]]
|
|
399
399
|
*/
|
|
400
400
|
static mergeWaypointsToRoute(t, e) {
|
|
401
|
-
for (const
|
|
402
|
-
e = this.mergeCoordinateToRoute(
|
|
401
|
+
for (const i of t)
|
|
402
|
+
e = this.mergeCoordinateToRoute(i, e);
|
|
403
403
|
return e;
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
@@ -409,15 +409,15 @@ class b {
|
|
|
409
409
|
* @param route [[[lng, lat]]]
|
|
410
410
|
* @return [[[lng, lat]]]
|
|
411
411
|
*/
|
|
412
|
-
static calculateRangeRoute(t, e,
|
|
413
|
-
|
|
412
|
+
static calculateRangeRoute(t, e, i) {
|
|
413
|
+
i = this.mergeWaypointsToRoute([t, e], i);
|
|
414
414
|
const s = [];
|
|
415
415
|
let o = 0;
|
|
416
|
-
return
|
|
416
|
+
return i.forEach((n) => {
|
|
417
417
|
if (o === 2)
|
|
418
418
|
return;
|
|
419
419
|
const r = [];
|
|
420
|
-
for (const c of
|
|
420
|
+
for (const c of n) {
|
|
421
421
|
if (l.roundPrecision(e.lng, 8) === l.roundPrecision(c[0], 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(c[1], 8)) {
|
|
422
422
|
r.push(c), o === 0 && r.push([t.lng, t.lat]), o = 2;
|
|
423
423
|
break;
|
|
@@ -435,13 +435,13 @@ class b {
|
|
|
435
435
|
* @param waypoints
|
|
436
436
|
* @return [{lng, lat}]
|
|
437
437
|
*/
|
|
438
|
-
static calculateRangeWaypoints(t, e,
|
|
439
|
-
const o = this.convertRouteToCoordinates(
|
|
438
|
+
static calculateRangeWaypoints(t, e, i, s = []) {
|
|
439
|
+
const o = this.convertRouteToCoordinates(i, 0), n = this.mergeCoordinatesToWaypoints([t, e, ...s], o), r = n.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
|
-
), c =
|
|
441
|
+
), c = n.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
|
|
444
|
+
return n.filter((d, u) => u >= r && u <= c);
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
447
|
* 计算坐标到航路上的最短距离
|
|
@@ -449,13 +449,13 @@ class b {
|
|
|
449
449
|
* @param route
|
|
450
450
|
*/
|
|
451
451
|
static calculateMinDistanceToRoute(t, e) {
|
|
452
|
-
let
|
|
453
|
-
return e.forEach((
|
|
454
|
-
for (let c = 0; c <
|
|
455
|
-
const a = { lng:
|
|
456
|
-
|
|
452
|
+
let i = Number.MAX_VALUE, s = 0, o = 0;
|
|
453
|
+
return e.forEach((n, r) => {
|
|
454
|
+
for (let c = 0; c < n.length - 1; c++) {
|
|
455
|
+
const a = { lng: n[c][0], lat: n[c][1] }, d = { lng: n[c + 1][0], lat: n[c + 1][1] }, u = this.calculatePointToLineDistance(t, a, d);
|
|
456
|
+
i > u && (i = u, s = c, o = r);
|
|
457
457
|
}
|
|
458
|
-
}), { minDist:
|
|
458
|
+
}), { minDist: i, segIndex: o, minIndex: s };
|
|
459
459
|
}
|
|
460
460
|
/**
|
|
461
461
|
* 计算子航线
|
|
@@ -464,11 +464,11 @@ class b {
|
|
|
464
464
|
* @return [[[lng, lat]]]
|
|
465
465
|
*/
|
|
466
466
|
static calculateSubRoute(t, e) {
|
|
467
|
-
const
|
|
468
|
-
b.mergeCoordinateToWaypoints(t,
|
|
467
|
+
const i = b.convertRouteToCoordinates(e);
|
|
468
|
+
b.mergeCoordinateToWaypoints(t, i, !0), e = b.divideAccordingToLng(i);
|
|
469
469
|
const { segIndex: s, minIndex: o } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
470
470
|
t.lng = l.convertToStdLng(t.lng);
|
|
471
|
-
const
|
|
471
|
+
const n = [];
|
|
472
472
|
let r = !0;
|
|
473
473
|
for (let c = s; c < e.length; c++)
|
|
474
474
|
if (r) {
|
|
@@ -476,10 +476,10 @@ class b {
|
|
|
476
476
|
a.push([t.lng, t.lat]);
|
|
477
477
|
for (let d = o + 1; d < e[c].length; d++)
|
|
478
478
|
t.lng === e[c][d][0] && t.lat === e[c][d][1] || a.push(e[c][d]);
|
|
479
|
-
|
|
479
|
+
n.push(a), r = !1;
|
|
480
480
|
} else
|
|
481
|
-
|
|
482
|
-
return
|
|
481
|
+
n.push([...e[c]]);
|
|
482
|
+
return n;
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
485
|
* 计算子途经点
|
|
@@ -488,20 +488,20 @@ class b {
|
|
|
488
488
|
* @return [{lng, lat}]
|
|
489
489
|
*/
|
|
490
490
|
static calculateSubWaypoints(t, e) {
|
|
491
|
-
let
|
|
492
|
-
for (let
|
|
493
|
-
const r = e[
|
|
491
|
+
let i = Number.MAX_VALUE, s = 0;
|
|
492
|
+
for (let n = 0; n < e.length - 1; n++) {
|
|
493
|
+
const r = e[n], c = e[n + 1];
|
|
494
494
|
if (this.calculateDistance(t, r) === 0)
|
|
495
495
|
return e;
|
|
496
496
|
if (this.calculateDistance(t, c) === 0)
|
|
497
497
|
return e.filter((d, u) => u > 0);
|
|
498
498
|
const a = this.calculatePointToLineDistance(t, r, c);
|
|
499
|
-
|
|
499
|
+
i > a && (i = a, s = n);
|
|
500
500
|
}
|
|
501
501
|
t.lng = l.convertToStdLng(t.lng);
|
|
502
502
|
const o = [t];
|
|
503
|
-
for (let
|
|
504
|
-
o.push(e[
|
|
503
|
+
for (let n = s + 1; n < e.length; n++)
|
|
504
|
+
o.push(e[n]);
|
|
505
505
|
return o;
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
@@ -511,14 +511,14 @@ class b {
|
|
|
511
511
|
* @param to { lng, lat }
|
|
512
512
|
* @param options
|
|
513
513
|
*/
|
|
514
|
-
static calculatePointToLineDistance(t, e,
|
|
515
|
-
t.lng = l.convertToStdLng(t.lng, 8), e = { ...e },
|
|
516
|
-
const o = l.convertToMonotonicLng([e,
|
|
517
|
-
e = o[0],
|
|
518
|
-
const
|
|
514
|
+
static calculatePointToLineDistance(t, e, i, s = { units: "nauticalmiles", method: "geodesic" }) {
|
|
515
|
+
t.lng = l.convertToStdLng(t.lng, 8), e = { ...e }, i = { ...i }, e.lng = l.convertToStdLng(e.lng, 8), i.lng = l.convertToStdLng(i.lng, 8);
|
|
516
|
+
const o = l.convertToMonotonicLng([e, i]);
|
|
517
|
+
e = o[0], i = o[1];
|
|
518
|
+
const n = g.lineString([
|
|
519
519
|
[e.lng, e.lat],
|
|
520
|
-
[
|
|
521
|
-
]), r = g.pointToLineDistance(g.point([t.lng, t.lat]),
|
|
520
|
+
[i.lng, i.lat]
|
|
521
|
+
]), r = g.pointToLineDistance(g.point([t.lng, t.lat]), n, s), c = g.pointToLineDistance(g.point([t.lng > 0 ? t.lng - 360 : t.lng + 360, t.lat]), n, s);
|
|
522
522
|
return l.roundPrecision(Math.min(r, c), 6);
|
|
523
523
|
}
|
|
524
524
|
/**
|
|
@@ -528,9 +528,9 @@ class b {
|
|
|
528
528
|
*/
|
|
529
529
|
static calculateWaypointsPropInRoute(t, e) {
|
|
530
530
|
e = this.mergeWaypointsToRoute(t, e);
|
|
531
|
-
for (let
|
|
532
|
-
const s = t[
|
|
533
|
-
|
|
531
|
+
for (let i = 0; i < t.length - 1; i++) {
|
|
532
|
+
const s = t[i], o = t[i + 1], n = this.calculateRangeRoute(s, o, e);
|
|
533
|
+
i === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(n), o.distanceFromStart = l.roundPrecision((s.distanceFromStart || 0) + o.distanceFromPrevious);
|
|
534
534
|
}
|
|
535
535
|
return t;
|
|
536
536
|
}
|
|
@@ -539,9 +539,9 @@ class b {
|
|
|
539
539
|
* @param waypoints [{lng, lat}]
|
|
540
540
|
* @param replace true replace the same waypoint with coordinate
|
|
541
541
|
*/
|
|
542
|
-
static mergeCoordinatesToWaypoints(t, e,
|
|
542
|
+
static mergeCoordinatesToWaypoints(t, e, i = !0) {
|
|
543
543
|
for (const s of t)
|
|
544
|
-
this.mergeCoordinateToWaypoints(s, e,
|
|
544
|
+
this.mergeCoordinateToWaypoints(s, e, i);
|
|
545
545
|
return e;
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
@@ -556,14 +556,14 @@ class b {
|
|
|
556
556
|
* @return
|
|
557
557
|
* [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: 179, lat: 50}, {lng: -170, lat: 40}, {lng: -160, lat: 30}]
|
|
558
558
|
*/
|
|
559
|
-
static mergeCoordinateToWaypoints(t, e,
|
|
559
|
+
static mergeCoordinateToWaypoints(t, e, i = !0) {
|
|
560
560
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
561
|
-
let s = Number.MAX_VALUE, o = 0,
|
|
561
|
+
let s = Number.MAX_VALUE, o = 0, n = 0, r = 0;
|
|
562
562
|
for (let c = 0; c < e.length - 1; c++) {
|
|
563
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,
|
|
564
|
+
s >= u && (s = u, o = c, n = this.calculateDistance(a, t, !1, 6), r = this.calculateDistance(d, t, !1, 6));
|
|
565
565
|
}
|
|
566
|
-
return
|
|
566
|
+
return n !== 0 && r !== 0 ? n < s || n === s && o === 0 ? e.unshift(t) : r < s || r === s && o === e.length - 2 ? e.push(t) : e.splice(o + 1, 0, t) : n === 0 ? i && e.splice(o, 1, t) : r === 0 && i && e.splice(o + 1, 1, t), e.map((c) => (c.lng = l.convertToStdLng(c.lng), c));
|
|
567
567
|
}
|
|
568
568
|
/**
|
|
569
569
|
* 生成航线(基于途经点生成大圆/横向航线,并根据是否跨180度分组)
|
|
@@ -572,11 +572,11 @@ class b {
|
|
|
572
572
|
*/
|
|
573
573
|
static generateRouteAccordingToWaypoints(t) {
|
|
574
574
|
const e = [];
|
|
575
|
-
for (let
|
|
576
|
-
const s = t[
|
|
577
|
-
if (
|
|
578
|
-
const
|
|
579
|
-
e.push(...
|
|
575
|
+
for (let i = 1; i < t.length; i++) {
|
|
576
|
+
const s = t[i - 1], o = t[i];
|
|
577
|
+
if (i === 1 && e.push(s), o.gcToPrevious) {
|
|
578
|
+
const n = this.interpolateCoordinates(s, o, 200, !1, !0, "nauticalmiles");
|
|
579
|
+
e.push(...n);
|
|
580
580
|
} else
|
|
581
581
|
e.push(o);
|
|
582
582
|
}
|
|
@@ -588,7 +588,7 @@ class b {
|
|
|
588
588
|
* @param route [[[lng, lat]]]
|
|
589
589
|
*/
|
|
590
590
|
static nearestCoordinateInRoute(t, e) {
|
|
591
|
-
const
|
|
591
|
+
const i = g.point([t.lng, t.lat]), o = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]), n = g.lineString(o), r = g.nearestPointOnLine(n, i), c = g.getCoord(r);
|
|
592
592
|
return { lng: l.roundPrecision(c[0], 8), lat: l.roundPrecision(c[1], 8) };
|
|
593
593
|
}
|
|
594
594
|
/**
|
|
@@ -597,20 +597,20 @@ class b {
|
|
|
597
597
|
* @param waypoints
|
|
598
598
|
*/
|
|
599
599
|
static calculatePrevWaypoint(t, e) {
|
|
600
|
-
let
|
|
600
|
+
let i = 0;
|
|
601
601
|
this.mergeCoordinateToWaypoints(t, e);
|
|
602
602
|
for (let s = 0; s < e.length - 1; s++) {
|
|
603
|
-
const o = e[s],
|
|
603
|
+
const o = e[s], n = e[s + 1];
|
|
604
604
|
if (this.calculateDistance(t, o) === 0) {
|
|
605
|
-
|
|
605
|
+
i = s;
|
|
606
606
|
break;
|
|
607
607
|
}
|
|
608
|
-
if (this.calculateDistance(t,
|
|
609
|
-
|
|
608
|
+
if (this.calculateDistance(t, n) === 0) {
|
|
609
|
+
i = s + 1;
|
|
610
610
|
break;
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
|
-
return e[
|
|
613
|
+
return e[i === 0 ? 0 : i - 1];
|
|
614
614
|
}
|
|
615
615
|
/**
|
|
616
616
|
* 计算下一个距离单位的坐标及其子航线
|
|
@@ -620,11 +620,11 @@ class b {
|
|
|
620
620
|
* @param units
|
|
621
621
|
* @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
|
|
622
622
|
*/
|
|
623
|
-
static calculateNextCoordinateAlongRoute(t, e,
|
|
623
|
+
static calculateNextCoordinateAlongRoute(t, e, i, s = "nauticalmiles") {
|
|
624
624
|
var f;
|
|
625
|
-
const o = t.speed || 12,
|
|
625
|
+
const o = t.speed || 12, n = [];
|
|
626
626
|
let r = [], c = !1, a = 0, d = 0, u;
|
|
627
|
-
if (e &&
|
|
627
|
+
if (e && i.length ? (n.push(t), i.forEach((h, T) => {
|
|
628
628
|
if (c)
|
|
629
629
|
r.push(h);
|
|
630
630
|
else {
|
|
@@ -637,7 +637,7 @@ class b {
|
|
|
637
637
|
S = { lng: h[M][0], lat: h[M][1] };
|
|
638
638
|
const D = this.calculateDistance(t, S, !0, 8, s);
|
|
639
639
|
if (a += D, a < e)
|
|
640
|
-
d += D,
|
|
640
|
+
d += D, n.push(S), t = S;
|
|
641
641
|
else {
|
|
642
642
|
if (d = e, a === e)
|
|
643
643
|
u = S, m.push([u.lng, u.lat]);
|
|
@@ -648,15 +648,15 @@ class b {
|
|
|
648
648
|
c = !0;
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
|
-
m.length && r.push(m),
|
|
651
|
+
m.length && r.push(m), T === i.length - 1 && !u && (u = S);
|
|
652
652
|
}
|
|
653
|
-
})) : (r =
|
|
654
|
-
if (
|
|
653
|
+
})) : (r = i, u = { ...t }), u)
|
|
654
|
+
if (n.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / o * 1e4) / 1e4, ((f = r[0]) == null ? void 0 : f.length) > 1) {
|
|
655
655
|
const h = { lng: r[0][1][0], lat: r[0][1][1] };
|
|
656
656
|
u.bearing = this.calculateBearing(u, h);
|
|
657
657
|
} else
|
|
658
658
|
u.bearing = 0;
|
|
659
|
-
return { coordinate: u, nextRoute: r, prevRoute:
|
|
659
|
+
return { coordinate: u, nextRoute: r, prevRoute: n };
|
|
660
660
|
}
|
|
661
661
|
/**
|
|
662
662
|
* 返回最近点及其是否为垂足(最近点不是起点或终点)
|
|
@@ -664,12 +664,12 @@ class b {
|
|
|
664
664
|
* @param from {lng, lat}
|
|
665
665
|
* @param to {lng, lat}
|
|
666
666
|
*/
|
|
667
|
-
static nearestCoordinateInLine(t, e,
|
|
668
|
-
const s = l.convertToStdLng(t.lng, 6), o = g.point([s, t.lat]),
|
|
669
|
-
[
|
|
670
|
-
[r,
|
|
667
|
+
static nearestCoordinateInLine(t, e, i) {
|
|
668
|
+
const s = l.convertToStdLng(t.lng, 6), o = g.point([s, t.lat]), n = l.convertToStdLng(e.lng, 6), r = l.convertToStdLng(i.lng, 6), c = g.lineString([
|
|
669
|
+
[n, e.lat],
|
|
670
|
+
[r, i.lat]
|
|
671
671
|
]), a = g.nearestPointOnLine(c, o), d = g.getCoord(a), u = l.roundPrecision(d[0], 6), f = l.roundPrecision(d[1], 6);
|
|
672
|
-
return { lng: u, lat: f, inline: !(u ===
|
|
672
|
+
return { lng: u, lat: f, inline: !(u === n && f === e.lat) && !(u === r && f === i.lat) };
|
|
673
673
|
}
|
|
674
674
|
/**
|
|
675
675
|
* 将route转coordinate
|
|
@@ -677,22 +677,22 @@ class b {
|
|
|
677
677
|
* @param distance 临近点过虑
|
|
678
678
|
*/
|
|
679
679
|
static convertRouteToCoordinates(t, e = 0) {
|
|
680
|
-
const
|
|
680
|
+
const i = [];
|
|
681
681
|
let s, o;
|
|
682
|
-
return t.forEach((
|
|
683
|
-
|
|
682
|
+
return t.forEach((n) => {
|
|
683
|
+
n.forEach((r) => {
|
|
684
684
|
const c = { lng: l.roundPrecision(r[0], 8), lat: l.roundPrecision(r[1], 8) };
|
|
685
685
|
if (!o)
|
|
686
|
-
|
|
686
|
+
i.push(c), o = c;
|
|
687
687
|
else if (o.bearing === void 0)
|
|
688
688
|
o.bearing = this.calculateBearing(o, c, !0);
|
|
689
689
|
else {
|
|
690
690
|
const a = this.calculateDistance(s, c, !0);
|
|
691
|
-
a && a >= e && (s.bearing = this.calculateBearing(s, c, !0),
|
|
691
|
+
a && a >= e && (s.bearing = this.calculateBearing(s, c, !0), i.push(s), o = s);
|
|
692
692
|
}
|
|
693
693
|
s = c;
|
|
694
694
|
});
|
|
695
|
-
}), s &&
|
|
695
|
+
}), s && i.push(s), i;
|
|
696
696
|
}
|
|
697
697
|
/**
|
|
698
698
|
* 抽稀(基于转向点)
|
|
@@ -700,8 +700,8 @@ class b {
|
|
|
700
700
|
* @param waypoints [{ lng, lat, gcToPrevious }]
|
|
701
701
|
* @param distance
|
|
702
702
|
*/
|
|
703
|
-
static simplifyRouteToCoordinates(t, e,
|
|
704
|
-
let s = this.convertRouteToCoordinates(t,
|
|
703
|
+
static simplifyRouteToCoordinates(t, e, i = 1) {
|
|
704
|
+
let s = this.convertRouteToCoordinates(t, i);
|
|
705
705
|
return s = this.simplifyGCCoordinates(s, e), s;
|
|
706
706
|
}
|
|
707
707
|
/**
|
|
@@ -714,17 +714,17 @@ class b {
|
|
|
714
714
|
this.mergeCoordinateToWaypoints(s, t, !0);
|
|
715
715
|
});
|
|
716
716
|
for (let s = 1; s < e.length; s++) {
|
|
717
|
-
const o = e[s - 1],
|
|
718
|
-
if (
|
|
719
|
-
const r = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng ===
|
|
717
|
+
const o = e[s - 1], n = e[s];
|
|
718
|
+
if (n.gcToPrevious) {
|
|
719
|
+
const r = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng === n.lng && a.lat === n.lat);
|
|
720
720
|
for (let a = c - 1; a > r; a--)
|
|
721
721
|
t.splice(a, 1);
|
|
722
722
|
}
|
|
723
723
|
}
|
|
724
|
-
let
|
|
724
|
+
let i = 0;
|
|
725
725
|
for (let s = 1; s < t.length; s++) {
|
|
726
|
-
const o = t[s - 1],
|
|
727
|
-
|
|
726
|
+
const o = t[s - 1], n = t[s];
|
|
727
|
+
n.gcToPrevious ? (o.bearing = this.calculateBearing(o, n, !1), n.distanceFromPrevious = this.calculateDistance(o, n, !1)) : (o.bearing = this.calculateBearing(o, n, !0), n.distanceFromPrevious = this.calculateDistance(o, n, !0)), i = l.roundPrecision(i + n.distanceFromPrevious), n.distanceFromStart = i;
|
|
728
728
|
}
|
|
729
729
|
return t.map((s) => (s.lng = l.convertToStdLng(s.lng), s));
|
|
730
730
|
}
|
|
@@ -737,11 +737,11 @@ class b {
|
|
|
737
737
|
for (const r of t)
|
|
738
738
|
for (const c of r)
|
|
739
739
|
e.push(c);
|
|
740
|
-
const
|
|
740
|
+
const i = g.featureCollection([]), s = l.convertToMonotonicLng2(e);
|
|
741
741
|
for (const r of s)
|
|
742
|
-
|
|
743
|
-
const
|
|
744
|
-
return { lng: l.convertToStdLng(
|
|
742
|
+
i.features.push(g.point(r));
|
|
743
|
+
const n = g.center(i).geometry.coordinates;
|
|
744
|
+
return { lng: l.convertToStdLng(n[0], 8), lat: l.roundPrecision(n[1], 8) };
|
|
745
745
|
}
|
|
746
746
|
/**
|
|
747
747
|
* 计算中心点
|
|
@@ -758,9 +758,9 @@ class b {
|
|
|
758
758
|
static calculateBBox(t) {
|
|
759
759
|
const e = [];
|
|
760
760
|
for (const o of t)
|
|
761
|
-
for (const
|
|
762
|
-
e.push(
|
|
763
|
-
const
|
|
761
|
+
for (const n of o)
|
|
762
|
+
e.push(n);
|
|
763
|
+
const i = l.convertToMonotonicLng2(e), s = g.lineString(i);
|
|
764
764
|
return g.bbox(s);
|
|
765
765
|
}
|
|
766
766
|
/**
|
|
@@ -777,14 +777,14 @@ class b {
|
|
|
777
777
|
* @param distance 三点最小距离, 小于此距离时,B点将被忽略(三点太近)
|
|
778
778
|
* @param angle 三点夹角, 大于此角度时,B点将被忽略(近似走RL)
|
|
779
779
|
*/
|
|
780
|
-
static simplifyCoordinates(t, e = 10,
|
|
780
|
+
static simplifyCoordinates(t, e = 10, i = 160) {
|
|
781
781
|
const s = [];
|
|
782
782
|
for (let o = 1; o < t.length; o++) {
|
|
783
|
-
const
|
|
783
|
+
const n = t[o - 1], r = t[o], c = t[o + 1];
|
|
784
784
|
let a = !1, d = !1;
|
|
785
|
-
if ((
|
|
786
|
-
const u = b.calculateDistance(
|
|
787
|
-
Math.round(Math.acos(
|
|
785
|
+
if ((n.velocity || n.suspend || n.important || n.pilot || o === 1) && (a = !0, s.push(n)), r.gcToPrevious && (a || (a = !0, s.push(n)), d = !0, s.push(r), o++), c) {
|
|
786
|
+
const u = b.calculateDistance(n, r, !0), f = b.calculateDistance(r, c, !0), h = b.calculateDistance(n, c, !0), T = (Math.pow(u, 2) + Math.pow(f, 2) - Math.pow(h, 2)) / (2 * u * f);
|
|
787
|
+
Math.round(Math.acos(T) * 180 / Math.PI) < i && h > e && !d && (s.push(r), o++);
|
|
788
788
|
}
|
|
789
789
|
if (o >= t.length - 1) {
|
|
790
790
|
const u = t.at(-1);
|
|
@@ -793,10 +793,22 @@ class b {
|
|
|
793
793
|
}
|
|
794
794
|
return s;
|
|
795
795
|
}
|
|
796
|
+
/**
|
|
797
|
+
* 在时间轨迹上寻找ts最近的点
|
|
798
|
+
* @param ts ts最近的点(向后取), 单位秒
|
|
799
|
+
* @param step 时间步长, 前后n小时
|
|
800
|
+
* @param waypoints 带时间的轨迹, 单位秒
|
|
801
|
+
*/
|
|
802
|
+
static nearestTSPointInWaypoints(t, e, i) {
|
|
803
|
+
const s = y.unix(t), o = i.filter(
|
|
804
|
+
(n) => s.clone().subtract(e, "hour").unix() <= (n.positionTime || 0) && s.clone().add(e, "h").unix() >= (n.positionTime || 0)
|
|
805
|
+
);
|
|
806
|
+
return o.sort((n, r) => (n.positionTime || 0) - (r.positionTime || 0)), o.at(-1);
|
|
807
|
+
}
|
|
796
808
|
}
|
|
797
|
-
let
|
|
809
|
+
let P;
|
|
798
810
|
try {
|
|
799
|
-
|
|
811
|
+
P = O.getLogger("vessel");
|
|
800
812
|
} catch {
|
|
801
813
|
} finally {
|
|
802
814
|
}
|
|
@@ -806,16 +818,16 @@ class q {
|
|
|
806
818
|
* @param raw
|
|
807
819
|
*/
|
|
808
820
|
static convert2Geojson(t) {
|
|
809
|
-
var
|
|
821
|
+
var i;
|
|
810
822
|
const e = g.featureCollection([]);
|
|
811
823
|
for (const s of t) {
|
|
812
824
|
if (s.forecasts) {
|
|
813
|
-
const o = (
|
|
814
|
-
for (const
|
|
815
|
-
const r = [], c =
|
|
825
|
+
const o = (i = s.history) == null ? void 0 : i[0];
|
|
826
|
+
for (const n of s.forecasts) {
|
|
827
|
+
const r = [], c = y(n.date).utc(), a = `${s.name}-${n.model}`;
|
|
816
828
|
if (o) {
|
|
817
|
-
const d =
|
|
818
|
-
model:
|
|
829
|
+
const d = y(o.updated).utc(), u = g.point([o.lng, o.lat], {
|
|
830
|
+
model: n.model,
|
|
819
831
|
name: s.name,
|
|
820
832
|
date: d.format(),
|
|
821
833
|
hour: 0,
|
|
@@ -827,11 +839,11 @@ class q {
|
|
|
827
839
|
});
|
|
828
840
|
e.features.push(u), r.push(u.geometry.coordinates);
|
|
829
841
|
}
|
|
830
|
-
for (const d in
|
|
831
|
-
const u =
|
|
842
|
+
for (const d in n == null ? void 0 : n.hours) {
|
|
843
|
+
const u = n.hours[d];
|
|
832
844
|
u.wind.spd = u.wind.spd || u.wind.speed;
|
|
833
845
|
const f = c.clone().add(Number(d), "hour"), h = g.point([u.lng, u.lat], {
|
|
834
|
-
model:
|
|
846
|
+
model: n.model,
|
|
835
847
|
name: s.name,
|
|
836
848
|
date: f.format(),
|
|
837
849
|
hour: Number(d),
|
|
@@ -847,9 +859,9 @@ class q {
|
|
|
847
859
|
}
|
|
848
860
|
if ((r == null ? void 0 : r.length) > 1) {
|
|
849
861
|
const d = g.lineString(l.convertToMonotonicLng2(r), {
|
|
850
|
-
date:
|
|
862
|
+
date: n.date,
|
|
851
863
|
id: s.id || s.name,
|
|
852
|
-
model:
|
|
864
|
+
model: n.model,
|
|
853
865
|
name: s.name,
|
|
854
866
|
category: a,
|
|
855
867
|
type: "forecast"
|
|
@@ -861,7 +873,7 @@ class q {
|
|
|
861
873
|
if (s.history) {
|
|
862
874
|
const o = [];
|
|
863
875
|
for (const r of s.history) {
|
|
864
|
-
const c =
|
|
876
|
+
const c = y(r.updated).utc(), a = g.point([r.lng, r.lat], {
|
|
865
877
|
name: s.name,
|
|
866
878
|
date: c.format(),
|
|
867
879
|
format: c.format("MMM-DD/HHmm[Z]"),
|
|
@@ -876,17 +888,17 @@ class q {
|
|
|
876
888
|
});
|
|
877
889
|
e.features.push(a), o.push(a.geometry.coordinates);
|
|
878
890
|
}
|
|
879
|
-
const
|
|
891
|
+
const n = s.history[0];
|
|
880
892
|
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
881
893
|
const r = g.lineString(l.convertToMonotonicLng2(o), {
|
|
882
894
|
name: s.name,
|
|
883
895
|
type: "history",
|
|
884
|
-
updated:
|
|
885
|
-
pressure: (
|
|
886
|
-
spd: (
|
|
887
|
-
kts:
|
|
888
|
-
source:
|
|
889
|
-
level:
|
|
896
|
+
updated: n == null ? void 0 : n.updated,
|
|
897
|
+
pressure: (n == null ? void 0 : n.pressure) > 1e4 ? l.roundPrecision((n == null ? void 0 : n.pressure) / 100, 0) : l.roundPrecision(n == null ? void 0 : n.pressure, 0),
|
|
898
|
+
spd: (n == null ? void 0 : n.speed) || (n == null ? void 0 : n.spd),
|
|
899
|
+
kts: n == null ? void 0 : n.kts,
|
|
900
|
+
source: n == null ? void 0 : n.source,
|
|
901
|
+
level: n == null ? void 0 : n.type
|
|
890
902
|
});
|
|
891
903
|
e.features.push(r);
|
|
892
904
|
}
|
|
@@ -900,15 +912,15 @@ class q {
|
|
|
900
912
|
* @param step
|
|
901
913
|
*/
|
|
902
914
|
static interpolate(t, e = 3) {
|
|
903
|
-
var o,
|
|
904
|
-
const
|
|
905
|
-
for (const a of
|
|
906
|
-
const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = a.properties.disabled,
|
|
907
|
-
let m = e * 60 - (
|
|
908
|
-
const S = (
|
|
915
|
+
var o, n, r, c;
|
|
916
|
+
const i = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
|
|
917
|
+
for (const a of i) {
|
|
918
|
+
const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = a.properties.disabled, T = y(a.properties.date).utc();
|
|
919
|
+
let m = e * 60 - (T.get("hour") * 60 + T.get("minute")) % (e * 60);
|
|
920
|
+
const S = (n = t == null ? void 0 : t.data) == null ? void 0 : n.features.filter(
|
|
909
921
|
(v) => v.geometry.type === "Point" && v.properties.type === "forecast" && v.properties.category === `${d}-${u}`
|
|
910
922
|
);
|
|
911
|
-
let M, D =
|
|
923
|
+
let M, D = T.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
912
924
|
for (; M = this.pickIndex(S, D), M <= S.length - 1; ) {
|
|
913
925
|
if (M > 0) {
|
|
914
926
|
const v = S[M], p = M === 0 ? void 0 : S[M - 1], N = (m / 60 - ((r = p == null ? void 0 : p.properties) == null ? void 0 : r.hour)) / (v.properties.hour - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], v.geometry.coordinates[0], N), $ = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], v.geometry.coordinates[1], N), W = g.point([I, $], {
|
|
@@ -928,7 +940,7 @@ class q {
|
|
|
928
940
|
});
|
|
929
941
|
s.push(W);
|
|
930
942
|
}
|
|
931
|
-
m += e * 60, D =
|
|
943
|
+
m += e * 60, D = T.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
932
944
|
}
|
|
933
945
|
}
|
|
934
946
|
return s;
|
|
@@ -940,8 +952,8 @@ class q {
|
|
|
940
952
|
* @param options
|
|
941
953
|
*/
|
|
942
954
|
static accelPassageAt(t, e) {
|
|
943
|
-
const { t1:
|
|
944
|
-
return { t1:
|
|
955
|
+
const { t1: i, t2: s, hr: o, hours: n } = this.tropicalCenterTwin(t, 24, e);
|
|
956
|
+
return { t1: i, t2: s, hr: o, hours: n };
|
|
945
957
|
}
|
|
946
958
|
/**
|
|
947
959
|
* 计算最佳绕航点
|
|
@@ -954,32 +966,32 @@ class q {
|
|
|
954
966
|
* @param speed 前进速度
|
|
955
967
|
* @param options
|
|
956
968
|
*/
|
|
957
|
-
static diversionPassageAt(t, e,
|
|
958
|
-
const { t1: o, t2:
|
|
959
|
-
if (o &&
|
|
969
|
+
static diversionPassageAt(t, e, i, s = {}) {
|
|
970
|
+
const { t1: o, t2: n, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
971
|
+
if (o && n) {
|
|
960
972
|
if (!s.debug) {
|
|
961
|
-
const
|
|
962
|
-
if (
|
|
963
|
-
return
|
|
973
|
+
const T = b.calculateDistance(t, o), m = b.calculateDistance(t, n);
|
|
974
|
+
if (T > 2 * i && m > 2 * i)
|
|
975
|
+
return P == null || P.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, T, m, {
|
|
964
976
|
from: t,
|
|
965
977
|
t1: o,
|
|
966
|
-
t2:
|
|
978
|
+
t2: n,
|
|
967
979
|
hr: r
|
|
968
980
|
}), {};
|
|
969
981
|
}
|
|
970
|
-
const a = b.calculateBearing(t, o), d = b.calculateBearing(o,
|
|
982
|
+
const a = b.calculateBearing(t, o), d = b.calculateBearing(o, n), u = Math.abs(a - d);
|
|
971
983
|
let f = 0;
|
|
972
984
|
u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
|
|
973
|
-
const h = b.calculateCoordinate(o, f,
|
|
974
|
-
return
|
|
985
|
+
const h = b.calculateCoordinate(o, f, i);
|
|
986
|
+
return P == null || P.info("[%s] the right tangent position: %j", s.requestId, {
|
|
975
987
|
from: t,
|
|
976
988
|
t1: o,
|
|
977
|
-
t2:
|
|
978
|
-
radius:
|
|
989
|
+
t2: n,
|
|
990
|
+
radius: i,
|
|
979
991
|
bearing1: a,
|
|
980
992
|
bearing2: d,
|
|
981
993
|
right: h
|
|
982
|
-
}), { at: h, t1: o, t2:
|
|
994
|
+
}), { at: h, t1: o, t2: n, hr: Number(r), hours: c };
|
|
983
995
|
}
|
|
984
996
|
return {};
|
|
985
997
|
}
|
|
@@ -993,23 +1005,23 @@ class q {
|
|
|
993
1005
|
* @param radius 与台风中心的距离
|
|
994
1006
|
* @param options
|
|
995
1007
|
*/
|
|
996
|
-
static driftPassageAt(t, e,
|
|
997
|
-
const { t1: o, t2:
|
|
998
|
-
if (o &&
|
|
1008
|
+
static driftPassageAt(t, e, i, s = {}) {
|
|
1009
|
+
const { t1: o, t2: n, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
1010
|
+
if (o && n) {
|
|
999
1011
|
if (!s.debug) {
|
|
1000
|
-
const h = b.calculateDistance(t, o),
|
|
1001
|
-
if (h > 2 *
|
|
1002
|
-
return
|
|
1012
|
+
const h = b.calculateDistance(t, o), T = b.calculateDistance(t, n);
|
|
1013
|
+
if (h > 2 * i && T > 2 * i)
|
|
1014
|
+
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, T, {
|
|
1003
1015
|
from: t,
|
|
1004
1016
|
t1: o,
|
|
1005
|
-
t2:
|
|
1017
|
+
t2: n,
|
|
1006
1018
|
hr: r
|
|
1007
1019
|
}), {};
|
|
1008
1020
|
}
|
|
1009
|
-
const a = b.calculateBearing(t, o), d = b.calculateBearing(o,
|
|
1010
|
-
return { at: b.calculateCoordinate(o, a - d + 180,
|
|
1021
|
+
const a = b.calculateBearing(t, o), d = b.calculateBearing(o, n), u = b.calculateDistance(t, o);
|
|
1022
|
+
return { at: b.calculateCoordinate(o, a - d + 180, i < u ? i : u), t1: o, t2: n, hr: Number(r), hours: c };
|
|
1011
1023
|
} else
|
|
1012
|
-
return
|
|
1024
|
+
return P == null || P.info("[%s] no need drift: %j", s.requestId, { from: t, t1: o, t2: n, hr: r }), {};
|
|
1013
1025
|
}
|
|
1014
1026
|
/**
|
|
1015
1027
|
* 获取台风中心点对
|
|
@@ -1019,42 +1031,42 @@ class q {
|
|
|
1019
1031
|
* @returns { t1: 当前台风中心点, t2: 未来hr小时台风中心点, hr: 未来台风中心点与当前台风中心点之间的时间差, hours: 未来24小时内所有台风中心点 }
|
|
1020
1032
|
* @private
|
|
1021
1033
|
*/
|
|
1022
|
-
static tropicalCenterTwin(t, e = 24,
|
|
1023
|
-
var d, u, f, h,
|
|
1034
|
+
static tropicalCenterTwin(t, e = 24, i = {}) {
|
|
1035
|
+
var d, u, f, h, T;
|
|
1024
1036
|
let s = {};
|
|
1025
1037
|
(d = t.forecasts) == null || d.forEach((m) => {
|
|
1026
1038
|
s = { ...m.hours, ...s };
|
|
1027
1039
|
});
|
|
1028
1040
|
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (s == null ? void 0 : s[(f = Object.keys(s)) == null ? void 0 : f[0]]);
|
|
1029
|
-
|
|
1030
|
-
let
|
|
1031
|
-
|
|
1032
|
-
const r = s == null ? void 0 : s[
|
|
1033
|
-
|
|
1034
|
-
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(
|
|
1041
|
+
P == null || P.info("[%s] the first tropical center: %j", i.requestId, o);
|
|
1042
|
+
let n = (h = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
|
|
1043
|
+
n || (n = (T = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : T.at(-1));
|
|
1044
|
+
const r = s == null ? void 0 : s[n || -1];
|
|
1045
|
+
P == null || P.info("[%s] the second tropical center: %j in %d hrs", i.requestId, r, n);
|
|
1046
|
+
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(n)), a = { 0: o };
|
|
1035
1047
|
for (const m of c)
|
|
1036
1048
|
a[m] = s[m];
|
|
1037
|
-
return { t1: o, t2: r, hr: Number(
|
|
1049
|
+
return { t1: o, t2: r, hr: Number(n), hours: a };
|
|
1038
1050
|
}
|
|
1039
1051
|
static pickIndex(t, e) {
|
|
1040
|
-
let
|
|
1052
|
+
let i = 0;
|
|
1041
1053
|
for (const s of t) {
|
|
1042
|
-
if (
|
|
1043
|
-
return
|
|
1044
|
-
|
|
1054
|
+
if (y(s.properties.date).isAfter(e))
|
|
1055
|
+
return i === 0 ? -1 : i;
|
|
1056
|
+
i++;
|
|
1045
1057
|
}
|
|
1046
|
-
return
|
|
1058
|
+
return i;
|
|
1047
1059
|
}
|
|
1048
|
-
static computeNumber(t, e,
|
|
1060
|
+
static computeNumber(t, e, i) {
|
|
1049
1061
|
if (t)
|
|
1050
1062
|
if (e) {
|
|
1051
1063
|
if (isNaN(t) && isNaN(e) && typeof t != "string" && typeof e != "string") {
|
|
1052
1064
|
const s = {};
|
|
1053
1065
|
for (const o in t)
|
|
1054
|
-
s[o] = this.computeNumber(t[o], e[o],
|
|
1066
|
+
s[o] = this.computeNumber(t[o], e[o], i);
|
|
1055
1067
|
return s;
|
|
1056
1068
|
}
|
|
1057
|
-
return Math.round((t + (e - t) *
|
|
1069
|
+
return Math.round((t + (e - t) * i) * 100) / 100;
|
|
1058
1070
|
} else
|
|
1059
1071
|
return t;
|
|
1060
1072
|
else
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(M,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):(M=typeof globalThis<"u"?globalThis:M||self,I(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,I,R,q,j){"use strict";function O(v){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const e in v)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(v,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>v[e]})}}return t.default=v,Object.freeze(t)}const g=O(I);function W(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 k={getLogger:$?$.getLogger:()=>new x};const A=W(k);class l{static guessTimeZoneOffset(t,e){const n=j(e,t),s=R().tz(n).utcOffset();return this.roundPrecision(s/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=l.convertToStdLng(t,e);let s="E";t<0&&(s="W"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,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);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,e),minute:l.roundPrecision(c,e),second:l.roundPrecision(i,e),pretty:f}}static lat2pretty(t,e=6,n="H°M′"){t=t%180;let s="N";t<0&&(s="S"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,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);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,e),minute:l.roundPrecision(c,e),second:l.roundPrecision(i,e),pretty:f}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=l.strReplace(t,"LNG");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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(t);return l.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=l.strReplace(t,"LAT");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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(t);return l.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=l.strReplace(t,n);const s=t[t.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(t,e)}:{lng:l.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),l.roundPrecision(t,e)}static roundPrecision(t,e=4){if(typeof t=="number"){const n=Number("1".padEnd(e+1,"0"));return Math.round(t*n)/n}return t}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(/-/g," ").replace(/°/," ").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 s=t,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${t}`);o>=90?t=`${s}E`:o<=-90?t=`${s}W`:["LAN","LNG"].includes(e==null?void 0:e.toUpperCase())?t=`${s}${o>0?"E":"W"}`:t=`${s}${o>0?"N":"S"}`}return t}static padNumber(t,e=2,n=2){const s=Math.trunc(t).toString().padStart(e,"0"),o=Math.trunc(l.roundPrecision(t-Math.trunc(t),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class b{static calculateBearing(t,e,n=!0,s=4){const o=g.points([[t.lng,t.lat],[e.lng,e.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(t,e,n=!0,s=4,o="nauticalmiles"){t={...t},e={...e},t.lng=l.convertToStdLng(t.lng,s),e.lng=l.convertToStdLng(e.lng,s);const i=g.points([[t.lng,t.lat],[e.lng,e.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(t,e=4,n="nauticalmiles"){let s=0,o;for(const i of t)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,e,n));const a={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,a,!0,e,n),o=a}return l.roundPrecision(s,e)}static calculateCoordinate(t,e,n,s="nauticalmiles",o=!0){const i=g.point([t.lng,t.lat]);let r;o?r=g.rhumbDestination(i,n,e,{units:s}):r=g.destination(i,n,e,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(t,e,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,i);s&&r.push({lng:t.lng,lat:t.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(t,c,d,i,!1));return o&&r.push({lng:e.lng,lat:e.lat}),r}static divideAccordingToLng(t,e=!1){if((t==null?void 0:t.length)<2)return[];t=this.deduplicateCoordinates(t);let n=[];const s=[];let o,i;for(let r=0;r<t.length-1;r++){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]);const c=o-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[o,t[r].lat],[i,t[r+1].lat]]);let d,u;e?(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 f=g.lineIntersect(d,u);let h;if(f.features.length){const P=g.getCoord(f.features[0]);h=l.roundPrecision(P[1],8)}else h=t[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===t.length-2&&n.push([i,t[r+1].lat])}return s.push(n),s}static deduplicateRoute(t){const e=[];for(const n of t){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);e.push(s)}return e}static deduplicateCoordinates(t){return t.reduce((e,n)=>(e.findIndex(s=>s.lat===n.lat&&s.lng===n.lng)===-1&&e.push(n),e),[])}static removeCoordinateFromRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);for(const n of e)for(let s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===t.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(t.lat,8)&&n.splice(s,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=l.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)l.roundPrecision(e[n].lng,8)===t.lng&&l.roundPrecision(e[n].lat,8)===l.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,s=0,o=0,i,r;return e.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},f={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(t,u,f);n>h&&(n=h,o=d,s=a,i=this.calculateDistance(u,t),r=this.calculateDistance(f,t))}}),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}static appendCoordinateToRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);const n=b.convertRouteToCoordinates(e);return n.push(t),b.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=b.convertRouteToCoordinates(e);return n.unshift(t),b.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([t.lng,t.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(t,e,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([t,e,...s],o),r=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,s=0,o=0;return e.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(t,a,d);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(t,e){const n=b.convertRouteToCoordinates(e);b.mergeCoordinateToWaypoints(t,n,!0),e=b.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...t},e);t.lng=l.convertToStdLng(t.lng);const i=[];let r=!0;for(let c=s;c<e.length;c++)if(r){const a=[];a.push([t.lng,t.lat]);for(let d=o+1;d<e[c].length;d++)t.lng===e[c][d][0]&&t.lat===e[c][d][1]||a.push(e[c][d]);i.push(a),r=!1}else i.push([...e[c]]);return i}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,s=0;for(let i=0;i<e.length-1;i++){const r=e[i],c=e[i+1];if(this.calculateDistance(t,r)===0)return e;if(this.calculateDistance(t,c)===0)return e.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(t,r,c);n>a&&(n=a,s=i)}t.lng=l.convertToStdLng(t.lng);const o=[t];for(let i=s+1;i<e.length;i++)o.push(e[i]);return o}static calculatePointToLineDistance(t,e,n,s={units:"nauticalmiles",method:"geodesic"}){t.lng=l.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=l.convertToStdLng(e.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([e,n]);e=o[0],n=o[1];const i=g.lineString([[e.lng,e.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([t.lng,t.lat]),i,s),c=g.pointToLineDistance(g.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),i,s);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(t,e){e=this.mergeWaypointsToRoute(t,e);for(let n=0;n<t.length-1;n++){const s=t[n],o=t[n+1],i=this.calculateRangeRoute(s,o,e);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return t}static mergeCoordinatesToWaypoints(t,e,n=!0){for(const s of t)this.mergeCoordinateToWaypoints(s,e,n);return e}static mergeCoordinateToWaypoints(t,e,n=!0){t.lng=l.convertToStdLng(t.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<e.length-1;c++){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);s>=u&&(s=u,o=c,i=this.calculateDistance(a,t,!1,6),r=this.calculateDistance(d,t,!1,6))}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))}static generateRouteAccordingToWaypoints(t){const e=[];for(let n=1;n<t.length;n++){const s=t[n-1],o=t[n];if(n===1&&e.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");e.push(...i)}else e.push(o)}return this.divideAccordingToLng(e,!0)}static nearestCoordinateInRoute(t,e){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);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(t,e){let n=0;this.mergeCoordinateToWaypoints(t,e);for(let s=0;s<e.length-1;s++){const o=e[s],i=e[s+1];if(this.calculateDistance(t,o)===0){n=s;break}if(this.calculateDistance(t,i)===0){n=s+1;break}}return e[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(t,e,n,s="nauticalmiles"){var f;const o=t.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(e&&n.length?(i.push(t),n.forEach((h,P)=>{if(c)r.push(h);else{const m=[];let C;for(let D=0;D<h.length;D++)if(u)m.push(h[D]);else{C={lng:h[D][0],lat:h[D][1]};const N=this.calculateDistance(t,C,!0,8,s);if(a+=N,a<e)d+=N,i.push(C),t=C;else{if(d=e,a===e)u=C,m.push([u.lng,u.lat]);else{const S=a-e,p=this.calculateBearing(C,t);u=this.calculateCoordinate(C,p,S,s),m.push([u.lng,u.lat]),m.push([C.lng,C.lat])}c=!0}}m.length&&r.push(m),P===n.length-1&&!u&&(u=C)}})):(r=n,u={...t}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/o*1e4)/1e4,((f=r[0])==null?void 0:f.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(t,e,n){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([[i,e.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,o),d=g.getCoord(a),u=l.roundPrecision(d[0],6),f=l.roundPrecision(d[1],6);return{lng:u,lat:f,inline:!(u===i&&f===e.lat)&&!(u===r&&f===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let s,o;return t.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>=e&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(t,e,n=1){let s=this.convertRouteToCoordinates(t,n);return s=this.simplifyGCCoordinates(s,e),s}static simplifyGCCoordinates(t,e){e.forEach(s=>{this.mergeCoordinateToWaypoints(s,t,!0)});for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];if(i.gcToPrevious){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);for(let a=c-1;a>r;a--)t.splice(a,1)}}let n=0;for(let s=1;s<t.length;s++){const o=t[s-1],i=t[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 t.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(t){const e=[];for(const r of t)for(const c of r)e.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(e);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(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateCenter(e)}static calculateBBox(t){const e=[];for(const o of t)for(const i of o)e.push(i);const n=l.convertToMonotonicLng2(e),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateBBox(e)}static simplifyCoordinates(t,e=10,n=160){const s=[];for(let o=1;o<t.length;o++){const i=t[o-1],r=t[o],c=t[o+1];let a=!1,d=!1;if((i.velocity||i.suspend||i.important||i.pilot||o===1)&&(a=!0,s.push(i)),r.gcToPrevious&&(a||(a=!0,s.push(i)),d=!0,s.push(r),o++),c){const u=b.calculateDistance(i,r,!0),f=b.calculateDistance(r,c,!0),h=b.calculateDistance(i,c,!0),P=(Math.pow(u,2)+Math.pow(f,2)-Math.pow(h,2))/(2*u*f);Math.round(Math.acos(P)*180/Math.PI)<n&&h>e&&!d&&(s.push(r),o++)}if(o>=t.length-1){const u=t.at(-1);u&&s.push(u)}}return s}}let T;try{T=A.getLogger("vessel")}catch{}finally{}class E{static convert2Geojson(t){var n;const e=g.featureCollection([]);for(const s of t){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"});e.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 f=c.clone().add(Number(d),"hour"),h=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:f.format(),hour:Number(d),format:f.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"});e.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"});e.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});e.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});e.features.push(r)}}}return e}static interpolate(t,e=3){var o,i,r,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"),s=[];for(const a of n){const d=a.properties.name,u=a.properties.model,f=a.properties.showCircle,h=a.properties.disabled,P=R(a.properties.date).utc();let m=e*60-(P.get("hour")*60+P.get("minute"))%(e*60);const C=(i=t==null?void 0:t.data)==null?void 0:i.features.filter(S=>S.geometry.type==="Point"&&S.properties.type==="forecast"&&S.properties.category===`${d}-${u}`);let D,N=P.clone().add(m,"minute").set({minute:0,second:0,millisecond:0});for(;D=this.pickIndex(C,N),D<=C.length-1;){if(D>0){const S=C[D],p=D===0?void 0:C[D-1],y=(m/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(S.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],S.geometry.coordinates[0],y),L=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],S.geometry.coordinates[1],y),B=g.point([F,L],{name:d,model:u,category:S==null?void 0:S.properties.category,date:N.format(),format:N.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,S.properties.gusts,y),hour:this.computeNumber(p==null?void 0:p.properties.hour,S.properties.hour,y),movement:this.computeNumber(p==null?void 0:p.properties.movement,S.properties.movement,y),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,S.properties.pressure,y),wind:this.computeNumber(p==null?void 0:p.properties.wind,S.properties.wind,y),type:"forecast",disabled:h,showCircle:f});s.push(B)}m+=e*60,N=P.clone().add(m,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(t,e){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(t,e,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(e,24,s);if(o&&i){if(!s.debug){const P=b.calculateDistance(t,o),m=b.calculateDistance(t,i);if(P>2*n&&m>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,P,m,{from:t,t1:o,t2:i,hr:r}),{}}const a=b.calculateBearing(t,o),d=b.calculateBearing(o,i),u=Math.abs(a-d);let f=0;u<180?f=u+90:u>=180&&(f=u-90);const h=b.calculateCoordinate(o,f,n);return T==null||T.info("[%s] the right tangent position: %j",s.requestId,{from:t,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(t,e,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(e,24,s);if(o&&i){if(!s.debug){const h=b.calculateDistance(t,o),P=b.calculateDistance(t,i);if(h>2*n&&P>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,h,P,{from:t,t1:o,t2:i,hr:r}),{}}const a=b.calculateBearing(t,o),d=b.calculateBearing(o,i),u=b.calculateDistance(t,o);return{at:b.calculateCoordinate(o,a-d+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return T==null||T.info("[%s] no need drift: %j",s.requestId,{from:t,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(t,e=24,n={}){var d,u,f,h,P;let s={};(d=t.forecasts)==null||d.forEach(m=>{s={...m.hours,...s}});const o=((u=t==null?void 0:t.history)==null?void 0:u[0])||(s==null?void 0:s[(f=Object.keys(s))==null?void 0:f[0]]);T==null||T.info("[%s] the first tropical center: %j",n.requestId,o);let i=(h=Object.keys(s||{}).filter(m=>Number(m)<=(e<0?24:e)))==null?void 0:h.at(-1);i||(i=(P=Object.keys(s||{}).filter(m=>Number(m)<=(e<0?24:2*e)))==null?void 0:P.at(-1));const r=s==null?void 0:s[i||-1];T==null||T.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(t,e){let n=0;for(const s of t){if(R(s.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 s={};for(const o in t)s[o]=this.computeNumber(t[o],e[o],n);return s}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}M.LaneHelper=b,M.LngLatHelper=l,M.TropicalHelper=E,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(M,x){typeof exports=="object"&&typeof module<"u"?x(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"],x):(M=typeof globalThis<"u"?globalThis:M||self,x(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,x,N,q,j){"use strict";function W(v){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const e in v)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(v,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>v[e]})}}return t.default=v,Object.freeze(t)}const g=W(x);function O(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}class I{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(v=>{I.prototype[v.toLowerCase()]=()=>{},I.prototype[`is${v}Enabled`]=()=>!1});const $=(()=>{try{return require("log4js")}catch{return null}})();var k={getLogger:$?$.getLogger:()=>new I};const A=O(k);class l{static guessTimeZoneOffset(t,e){const n=j(e,t),s=N().tz(n).utcOffset();return this.roundPrecision(s/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=l.convertToStdLng(t,e);let s="E";t<0&&(s="W"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,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);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,e),minute:l.roundPrecision(c,e),second:l.roundPrecision(i,e),pretty:f}}static lat2pretty(t,e=6,n="H°M′"){t=t%180;let s="N";t<0&&(s="S"),t=Math.abs(t),n=n.toUpperCase();let o=t*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,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);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(d,e),minute:l.roundPrecision(c,e),second:l.roundPrecision(i,e),pretty:f}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=l.strReplace(t,"LNG");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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(t);return l.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=l.strReplace(t,"LAT");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const o=t.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(t);return l.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=l.strReplace(t,n);const s=t[t.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(t,e)}:{lng:l.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),l.roundPrecision(t,e)}static roundPrecision(t,e=4){if(typeof t=="number"){const n=Number("1".padEnd(e+1,"0"));return Math.round(t*n)/n}return t}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(/-/g," ").replace(/°/," ").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 s=t,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${t}`);o>=90?t=`${s}E`:o<=-90?t=`${s}W`:["LAN","LNG"].includes(e==null?void 0:e.toUpperCase())?t=`${s}${o>0?"E":"W"}`:t=`${s}${o>0?"N":"S"}`}return t}static padNumber(t,e=2,n=2){const s=Math.trunc(t).toString().padStart(e,"0"),o=Math.trunc(l.roundPrecision(t-Math.trunc(t),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class b{static calculateBearing(t,e,n=!0,s=4){const o=g.points([[t.lng,t.lat],[e.lng,e.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(t,e,n=!0,s=4,o="nauticalmiles"){t={...t},e={...e},t.lng=l.convertToStdLng(t.lng,s),e.lng=l.convertToStdLng(e.lng,s);const i=g.points([[t.lng,t.lat],[e.lng,e.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(t,e=4,n="nauticalmiles"){let s=0,o;for(const i of t)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,e,n));const a={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,a,!0,e,n),o=a}return l.roundPrecision(s,e)}static calculateCoordinate(t,e,n,s="nauticalmiles",o=!0){const i=g.point([t.lng,t.lat]);let r;o?r=g.rhumbDestination(i,n,e,{units:s}):r=g.destination(i,n,e,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(t,e,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,i);s&&r.push({lng:t.lng,lat:t.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(t,c,d,i,!1));return o&&r.push({lng:e.lng,lat:e.lat}),r}static divideAccordingToLng(t,e=!1){if((t==null?void 0:t.length)<2)return[];t=this.deduplicateCoordinates(t);let n=[];const s=[];let o,i;for(let r=0;r<t.length-1;r++){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]);const c=o-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[o,t[r].lat],[i,t[r+1].lat]]);let d,u;e?(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 f=g.lineIntersect(d,u);let h;if(f.features.length){const P=g.getCoord(f.features[0]);h=l.roundPrecision(P[1],8)}else h=t[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===t.length-2&&n.push([i,t[r+1].lat])}return s.push(n),s}static deduplicateRoute(t){const e=[];for(const n of t){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);e.push(s)}return e}static deduplicateCoordinates(t){return t.reduce((e,n)=>(e.findIndex(s=>s.lat===n.lat&&s.lng===n.lng)===-1&&e.push(n),e),[])}static removeCoordinateFromRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);for(const n of e)for(let s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===t.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(t.lat,8)&&n.splice(s,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=l.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)l.roundPrecision(e[n].lng,8)===t.lng&&l.roundPrecision(e[n].lat,8)===l.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,s=0,o=0,i,r;return e.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},f={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(t,u,f);n>h&&(n=h,o=d,s=a,i=this.calculateDistance(u,t),r=this.calculateDistance(f,t))}}),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}static appendCoordinateToRoute(t,e){t.lng=l.convertToStdLng(t.lng,8);const n=b.convertRouteToCoordinates(e);return n.push(t),b.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=b.convertRouteToCoordinates(e);return n.unshift(t),b.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([t.lng,t.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(t,e,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([t,e,...s],o),r=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,s=0,o=0;return e.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(t,a,d);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(t,e){const n=b.convertRouteToCoordinates(e);b.mergeCoordinateToWaypoints(t,n,!0),e=b.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...t},e);t.lng=l.convertToStdLng(t.lng);const i=[];let r=!0;for(let c=s;c<e.length;c++)if(r){const a=[];a.push([t.lng,t.lat]);for(let d=o+1;d<e[c].length;d++)t.lng===e[c][d][0]&&t.lat===e[c][d][1]||a.push(e[c][d]);i.push(a),r=!1}else i.push([...e[c]]);return i}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,s=0;for(let i=0;i<e.length-1;i++){const r=e[i],c=e[i+1];if(this.calculateDistance(t,r)===0)return e;if(this.calculateDistance(t,c)===0)return e.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(t,r,c);n>a&&(n=a,s=i)}t.lng=l.convertToStdLng(t.lng);const o=[t];for(let i=s+1;i<e.length;i++)o.push(e[i]);return o}static calculatePointToLineDistance(t,e,n,s={units:"nauticalmiles",method:"geodesic"}){t.lng=l.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=l.convertToStdLng(e.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([e,n]);e=o[0],n=o[1];const i=g.lineString([[e.lng,e.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([t.lng,t.lat]),i,s),c=g.pointToLineDistance(g.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),i,s);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(t,e){e=this.mergeWaypointsToRoute(t,e);for(let n=0;n<t.length-1;n++){const s=t[n],o=t[n+1],i=this.calculateRangeRoute(s,o,e);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return t}static mergeCoordinatesToWaypoints(t,e,n=!0){for(const s of t)this.mergeCoordinateToWaypoints(s,e,n);return e}static mergeCoordinateToWaypoints(t,e,n=!0){t.lng=l.convertToStdLng(t.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<e.length-1;c++){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);s>=u&&(s=u,o=c,i=this.calculateDistance(a,t,!1,6),r=this.calculateDistance(d,t,!1,6))}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))}static generateRouteAccordingToWaypoints(t){const e=[];for(let n=1;n<t.length;n++){const s=t[n-1],o=t[n];if(n===1&&e.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");e.push(...i)}else e.push(o)}return this.divideAccordingToLng(e,!0)}static nearestCoordinateInRoute(t,e){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);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(t,e){let n=0;this.mergeCoordinateToWaypoints(t,e);for(let s=0;s<e.length-1;s++){const o=e[s],i=e[s+1];if(this.calculateDistance(t,o)===0){n=s;break}if(this.calculateDistance(t,i)===0){n=s+1;break}}return e[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(t,e,n,s="nauticalmiles"){var f;const o=t.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(e&&n.length?(i.push(t),n.forEach((h,P)=>{if(c)r.push(h);else{const m=[];let C;for(let D=0;D<h.length;D++)if(u)m.push(h[D]);else{C={lng:h[D][0],lat:h[D][1]};const y=this.calculateDistance(t,C,!0,8,s);if(a+=y,a<e)d+=y,i.push(C),t=C;else{if(d=e,a===e)u=C,m.push([u.lng,u.lat]);else{const S=a-e,p=this.calculateBearing(C,t);u=this.calculateCoordinate(C,p,S,s),m.push([u.lng,u.lat]),m.push([C.lng,C.lat])}c=!0}}m.length&&r.push(m),P===n.length-1&&!u&&(u=C)}})):(r=n,u={...t}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/o*1e4)/1e4,((f=r[0])==null?void 0:f.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(t,e,n){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([[i,e.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,o),d=g.getCoord(a),u=l.roundPrecision(d[0],6),f=l.roundPrecision(d[1],6);return{lng:u,lat:f,inline:!(u===i&&f===e.lat)&&!(u===r&&f===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let s,o;return t.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>=e&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(t,e,n=1){let s=this.convertRouteToCoordinates(t,n);return s=this.simplifyGCCoordinates(s,e),s}static simplifyGCCoordinates(t,e){e.forEach(s=>{this.mergeCoordinateToWaypoints(s,t,!0)});for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];if(i.gcToPrevious){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);for(let a=c-1;a>r;a--)t.splice(a,1)}}let n=0;for(let s=1;s<t.length;s++){const o=t[s-1],i=t[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 t.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(t){const e=[];for(const r of t)for(const c of r)e.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(e);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(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateCenter(e)}static calculateBBox(t){const e=[];for(const o of t)for(const i of o)e.push(i);const n=l.convertToMonotonicLng2(e),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateBBox(e)}static simplifyCoordinates(t,e=10,n=160){const s=[];for(let o=1;o<t.length;o++){const i=t[o-1],r=t[o],c=t[o+1];let a=!1,d=!1;if((i.velocity||i.suspend||i.important||i.pilot||o===1)&&(a=!0,s.push(i)),r.gcToPrevious&&(a||(a=!0,s.push(i)),d=!0,s.push(r),o++),c){const u=b.calculateDistance(i,r,!0),f=b.calculateDistance(r,c,!0),h=b.calculateDistance(i,c,!0),P=(Math.pow(u,2)+Math.pow(f,2)-Math.pow(h,2))/(2*u*f);Math.round(Math.acos(P)*180/Math.PI)<n&&h>e&&!d&&(s.push(r),o++)}if(o>=t.length-1){const u=t.at(-1);u&&s.push(u)}}return s}static nearestTSPointInWaypoints(t,e,n){const s=N.unix(t),o=n.filter(i=>s.clone().subtract(e,"hour").unix()<=(i.positionTime||0)&&s.clone().add(e,"h").unix()>=(i.positionTime||0));return o.sort((i,r)=>(i.positionTime||0)-(r.positionTime||0)),o.at(-1)}}let T;try{T=A.getLogger("vessel")}catch{}finally{}class E{static convert2Geojson(t){var n;const e=g.featureCollection([]);for(const s of t){if(s.forecasts){const o=(n=s.history)==null?void 0:n[0];for(const i of s.forecasts){const r=[],c=N(i.date).utc(),a=`${s.name}-${i.model}`;if(o){const d=N(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"});e.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 f=c.clone().add(Number(d),"hour"),h=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:f.format(),hour:Number(d),format:f.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"});e.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"});e.features.push(d)}}}if(s.history){const o=[];for(const r of s.history){const c=N(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});e.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});e.features.push(r)}}}return e}static interpolate(t,e=3){var o,i,r,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"),s=[];for(const a of n){const d=a.properties.name,u=a.properties.model,f=a.properties.showCircle,h=a.properties.disabled,P=N(a.properties.date).utc();let m=e*60-(P.get("hour")*60+P.get("minute"))%(e*60);const C=(i=t==null?void 0:t.data)==null?void 0:i.features.filter(S=>S.geometry.type==="Point"&&S.properties.type==="forecast"&&S.properties.category===`${d}-${u}`);let D,y=P.clone().add(m,"minute").set({minute:0,second:0,millisecond:0});for(;D=this.pickIndex(C,y),D<=C.length-1;){if(D>0){const S=C[D],p=D===0?void 0:C[D-1],R=(m/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(S.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],S.geometry.coordinates[0],R),L=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],S.geometry.coordinates[1],R),B=g.point([F,L],{name:d,model:u,category:S==null?void 0:S.properties.category,date:y.format(),format:y.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,S.properties.gusts,R),hour:this.computeNumber(p==null?void 0:p.properties.hour,S.properties.hour,R),movement:this.computeNumber(p==null?void 0:p.properties.movement,S.properties.movement,R),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,S.properties.pressure,R),wind:this.computeNumber(p==null?void 0:p.properties.wind,S.properties.wind,R),type:"forecast",disabled:h,showCircle:f});s.push(B)}m+=e*60,y=P.clone().add(m,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(t,e){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(t,e,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(e,24,s);if(o&&i){if(!s.debug){const P=b.calculateDistance(t,o),m=b.calculateDistance(t,i);if(P>2*n&&m>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,P,m,{from:t,t1:o,t2:i,hr:r}),{}}const a=b.calculateBearing(t,o),d=b.calculateBearing(o,i),u=Math.abs(a-d);let f=0;u<180?f=u+90:u>=180&&(f=u-90);const h=b.calculateCoordinate(o,f,n);return T==null||T.info("[%s] the right tangent position: %j",s.requestId,{from:t,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(t,e,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(e,24,s);if(o&&i){if(!s.debug){const h=b.calculateDistance(t,o),P=b.calculateDistance(t,i);if(h>2*n&&P>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,h,P,{from:t,t1:o,t2:i,hr:r}),{}}const a=b.calculateBearing(t,o),d=b.calculateBearing(o,i),u=b.calculateDistance(t,o);return{at:b.calculateCoordinate(o,a-d+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return T==null||T.info("[%s] no need drift: %j",s.requestId,{from:t,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(t,e=24,n={}){var d,u,f,h,P;let s={};(d=t.forecasts)==null||d.forEach(m=>{s={...m.hours,...s}});const o=((u=t==null?void 0:t.history)==null?void 0:u[0])||(s==null?void 0:s[(f=Object.keys(s))==null?void 0:f[0]]);T==null||T.info("[%s] the first tropical center: %j",n.requestId,o);let i=(h=Object.keys(s||{}).filter(m=>Number(m)<=(e<0?24:e)))==null?void 0:h.at(-1);i||(i=(P=Object.keys(s||{}).filter(m=>Number(m)<=(e<0?24:2*e)))==null?void 0:P.at(-1));const r=s==null?void 0:s[i||-1];T==null||T.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(t,e){let n=0;for(const s of t){if(N(s.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 s={};for(const o in t)s[o]=this.computeNumber(t[o],e[o],n);return s}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}M.LaneHelper=b,M.LngLatHelper=l,M.TropicalHelper=E,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
package/dist/lane/src/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface Coordinate {
|
|
|
16
16
|
suspend?: number;
|
|
17
17
|
velocity?: number;
|
|
18
18
|
pilot?: boolean;
|
|
19
|
+
positionTime?: number;
|
|
19
20
|
}
|
|
20
21
|
export declare class LaneHelper {
|
|
21
22
|
/**
|
|
@@ -307,4 +308,11 @@ export declare class LaneHelper {
|
|
|
307
308
|
* @param angle 三点夹角, 大于此角度时,B点将被忽略(近似走RL)
|
|
308
309
|
*/
|
|
309
310
|
static simplifyCoordinates(coordinates: Coordinate[], minDistance?: number, minAngle?: number): Coordinate[];
|
|
311
|
+
/**
|
|
312
|
+
* 在时间轨迹上寻找ts最近的点
|
|
313
|
+
* @param ts ts最近的点(向后取), 单位秒
|
|
314
|
+
* @param step 时间步长, 前后n小时
|
|
315
|
+
* @param waypoints 带时间的轨迹, 单位秒
|
|
316
|
+
*/
|
|
317
|
+
static nearestTSPointInWaypoints(ts: number, step: number, waypoints: Coordinate[]): Coordinate | undefined;
|
|
310
318
|
}
|