@idm-plugin/geo 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +222 -227
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,11 +28,11 @@ const k = () => {
|
|
|
28
28
|
} catch {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
}, y = k(),
|
|
32
|
-
var
|
|
33
|
-
getLogger:
|
|
31
|
+
}, y = k(), L = y ? y.getLogger : () => new R();
|
|
32
|
+
var A = {
|
|
33
|
+
getLogger: L
|
|
34
34
|
};
|
|
35
|
-
const
|
|
35
|
+
const F = /* @__PURE__ */ E(A);
|
|
36
36
|
class l {
|
|
37
37
|
/**
|
|
38
38
|
* 基于输入的经度,计算出时区
|
|
@@ -40,8 +40,8 @@ class l {
|
|
|
40
40
|
* @param lat
|
|
41
41
|
*/
|
|
42
42
|
static guessTimeZoneOffset(t, e) {
|
|
43
|
-
const n = W(e, t),
|
|
44
|
-
return this.roundPrecision(
|
|
43
|
+
const n = W(e, t), s = D().tz(n).utcOffset();
|
|
44
|
+
return this.roundPrecision(s / 60, 1);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* 将时间offset转换为时区,例如:8.5 => +08:30
|
|
@@ -54,16 +54,16 @@ class l {
|
|
|
54
54
|
}
|
|
55
55
|
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
56
56
|
t = l.convertToStdLng(t, e);
|
|
57
|
-
let
|
|
58
|
-
t < 0 && (
|
|
59
|
-
let o = t * 3600,
|
|
60
|
-
|
|
61
|
-
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${
|
|
57
|
+
let s = "E";
|
|
58
|
+
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
59
|
+
let o = t * 3600, i, r, c, a, d, u;
|
|
60
|
+
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = l.roundPrecision(c, e).toString().padStart(2, "0") : a = l.padNumber(c, 2, 2), o = o - c * 60), d = o / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(3, "0") : u = l.padNumber(d, 3, 2);
|
|
61
|
+
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
62
62
|
return {
|
|
63
|
-
direction:
|
|
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(i, e),
|
|
67
67
|
pretty: f
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -75,16 +75,16 @@ class l {
|
|
|
75
75
|
*/
|
|
76
76
|
static lat2pretty(t, e = 6, n = "H°M′") {
|
|
77
77
|
t = t % 180;
|
|
78
|
-
let
|
|
79
|
-
t < 0 && (
|
|
80
|
-
let o = t * 3600,
|
|
81
|
-
|
|
82
|
-
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${
|
|
78
|
+
let s = "N";
|
|
79
|
+
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
80
|
+
let o = t * 3600, i, r, c, a, d, u;
|
|
81
|
+
i = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - i, r = l.padNumber(i, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = l.roundPrecision(c, e).toString().padStart(2, "0") : a = l.padNumber(c, 2, 2), o = o - c * 60), d = o / 3600, n.indexOf("M") !== -1 ? u = l.roundPrecision(d, e).toString().padStart(2, "0") : u = l.padNumber(d, 2, 2);
|
|
82
|
+
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
83
83
|
return {
|
|
84
|
-
direction:
|
|
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(i, e),
|
|
88
88
|
pretty: f
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -92,15 +92,15 @@ class l {
|
|
|
92
92
|
let n;
|
|
93
93
|
if (isNaN(t)) {
|
|
94
94
|
t = l.strReplace(t, "LNG");
|
|
95
|
-
const
|
|
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 [i, r] = o;
|
|
99
|
+
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, i > 360 && !r) {
|
|
100
|
+
const c = this.roundPrecision(i / 100, 0);
|
|
101
|
+
r = i - c * 100, i = c;
|
|
102
102
|
}
|
|
103
|
-
n =
|
|
103
|
+
n = i + (r ?? 0) / 60, s === "W" && (n = n * -1);
|
|
104
104
|
} else
|
|
105
105
|
n = Number(t);
|
|
106
106
|
return l.convertToStdLng(n, e);
|
|
@@ -109,23 +109,23 @@ class l {
|
|
|
109
109
|
let n;
|
|
110
110
|
if (isNaN(t)) {
|
|
111
111
|
t = l.strReplace(t, "LAT");
|
|
112
|
-
const
|
|
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 [i, r] = o;
|
|
116
|
+
if (r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, i > 90 && !r) {
|
|
117
|
+
const c = this.roundPrecision(i / 100, 0);
|
|
118
|
+
r = i - c * 100, i = c;
|
|
119
119
|
}
|
|
120
|
-
n =
|
|
120
|
+
n = i + (r ?? 0) / 60, s === "S" && (n = n * -1);
|
|
121
121
|
} else
|
|
122
122
|
n = Number(t);
|
|
123
123
|
return l.roundPrecision(n, e);
|
|
124
124
|
}
|
|
125
125
|
static str2LngOrLat(t, e = 6, n = "LAT") {
|
|
126
126
|
t = l.strReplace(t, n);
|
|
127
|
-
const
|
|
128
|
-
return ["N", "S"].includes(
|
|
127
|
+
const s = t[t.length - 1].toUpperCase();
|
|
128
|
+
return ["N", "S"].includes(s) ? {
|
|
129
129
|
lat: l.str2Lat(t, e)
|
|
130
130
|
} : {
|
|
131
131
|
lng: l.str2Lng(t, e)
|
|
@@ -163,10 +163,10 @@ class l {
|
|
|
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
164
|
const n = t[t.length - 1].toUpperCase();
|
|
165
165
|
if (!["N", "S", "E", "W"].includes(n)) {
|
|
166
|
-
const
|
|
166
|
+
const s = t, o = Number(s.split(" ")[0]);
|
|
167
167
|
if (isNaN(o))
|
|
168
168
|
throw new Error(`invalid Lat/Lng: ${t}`);
|
|
169
|
-
o >= 90 ? t = `${
|
|
169
|
+
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"}`;
|
|
170
170
|
}
|
|
171
171
|
return t;
|
|
172
172
|
}
|
|
@@ -178,8 +178,8 @@ class l {
|
|
|
178
178
|
* @param dcmPrecision 小数位数
|
|
179
179
|
*/
|
|
180
180
|
static padNumber(t, e = 2, n = 2) {
|
|
181
|
-
const
|
|
182
|
-
return `${
|
|
181
|
+
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");
|
|
182
|
+
return `${s}.${o}`;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
class S {
|
|
@@ -191,13 +191,13 @@ class S {
|
|
|
191
191
|
* @param precision
|
|
192
192
|
* @returns {number} 单位度
|
|
193
193
|
*/
|
|
194
|
-
static calculateBearing(t, e, n = !0,
|
|
194
|
+
static calculateBearing(t, e, n = !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 n ?
|
|
199
|
+
let i;
|
|
200
|
+
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);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* 计算两点间距离
|
|
@@ -208,14 +208,14 @@ class S {
|
|
|
208
208
|
* @param units 单位,默认 nm(海里)
|
|
209
209
|
* @returns {number}
|
|
210
210
|
*/
|
|
211
|
-
static calculateDistance(t, e, n = !0,
|
|
212
|
-
t = { ...t }, e = { ...e }, t.lng = l.convertToStdLng(t.lng,
|
|
213
|
-
const
|
|
211
|
+
static calculateDistance(t, e, n = !0, s = 4, o = "nauticalmiles") {
|
|
212
|
+
t = { ...t }, e = { ...e }, t.lng = l.convertToStdLng(t.lng, s), e.lng = l.convertToStdLng(e.lng, s);
|
|
213
|
+
const i = g.points([
|
|
214
214
|
[t.lng, t.lat],
|
|
215
215
|
[e.lng, e.lat]
|
|
216
216
|
]);
|
|
217
217
|
let r;
|
|
218
|
-
return n ? r = g.rhumbDistance(
|
|
218
|
+
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);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* 计算航线距离
|
|
@@ -224,15 +224,15 @@ class S {
|
|
|
224
224
|
* @param units
|
|
225
225
|
*/
|
|
226
226
|
static calculateRouteDistance(t, e = 4, n = "nauticalmiles") {
|
|
227
|
-
let
|
|
228
|
-
for (const
|
|
229
|
-
for (let r = 0; r <
|
|
230
|
-
const c = { lng:
|
|
231
|
-
r === 0 && o && (
|
|
232
|
-
const a = { lng:
|
|
233
|
-
|
|
227
|
+
let s = 0, o;
|
|
228
|
+
for (const i of t)
|
|
229
|
+
for (let r = 0; r < i.length - 1; r++) {
|
|
230
|
+
const c = { lng: i[r][0], lat: i[r][1] };
|
|
231
|
+
r === 0 && o && (s += this.calculateDistance(o, c, !0, e, n));
|
|
232
|
+
const a = { lng: i[r + 1][0], lat: i[r + 1][1] };
|
|
233
|
+
s += this.calculateDistance(c, a, !0, e, n), o = a;
|
|
234
234
|
}
|
|
235
|
-
return l.roundPrecision(
|
|
235
|
+
return l.roundPrecision(s, e);
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* 计算坐标(基于方位角和距离)
|
|
@@ -242,10 +242,10 @@ class S {
|
|
|
242
242
|
* @param units 单位,默认 nm(海里)
|
|
243
243
|
* @param rhumb
|
|
244
244
|
*/
|
|
245
|
-
static calculateCoordinate(t, e, n,
|
|
246
|
-
const
|
|
245
|
+
static calculateCoordinate(t, e, n, s = "nauticalmiles", o = !0) {
|
|
246
|
+
const i = g.point([t.lng, t.lat]);
|
|
247
247
|
let r;
|
|
248
|
-
o ? r = g.rhumbDestination(
|
|
248
|
+
o ? r = g.rhumbDestination(i, n, e, { units: s }) : r = g.destination(i, n, 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 S {
|
|
|
258
258
|
* @param includeTail true 包含终点 to
|
|
259
259
|
* @param units 单位,默认 nm(海里)
|
|
260
260
|
*/
|
|
261
|
-
static interpolateCoordinates(t, e, n,
|
|
262
|
-
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8,
|
|
263
|
-
|
|
261
|
+
static interpolateCoordinates(t, e, n, s = !0, o = !0, i = "nauticalmiles") {
|
|
262
|
+
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, i);
|
|
263
|
+
s && r.push({ lng: t.lng, lat: t.lat });
|
|
264
264
|
let d = 0;
|
|
265
265
|
for (; d < a; )
|
|
266
|
-
d += n, d < a && r.push(this.calculateCoordinate(t, c, d,
|
|
266
|
+
d += n, d < a && r.push(this.calculateCoordinate(t, c, d, i, !1));
|
|
267
267
|
return o && r.push({ lng: e.lng, lat: e.lat }), r;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
@@ -282,15 +282,15 @@ class S {
|
|
|
282
282
|
return [];
|
|
283
283
|
t = this.deduplicateCoordinates(t);
|
|
284
284
|
let n = [];
|
|
285
|
-
const
|
|
286
|
-
let o,
|
|
285
|
+
const s = [];
|
|
286
|
+
let o, i;
|
|
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), i = l.convertToStdLng(t[r + 1].lng, 8), t[r].lat = l.roundPrecision(t[r].lat, 8), t[r + 1].lat = l.roundPrecision(t[r + 1].lat, 8), n.push([o, t[r].lat]);
|
|
289
|
+
const c = o - i;
|
|
290
290
|
if (Math.abs(c) > 180) {
|
|
291
291
|
const a = l.convertToMonotonicLng2([
|
|
292
292
|
[o, t[r].lat],
|
|
293
|
-
[
|
|
293
|
+
[i, t[r + 1].lat]
|
|
294
294
|
]);
|
|
295
295
|
let d, u;
|
|
296
296
|
e ? (d = g.lineString(a), u = g.lineString([
|
|
@@ -304,11 +304,11 @@ class S {
|
|
|
304
304
|
h = l.roundPrecision(C[1], 8);
|
|
305
305
|
} else
|
|
306
306
|
h = t[r].lat;
|
|
307
|
-
c > 0 ? (n.push([180 - 1e-6, h]),
|
|
307
|
+
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]));
|
|
308
308
|
}
|
|
309
|
-
r === t.length - 2 && n.push([
|
|
309
|
+
r === t.length - 2 && n.push([i, t[r + 1].lat]);
|
|
310
310
|
}
|
|
311
|
-
return
|
|
311
|
+
return s.push(n), s;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* 去除重复坐标
|
|
@@ -317,8 +317,8 @@ class S {
|
|
|
317
317
|
static deduplicateRoute(t) {
|
|
318
318
|
const e = [];
|
|
319
319
|
for (const n of t) {
|
|
320
|
-
const
|
|
321
|
-
e.push(
|
|
320
|
+
const s = n.reduce((o, i) => (o.findIndex((r) => r[0] === i[0] && r[1] === i[1]) === -1 && o.push(i), o), []);
|
|
321
|
+
e.push(s);
|
|
322
322
|
}
|
|
323
323
|
return e;
|
|
324
324
|
}
|
|
@@ -327,7 +327,7 @@ class S {
|
|
|
327
327
|
* @param coordinates
|
|
328
328
|
*/
|
|
329
329
|
static deduplicateCoordinates(t) {
|
|
330
|
-
return t.reduce((e, n) => (e.findIndex((
|
|
330
|
+
return t.reduce((e, n) => (e.findIndex((s) => s.lat === n.lat && s.lng === n.lng) === -1 && e.push(n), e), []);
|
|
331
331
|
}
|
|
332
332
|
/**
|
|
333
333
|
* 移出坐标
|
|
@@ -337,8 +337,8 @@ class S {
|
|
|
337
337
|
static removeCoordinateFromRoute(t, e) {
|
|
338
338
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
339
339
|
for (const n of e)
|
|
340
|
-
for (let
|
|
341
|
-
l.roundPrecision(n[
|
|
340
|
+
for (let s = n.length - 1; s >= 0; s--)
|
|
341
|
+
l.roundPrecision(n[s][0], 8) === t.lng && l.roundPrecision(n[s][1], 8) === l.roundPrecision(t.lat, 8) && n.splice(s, 1);
|
|
342
342
|
return e;
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
@@ -365,13 +365,13 @@ class S {
|
|
|
365
365
|
*/
|
|
366
366
|
static mergeCoordinateToRoute(t, e) {
|
|
367
367
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
368
|
-
let n = Number.MAX_VALUE,
|
|
368
|
+
let n = Number.MAX_VALUE, s = 0, o = 0, i, 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
|
-
n > h && (n = h, o = d,
|
|
372
|
+
n > h && (n = h, o = d, s = a, i = this.calculateDistance(u, t), r = this.calculateDistance(f, t));
|
|
373
373
|
}
|
|
374
|
-
}),
|
|
374
|
+
}), i !== 0 && r !== 0 ? e[s].splice(o + 1, 0, [t.lng, t.lat]) : i === 0 ? e[s].splice(o, 1, [t.lng, t.lat]) : r === 0 && e[s].splice(o + 1, 1, [t.lng, t.lat]), e;
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
377
377
|
* 向Route尾加1个坐标
|
|
@@ -411,21 +411,21 @@ class S {
|
|
|
411
411
|
*/
|
|
412
412
|
static calculateRangeRoute(t, e, n) {
|
|
413
413
|
n = this.mergeWaypointsToRoute([t, e], n);
|
|
414
|
-
const
|
|
414
|
+
const s = [];
|
|
415
415
|
let o = 0;
|
|
416
|
-
return n.forEach((
|
|
416
|
+
return n.forEach((i) => {
|
|
417
417
|
if (o === 2)
|
|
418
418
|
return;
|
|
419
419
|
const r = [];
|
|
420
|
-
for (const c of
|
|
420
|
+
for (const c of i) {
|
|
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;
|
|
424
424
|
}
|
|
425
425
|
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));
|
|
426
426
|
}
|
|
427
|
-
r.length &&
|
|
428
|
-
}),
|
|
427
|
+
r.length && s.push(r);
|
|
428
|
+
}), s;
|
|
429
429
|
}
|
|
430
430
|
/**
|
|
431
431
|
* 计算from到to之间的航线
|
|
@@ -435,13 +435,13 @@ class S {
|
|
|
435
435
|
* @param waypoints
|
|
436
436
|
* @return [{lng, lat}]
|
|
437
437
|
*/
|
|
438
|
-
static calculateRangeWaypoints(t, e, n,
|
|
439
|
-
const o = this.convertRouteToCoordinates(n, 0),
|
|
438
|
+
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
439
|
+
const o = this.convertRouteToCoordinates(n, 0), i = this.mergeCoordinatesToWaypoints([t, e, ...s], o), r = i.findIndex(
|
|
440
440
|
(d) => l.roundPrecision(t.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(t.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
441
|
-
), c =
|
|
441
|
+
), c = i.findIndex(
|
|
442
442
|
(d) => l.roundPrecision(e.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
443
443
|
);
|
|
444
|
-
return
|
|
444
|
+
return i.filter((d, u) => u >= r && u <= c);
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
447
|
* 计算坐标到航路上的最短距离
|
|
@@ -449,13 +449,13 @@ class S {
|
|
|
449
449
|
* @param route
|
|
450
450
|
*/
|
|
451
451
|
static calculateMinDistanceToRoute(t, e) {
|
|
452
|
-
let n = Number.MAX_VALUE,
|
|
453
|
-
return e.forEach((
|
|
454
|
-
for (let c = 0; c <
|
|
455
|
-
const a = { lng:
|
|
456
|
-
n > u && (n = u,
|
|
452
|
+
let n = Number.MAX_VALUE, s = 0, o = 0;
|
|
453
|
+
return e.forEach((i, r) => {
|
|
454
|
+
for (let c = 0; c < i.length - 1; c++) {
|
|
455
|
+
const a = { lng: i[c][0], lat: i[c][1] }, d = { lng: i[c + 1][0], lat: i[c + 1][1] }, u = this.calculatePointToLineDistance(t, a, d);
|
|
456
|
+
n > u && (n = u, s = c, o = r);
|
|
457
457
|
}
|
|
458
|
-
}), { minDist: n, segIndex: o, minIndex:
|
|
458
|
+
}), { minDist: n, segIndex: o, minIndex: s };
|
|
459
459
|
}
|
|
460
460
|
/**
|
|
461
461
|
* 计算子航线
|
|
@@ -464,17 +464,17 @@ class S {
|
|
|
464
464
|
* @return [[[lng, lat]]]
|
|
465
465
|
*/
|
|
466
466
|
static calculateSubRoute(t, e) {
|
|
467
|
-
const { segIndex: n, minIndex:
|
|
467
|
+
const { segIndex: n, minIndex: s } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
468
468
|
t.lng = l.convertToStdLng(t.lng);
|
|
469
469
|
const o = [];
|
|
470
|
-
let
|
|
470
|
+
let i = !0;
|
|
471
471
|
for (let r = n; r < e.length; r++)
|
|
472
|
-
if (
|
|
472
|
+
if (i) {
|
|
473
473
|
const c = [];
|
|
474
474
|
c.push([t.lng, t.lat]);
|
|
475
|
-
for (let a =
|
|
475
|
+
for (let a = s + 1; a < e[r].length; a++)
|
|
476
476
|
t.lng === e[r][a][0] && t.lat === e[r][a][1] || c.push(e[r][a]);
|
|
477
|
-
o.push(c),
|
|
477
|
+
o.push(c), i = !1;
|
|
478
478
|
} else
|
|
479
479
|
o.push([...e[r]]);
|
|
480
480
|
return o;
|
|
@@ -486,20 +486,20 @@ class S {
|
|
|
486
486
|
* @return [{lng, lat}]
|
|
487
487
|
*/
|
|
488
488
|
static calculateSubWaypoints(t, e) {
|
|
489
|
-
let n = Number.MAX_VALUE,
|
|
490
|
-
for (let
|
|
491
|
-
const r = e[
|
|
489
|
+
let n = Number.MAX_VALUE, s = 0;
|
|
490
|
+
for (let i = 0; i < e.length - 1; i++) {
|
|
491
|
+
const r = e[i], c = e[i + 1];
|
|
492
492
|
if (this.calculateDistance(t, r) === 0)
|
|
493
493
|
return e;
|
|
494
494
|
if (this.calculateDistance(t, c) === 0)
|
|
495
495
|
return e.filter((d, u) => u > 0);
|
|
496
496
|
const a = this.calculatePointToLineDistance(t, r, c);
|
|
497
|
-
n > a && (n = a,
|
|
497
|
+
n > a && (n = a, s = i);
|
|
498
498
|
}
|
|
499
499
|
t.lng = l.convertToStdLng(t.lng);
|
|
500
500
|
const o = [t];
|
|
501
|
-
for (let
|
|
502
|
-
o.push(e[
|
|
501
|
+
for (let i = s + 1; i < e.length; i++)
|
|
502
|
+
o.push(e[i]);
|
|
503
503
|
return o;
|
|
504
504
|
}
|
|
505
505
|
/**
|
|
@@ -509,14 +509,14 @@ class S {
|
|
|
509
509
|
* @param to { lng, lat }
|
|
510
510
|
* @param options
|
|
511
511
|
*/
|
|
512
|
-
static calculatePointToLineDistance(t, e, n,
|
|
512
|
+
static calculatePointToLineDistance(t, e, n, s = { units: "nauticalmiles", method: "geodesic" }) {
|
|
513
513
|
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);
|
|
514
514
|
const o = l.convertToMonotonicLng([e, n]);
|
|
515
515
|
e = o[0], n = o[1];
|
|
516
|
-
const
|
|
516
|
+
const i = g.lineString([
|
|
517
517
|
[e.lng, e.lat],
|
|
518
518
|
[n.lng, n.lat]
|
|
519
|
-
]), r = g.pointToLineDistance(g.point([t.lng, t.lat]),
|
|
519
|
+
]), 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);
|
|
520
520
|
return l.roundPrecision(Math.min(r, c), 6);
|
|
521
521
|
}
|
|
522
522
|
/**
|
|
@@ -527,8 +527,8 @@ class S {
|
|
|
527
527
|
static calculateWaypointsPropInRoute(t, e) {
|
|
528
528
|
e = this.mergeWaypointsToRoute(t, e);
|
|
529
529
|
for (let n = 0; n < t.length - 1; n++) {
|
|
530
|
-
const
|
|
531
|
-
n === 0 && (
|
|
530
|
+
const s = t[n], o = t[n + 1], i = this.calculateRangeRoute(s, o, e);
|
|
531
|
+
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(i), o.distanceFromStart = l.roundPrecision((s.distanceFromStart || 0) + o.distanceFromPrevious);
|
|
532
532
|
}
|
|
533
533
|
return t;
|
|
534
534
|
}
|
|
@@ -538,8 +538,8 @@ class S {
|
|
|
538
538
|
* @param replace true replace the same waypoint with coordinate
|
|
539
539
|
*/
|
|
540
540
|
static mergeCoordinatesToWaypoints(t, e, n = !0) {
|
|
541
|
-
for (const
|
|
542
|
-
this.mergeCoordinateToWaypoints(
|
|
541
|
+
for (const s of t)
|
|
542
|
+
this.mergeCoordinateToWaypoints(s, e, n);
|
|
543
543
|
return e;
|
|
544
544
|
}
|
|
545
545
|
/**
|
|
@@ -556,12 +556,12 @@ class S {
|
|
|
556
556
|
*/
|
|
557
557
|
static mergeCoordinateToWaypoints(t, e, n = !0) {
|
|
558
558
|
t.lng = l.convertToStdLng(t.lng, 8);
|
|
559
|
-
let
|
|
559
|
+
let s = Number.MAX_VALUE, o = 0, i = 0, r = 0;
|
|
560
560
|
for (let c = 0; c < e.length - 1; c++) {
|
|
561
561
|
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);
|
|
562
|
-
|
|
562
|
+
s >= u && (s = u, o = c, i = this.calculateDistance(a, t, !1, 6), r = this.calculateDistance(d, t, !1, 6));
|
|
563
563
|
}
|
|
564
|
-
return
|
|
564
|
+
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));
|
|
565
565
|
}
|
|
566
566
|
/**
|
|
567
567
|
* 生成航线(基于途经点生成大圆/横向航线,并根据是否跨180度分组)
|
|
@@ -571,10 +571,10 @@ class S {
|
|
|
571
571
|
static generateRouteAccordingToWaypoints(t) {
|
|
572
572
|
const e = [];
|
|
573
573
|
for (let n = 1; n < t.length; n++) {
|
|
574
|
-
const
|
|
575
|
-
if (n === 1 && e.push(
|
|
576
|
-
const
|
|
577
|
-
e.push(...
|
|
574
|
+
const s = t[n - 1], o = t[n];
|
|
575
|
+
if (n === 1 && e.push(s), o.gcToPrevious) {
|
|
576
|
+
const i = this.interpolateCoordinates(s, o, 200, !1, !0, "nauticalmiles");
|
|
577
|
+
e.push(...i);
|
|
578
578
|
} else
|
|
579
579
|
e.push(o);
|
|
580
580
|
}
|
|
@@ -586,13 +586,8 @@ class S {
|
|
|
586
586
|
* @param route [[[lng, lat]]]
|
|
587
587
|
*/
|
|
588
588
|
static nearestCoordinateInRoute(t, e) {
|
|
589
|
-
const n = g.point([t.lng, t.lat]),
|
|
590
|
-
|
|
591
|
-
const a = c.map((d) => g.point(d));
|
|
592
|
-
i.push(...a);
|
|
593
|
-
}
|
|
594
|
-
const o = g.featureCollection(i), s = g.nearestPoint(n, o), r = g.getCoord(s);
|
|
595
|
-
return { lng: r[0], lat: r[1] };
|
|
589
|
+
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);
|
|
590
|
+
return { lng: l.roundPrecision(c[0], 8), lat: l.roundPrecision(c[1], 8) };
|
|
596
591
|
}
|
|
597
592
|
/**
|
|
598
593
|
* 计算经过方向上的最后一个waypoint
|
|
@@ -602,14 +597,14 @@ class S {
|
|
|
602
597
|
static calculatePrevWaypoint(t, e) {
|
|
603
598
|
let n = 0;
|
|
604
599
|
this.mergeCoordinateToWaypoints(t, e);
|
|
605
|
-
for (let
|
|
606
|
-
const o = e[
|
|
600
|
+
for (let s = 0; s < e.length - 1; s++) {
|
|
601
|
+
const o = e[s], i = e[s + 1];
|
|
607
602
|
if (this.calculateDistance(t, o) === 0) {
|
|
608
|
-
n =
|
|
603
|
+
n = s;
|
|
609
604
|
break;
|
|
610
605
|
}
|
|
611
|
-
if (this.calculateDistance(t,
|
|
612
|
-
n =
|
|
606
|
+
if (this.calculateDistance(t, i) === 0) {
|
|
607
|
+
n = s + 1;
|
|
613
608
|
break;
|
|
614
609
|
}
|
|
615
610
|
}
|
|
@@ -623,11 +618,11 @@ class S {
|
|
|
623
618
|
* @param units
|
|
624
619
|
* @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
|
|
625
620
|
*/
|
|
626
|
-
static calculateNextCoordinateAlongRoute(t, e, n,
|
|
621
|
+
static calculateNextCoordinateAlongRoute(t, e, n, s = "nauticalmiles") {
|
|
627
622
|
var f;
|
|
628
|
-
const o = t.speed || 12,
|
|
623
|
+
const o = t.speed || 12, i = [];
|
|
629
624
|
let r = [], c = !1, a = 0, d = 0, u;
|
|
630
|
-
if (e && n.length ? (
|
|
625
|
+
if (e && n.length ? (i.push(t), n.forEach((h, C) => {
|
|
631
626
|
if (c)
|
|
632
627
|
r.push(h);
|
|
633
628
|
else {
|
|
@@ -638,15 +633,15 @@ class S {
|
|
|
638
633
|
m.push(h[M]);
|
|
639
634
|
else {
|
|
640
635
|
P = { lng: h[M][0], lat: h[M][1] };
|
|
641
|
-
const b = this.calculateDistance(t, P, !0, 8,
|
|
636
|
+
const b = this.calculateDistance(t, P, !0, 8, s);
|
|
642
637
|
if (a += b, a < e)
|
|
643
|
-
d += b,
|
|
638
|
+
d += b, i.push(P), t = P;
|
|
644
639
|
else {
|
|
645
640
|
if (d = e, a === e)
|
|
646
641
|
u = P, m.push([u.lng, u.lat]);
|
|
647
642
|
else {
|
|
648
643
|
const p = a - e, N = this.calculateBearing(P, t);
|
|
649
|
-
u = this.calculateCoordinate(P, N, p,
|
|
644
|
+
u = this.calculateCoordinate(P, N, p, s), m.push([u.lng, u.lat]), m.push([P.lng, P.lat]);
|
|
650
645
|
}
|
|
651
646
|
c = !0;
|
|
652
647
|
}
|
|
@@ -654,12 +649,12 @@ class S {
|
|
|
654
649
|
m.length && r.push(m), C === n.length - 1 && !u && (u = P);
|
|
655
650
|
}
|
|
656
651
|
})) : (r = n, u = { ...t }), u)
|
|
657
|
-
if (
|
|
652
|
+
if (i.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / o * 1e4) / 1e4, ((f = r[0]) == null ? void 0 : f.length) > 1) {
|
|
658
653
|
const h = { lng: r[0][1][0], lat: r[0][1][1] };
|
|
659
654
|
u.bearing = this.calculateBearing(u, h);
|
|
660
655
|
} else
|
|
661
656
|
u.bearing = 0;
|
|
662
|
-
return { coordinate: u, nextRoute: r, prevRoute:
|
|
657
|
+
return { coordinate: u, nextRoute: r, prevRoute: i };
|
|
663
658
|
}
|
|
664
659
|
/**
|
|
665
660
|
* 返回最近点及其是否为垂足(最近点不是起点或终点)
|
|
@@ -668,11 +663,11 @@ class S {
|
|
|
668
663
|
* @param to {lng, lat}
|
|
669
664
|
*/
|
|
670
665
|
static nearestCoordinateInLine(t, e, n) {
|
|
671
|
-
const
|
|
672
|
-
[
|
|
666
|
+
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([
|
|
667
|
+
[i, e.lat],
|
|
673
668
|
[r, n.lat]
|
|
674
669
|
]), a = g.nearestPointOnLine(c, o), d = g.getCoord(a), u = l.roundPrecision(d[0], 6), f = l.roundPrecision(d[1], 6);
|
|
675
|
-
return { lng: u, lat: f, inline: !(u ===
|
|
670
|
+
return { lng: u, lat: f, inline: !(u === i && f === e.lat) && !(u === r && f === n.lat) };
|
|
676
671
|
}
|
|
677
672
|
/**
|
|
678
673
|
* 将route转coordinate
|
|
@@ -681,21 +676,21 @@ class S {
|
|
|
681
676
|
*/
|
|
682
677
|
static convertRouteToCoordinates(t, e = 0) {
|
|
683
678
|
const n = [];
|
|
684
|
-
let
|
|
685
|
-
return t.forEach((
|
|
686
|
-
|
|
679
|
+
let s, o;
|
|
680
|
+
return t.forEach((i) => {
|
|
681
|
+
i.forEach((r) => {
|
|
687
682
|
const c = { lng: l.roundPrecision(r[0], 8), lat: l.roundPrecision(r[1], 8) };
|
|
688
683
|
if (!o)
|
|
689
684
|
n.push(c), o = c;
|
|
690
685
|
else if (o.bearing === void 0)
|
|
691
686
|
o.bearing = this.calculateBearing(o, c, !0);
|
|
692
687
|
else {
|
|
693
|
-
const a = this.calculateDistance(
|
|
694
|
-
a && a >= e && (
|
|
688
|
+
const a = this.calculateDistance(s, c, !0);
|
|
689
|
+
a && a >= e && (s.bearing = this.calculateBearing(s, c, !0), n.push(s), o = s);
|
|
695
690
|
}
|
|
696
|
-
|
|
691
|
+
s = c;
|
|
697
692
|
});
|
|
698
|
-
}),
|
|
693
|
+
}), s && n.push(s), n;
|
|
699
694
|
}
|
|
700
695
|
/**
|
|
701
696
|
* 抽稀(基于转向点)
|
|
@@ -704,8 +699,8 @@ class S {
|
|
|
704
699
|
* @param distance
|
|
705
700
|
*/
|
|
706
701
|
static simplifyRouteToCoordinates(t, e, n = 1) {
|
|
707
|
-
let
|
|
708
|
-
return
|
|
702
|
+
let s = this.convertRouteToCoordinates(t, n);
|
|
703
|
+
return s = this.simplifyGCCoordinates(s, e), s;
|
|
709
704
|
}
|
|
710
705
|
/**
|
|
711
706
|
* 基于大圆标识抽稀
|
|
@@ -713,23 +708,23 @@ class S {
|
|
|
713
708
|
* @param waypoints
|
|
714
709
|
*/
|
|
715
710
|
static simplifyGCCoordinates(t, e) {
|
|
716
|
-
e.forEach((
|
|
717
|
-
this.mergeCoordinateToWaypoints(
|
|
711
|
+
e.forEach((s) => {
|
|
712
|
+
this.mergeCoordinateToWaypoints(s, t, !0);
|
|
718
713
|
});
|
|
719
|
-
for (let
|
|
720
|
-
const o = e[
|
|
721
|
-
if (
|
|
722
|
-
const r = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng ===
|
|
714
|
+
for (let s = 1; s < e.length; s++) {
|
|
715
|
+
const o = e[s - 1], i = e[s];
|
|
716
|
+
if (i.gcToPrevious) {
|
|
717
|
+
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);
|
|
723
718
|
for (let a = c - 1; a > r; a--)
|
|
724
719
|
t.splice(a, 1);
|
|
725
720
|
}
|
|
726
721
|
}
|
|
727
722
|
let n = 0;
|
|
728
|
-
for (let
|
|
729
|
-
const o = t[
|
|
730
|
-
|
|
723
|
+
for (let s = 1; s < t.length; s++) {
|
|
724
|
+
const o = t[s - 1], i = t[s];
|
|
725
|
+
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;
|
|
731
726
|
}
|
|
732
|
-
return t.map((
|
|
727
|
+
return t.map((s) => (s.lng = l.convertToStdLng(s.lng), s));
|
|
733
728
|
}
|
|
734
729
|
/**
|
|
735
730
|
* 计算轨迹中心点
|
|
@@ -740,11 +735,11 @@ class S {
|
|
|
740
735
|
for (const r of t)
|
|
741
736
|
for (const c of r)
|
|
742
737
|
e.push(c);
|
|
743
|
-
const n = g.featureCollection([]),
|
|
744
|
-
for (const r of
|
|
738
|
+
const n = g.featureCollection([]), s = l.convertToMonotonicLng2(e);
|
|
739
|
+
for (const r of s)
|
|
745
740
|
n.features.push(g.point(r));
|
|
746
|
-
const
|
|
747
|
-
return { lng: l.convertToStdLng(
|
|
741
|
+
const i = g.center(n).geometry.coordinates;
|
|
742
|
+
return { lng: l.convertToStdLng(i[0], 8), lat: l.roundPrecision(i[1], 8) };
|
|
748
743
|
}
|
|
749
744
|
/**
|
|
750
745
|
* 计算中心点
|
|
@@ -761,10 +756,10 @@ class S {
|
|
|
761
756
|
static calculateBBox(t) {
|
|
762
757
|
const e = [];
|
|
763
758
|
for (const o of t)
|
|
764
|
-
for (const
|
|
765
|
-
e.push(
|
|
766
|
-
const n = l.convertToMonotonicLng2(e),
|
|
767
|
-
return g.bbox(
|
|
759
|
+
for (const i of o)
|
|
760
|
+
e.push(i);
|
|
761
|
+
const n = l.convertToMonotonicLng2(e), s = g.lineString(n);
|
|
762
|
+
return g.bbox(s);
|
|
768
763
|
}
|
|
769
764
|
/**
|
|
770
765
|
* 计算BBox
|
|
@@ -777,7 +772,7 @@ class S {
|
|
|
777
772
|
}
|
|
778
773
|
let T;
|
|
779
774
|
try {
|
|
780
|
-
T =
|
|
775
|
+
T = F.getLogger("vessel");
|
|
781
776
|
} catch {
|
|
782
777
|
} finally {
|
|
783
778
|
}
|
|
@@ -789,15 +784,15 @@ class U {
|
|
|
789
784
|
static convert2Geojson(t) {
|
|
790
785
|
var n;
|
|
791
786
|
const e = g.featureCollection([]);
|
|
792
|
-
for (const
|
|
793
|
-
if (
|
|
794
|
-
const o = (n =
|
|
795
|
-
for (const
|
|
796
|
-
const r = [], c = D(
|
|
787
|
+
for (const s of t) {
|
|
788
|
+
if (s.forecasts) {
|
|
789
|
+
const o = (n = s.history) == null ? void 0 : n[0];
|
|
790
|
+
for (const i of s.forecasts) {
|
|
791
|
+
const r = [], c = D(i.date).utc(), a = `${s.name}-${i.model}`;
|
|
797
792
|
if (o) {
|
|
798
793
|
const d = D(o.updated).utc(), u = g.point([o.lng, o.lat], {
|
|
799
|
-
model:
|
|
800
|
-
name:
|
|
794
|
+
model: i.model,
|
|
795
|
+
name: s.name,
|
|
801
796
|
date: d.format(),
|
|
802
797
|
hour: 0,
|
|
803
798
|
format: d.format("MMM-DD/HHmm[Z]"),
|
|
@@ -808,12 +803,12 @@ class U {
|
|
|
808
803
|
});
|
|
809
804
|
e.features.push(u), r.push(u.geometry.coordinates);
|
|
810
805
|
}
|
|
811
|
-
for (const d in
|
|
812
|
-
const u =
|
|
806
|
+
for (const d in i == null ? void 0 : i.hours) {
|
|
807
|
+
const u = i.hours[d];
|
|
813
808
|
u.wind.spd = u.wind.spd || u.wind.speed;
|
|
814
809
|
const f = c.clone().add(Number(d), "hour"), h = g.point([u.lng, u.lat], {
|
|
815
|
-
model:
|
|
816
|
-
name:
|
|
810
|
+
model: i.model,
|
|
811
|
+
name: s.name,
|
|
817
812
|
date: f.format(),
|
|
818
813
|
hour: Number(d),
|
|
819
814
|
format: f.format("MMM-DD/HHmm[Z]"),
|
|
@@ -828,10 +823,10 @@ class U {
|
|
|
828
823
|
}
|
|
829
824
|
if ((r == null ? void 0 : r.length) > 1) {
|
|
830
825
|
const d = g.lineString(l.convertToMonotonicLng2(r), {
|
|
831
|
-
date:
|
|
832
|
-
id:
|
|
833
|
-
model:
|
|
834
|
-
name:
|
|
826
|
+
date: i.date,
|
|
827
|
+
id: s.id || s.name,
|
|
828
|
+
model: i.model,
|
|
829
|
+
name: s.name,
|
|
835
830
|
category: a,
|
|
836
831
|
type: "forecast"
|
|
837
832
|
});
|
|
@@ -839,11 +834,11 @@ class U {
|
|
|
839
834
|
}
|
|
840
835
|
}
|
|
841
836
|
}
|
|
842
|
-
if (
|
|
837
|
+
if (s.history) {
|
|
843
838
|
const o = [];
|
|
844
|
-
for (const r of
|
|
839
|
+
for (const r of s.history) {
|
|
845
840
|
const c = D(r.updated).utc(), a = g.point([r.lng, r.lat], {
|
|
846
|
-
name:
|
|
841
|
+
name: s.name,
|
|
847
842
|
date: c.format(),
|
|
848
843
|
format: c.format("MMM-DD/HHmm[Z]"),
|
|
849
844
|
pressure: r.pressure > 1e4 ? l.roundPrecision(r.pressure / 100, 0) : l.roundPrecision(r.pressure, 0),
|
|
@@ -852,21 +847,21 @@ class U {
|
|
|
852
847
|
source: r.source,
|
|
853
848
|
level: r.type,
|
|
854
849
|
type: "history",
|
|
855
|
-
category: `${
|
|
850
|
+
category: `${s.name}-history`
|
|
856
851
|
});
|
|
857
852
|
e.features.push(a), o.push(a.geometry.coordinates);
|
|
858
853
|
}
|
|
859
|
-
const
|
|
854
|
+
const i = s.history[0];
|
|
860
855
|
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
861
856
|
const r = g.lineString(l.convertToMonotonicLng2(o), {
|
|
862
|
-
name:
|
|
857
|
+
name: s.name,
|
|
863
858
|
type: "history",
|
|
864
|
-
updated:
|
|
865
|
-
pressure: (
|
|
866
|
-
spd: (
|
|
867
|
-
kts:
|
|
868
|
-
source:
|
|
869
|
-
level:
|
|
859
|
+
updated: i == null ? void 0 : i.updated,
|
|
860
|
+
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),
|
|
861
|
+
spd: (i == null ? void 0 : i.speed) || (i == null ? void 0 : i.spd),
|
|
862
|
+
kts: i == null ? void 0 : i.kts,
|
|
863
|
+
source: i == null ? void 0 : i.source,
|
|
864
|
+
level: i == null ? void 0 : i.type
|
|
870
865
|
});
|
|
871
866
|
e.features.push(r);
|
|
872
867
|
}
|
|
@@ -880,12 +875,12 @@ class U {
|
|
|
880
875
|
* @param step
|
|
881
876
|
*/
|
|
882
877
|
static interpolate(t, e = 3) {
|
|
883
|
-
var o,
|
|
884
|
-
const n = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"),
|
|
878
|
+
var o, i, r, c;
|
|
879
|
+
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 = [];
|
|
885
880
|
for (const a of n) {
|
|
886
881
|
const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = D(a.properties.date).utc();
|
|
887
882
|
let C = e * 60 - (h.get("hour") * 60 + h.get("minute")) % (e * 60);
|
|
888
|
-
const m = (
|
|
883
|
+
const m = (i = t == null ? void 0 : t.data) == null ? void 0 : i.features.filter(
|
|
889
884
|
(b) => b.geometry.type === "Point" && b.properties.type === "forecast" && b.properties.category === `${d}-${u}`
|
|
890
885
|
);
|
|
891
886
|
let P, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
@@ -905,12 +900,12 @@ class U {
|
|
|
905
900
|
type: "forecast",
|
|
906
901
|
showCircle: f
|
|
907
902
|
});
|
|
908
|
-
|
|
903
|
+
s.push($);
|
|
909
904
|
}
|
|
910
905
|
C += e * 60, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
911
906
|
}
|
|
912
907
|
}
|
|
913
|
-
return
|
|
908
|
+
return s;
|
|
914
909
|
}
|
|
915
910
|
/**
|
|
916
911
|
* 计算最佳绕航点
|
|
@@ -923,22 +918,22 @@ class U {
|
|
|
923
918
|
* @param speed 前进速度
|
|
924
919
|
* @param options
|
|
925
920
|
*/
|
|
926
|
-
static diversionPassageAt(t, e, n,
|
|
927
|
-
const { t1: o, t2:
|
|
928
|
-
if (o &&
|
|
929
|
-
const a = S.calculateBearing(t, o), d = S.calculateBearing(o,
|
|
921
|
+
static diversionPassageAt(t, e, n, s = {}) {
|
|
922
|
+
const { t1: o, t2: i, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
923
|
+
if (o && i) {
|
|
924
|
+
const a = S.calculateBearing(t, o), d = S.calculateBearing(o, i), u = Math.abs(a - d);
|
|
930
925
|
let f = 0;
|
|
931
926
|
u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
|
|
932
927
|
const h = S.calculateCoordinate(o, f, n);
|
|
933
|
-
return T == null || T.info("[%s] the right tangent position: %j",
|
|
928
|
+
return T == null || T.info("[%s] the right tangent position: %j", s.requestId, {
|
|
934
929
|
from: t,
|
|
935
930
|
t1: o,
|
|
936
|
-
t2:
|
|
931
|
+
t2: i,
|
|
937
932
|
radius: n,
|
|
938
933
|
bearing1: a,
|
|
939
934
|
bearing2: d,
|
|
940
935
|
right: h
|
|
941
|
-
}), { at: h, t1: o, t2:
|
|
936
|
+
}), { at: h, t1: o, t2: i, hr: Number(r), hours: c };
|
|
942
937
|
}
|
|
943
938
|
return {};
|
|
944
939
|
}
|
|
@@ -952,13 +947,13 @@ class U {
|
|
|
952
947
|
* @param radius 与台风中心的距离
|
|
953
948
|
* @param options
|
|
954
949
|
*/
|
|
955
|
-
static driftPassageAt(t, e, n,
|
|
956
|
-
const { t1: o, t2:
|
|
957
|
-
if (o &&
|
|
958
|
-
const a = S.calculateBearing(t, o), d = S.calculateBearing(o,
|
|
959
|
-
return { at: S.calculateCoordinate(o, a - d + 180, n < u ? n : u), t1: o, t2:
|
|
950
|
+
static driftPassageAt(t, e, n, s = {}) {
|
|
951
|
+
const { t1: o, t2: i, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
952
|
+
if (o && i) {
|
|
953
|
+
const a = S.calculateBearing(t, o), d = S.calculateBearing(o, i), u = S.calculateDistance(t, o);
|
|
954
|
+
return { at: S.calculateCoordinate(o, a - d + 180, n < u ? n : u), t1: o, t2: i, hr: Number(r), hours: c };
|
|
960
955
|
} else
|
|
961
|
-
return T == null || T.info("[%s] no need drift: %j",
|
|
956
|
+
return T == null || T.info("[%s] no need drift: %j", s.requestId, { from: t, t1: o, t2: i, hr: r }), {};
|
|
962
957
|
}
|
|
963
958
|
/**
|
|
964
959
|
* 获取台风中心点对
|
|
@@ -969,25 +964,25 @@ class U {
|
|
|
969
964
|
*/
|
|
970
965
|
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
971
966
|
var d, u, f, h, C;
|
|
972
|
-
let
|
|
967
|
+
let s = {};
|
|
973
968
|
(d = t.forecasts) == null || d.forEach((m) => {
|
|
974
|
-
|
|
969
|
+
s = { ...m.hours, ...s };
|
|
975
970
|
});
|
|
976
|
-
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (
|
|
971
|
+
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]]);
|
|
977
972
|
T == null || T.info("[%s] the first tropical center: %j", n.requestId, o);
|
|
978
|
-
let
|
|
979
|
-
|
|
980
|
-
const r =
|
|
981
|
-
T == null || T.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r,
|
|
982
|
-
const c = Object.keys(
|
|
973
|
+
let i = (h = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
|
|
974
|
+
i || (i = (C = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : C.at(-1));
|
|
975
|
+
const r = s == null ? void 0 : s[i || -1];
|
|
976
|
+
T == null || T.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, i);
|
|
977
|
+
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(i)), a = { 0: o };
|
|
983
978
|
for (const m of c)
|
|
984
|
-
a[m] =
|
|
985
|
-
return { t1: o, t2: r, hr:
|
|
979
|
+
a[m] = s[m];
|
|
980
|
+
return { t1: o, t2: r, hr: i, hours: a };
|
|
986
981
|
}
|
|
987
982
|
static pickIndex(t, e) {
|
|
988
983
|
let n = 0;
|
|
989
|
-
for (const
|
|
990
|
-
if (D(
|
|
984
|
+
for (const s of t) {
|
|
985
|
+
if (D(s.properties.date).isAfter(e))
|
|
991
986
|
return n === 0 ? -1 : n;
|
|
992
987
|
n++;
|
|
993
988
|
}
|
|
@@ -997,10 +992,10 @@ class U {
|
|
|
997
992
|
if (t)
|
|
998
993
|
if (e) {
|
|
999
994
|
if (isNaN(t) && isNaN(e) && typeof t != "string" && typeof e != "string") {
|
|
1000
|
-
const
|
|
995
|
+
const s = {};
|
|
1001
996
|
for (const o in t)
|
|
1002
|
-
|
|
1003
|
-
return
|
|
997
|
+
s[o] = this.computeNumber(t[o], e[o], n);
|
|
998
|
+
return s;
|
|
1004
999
|
}
|
|
1005
1000
|
return Math.round((t + (e - t) * n) * 100) / 100;
|
|
1006
1001
|
} else
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,R){typeof exports=="object"&&typeof module<"u"?R(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"],R):(C=typeof globalThis<"u"?globalThis:C||self,R(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,R,y,B,$){"use strict";function k(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const g=k(R);function j(b){return b&&b.__esModule&&Object.prototype.hasOwnProperty.call(b,"default")?b.default:b}class x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(b=>{x.prototype[b.toLowerCase()]=()=>{},x.prototype[`is${b}Enabled`]=()=>!1});const I=(()=>{try{return require("log4js")}catch{return null}})();var L={getLogger:I?I.getLogger:()=>new x};const O=j(L);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),o=y().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;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,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;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,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,s=Number(o.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${o}E`:s<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${s>0?"E":"W"}`:e=`${o}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${s}`}}class v{static calculateBearing(e,t,n=!0,o=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(s.features[0],s.features[1]):i=g.bearing(s.features[0],s.features[1]),i<0&&(i+=360),l.roundPrecision(i,o)}static calculateDistance(e,t,n=!0,o=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:s}):r=g.distance(i.features[0],i.features[1],{units:s}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,s;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&s&&(o+=this.calculateDistance(s,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};o+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",s=!0){const i=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(i,n,t,{units:o}):r=g.destination(i,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,s=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let s,i;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([s,e[r].lat]);const c=s-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const h=g.lineIntersect(d,u);let f;if(h.features.length){const M=g.getCoord(h.features[0]);f=l.roundPrecision(M[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),o.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),o.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((s,i)=>(s.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&s.push(i),s),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,s=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},h={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,h);n>f&&(n=f,s=d,o=a,i=this.calculateDistance(u,e),r=this.calculateDistance(h,e))}}),i!==0&&r!==0?t[o].splice(s+1,0,[e.lng,e.lat]):i===0?t[o].splice(s,1,[e.lng,e.lat]):r===0&&t[o].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=v.convertRouteToCoordinates(t);return n.push(e),v.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=v.convertRouteToCoordinates(t);return n.unshift(e),v.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let s=0;return n.forEach(i=>{if(s===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const s=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...o],s),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,s=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,o=c,s=r)}}),{minDist:n,segIndex:s,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let i=!0;for(let r=n;r<t.length;r++)if(i){const c=[];c.push([e.lng,e.lat]);for(let a=o+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),i=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,o=i)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let i=o+1;i<t.length;i++)s.push(t[i]);return s}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],s=e[n+1],i=this.calculateRangeRoute(o,s,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(i),s.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,s=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,d);o>=u&&(o=u,s=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<o||i===o&&s===0?t.unshift(e):r<o||r===o&&s===t.length-2?t.push(e):t.splice(s+1,0,e):i===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],s=e[n];if(n===1&&t.push(o),s.gcToPrevious){const i=this.interpolateCoordinates(o,s,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const a=c.map(d=>g.point(d));o.push(...a)}const s=g.featureCollection(o),i=g.nearestPoint(n,s),r=g.getCoord(i);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const s=t[o],i=t[o+1];if(this.calculateDistance(e,s)===0){n=o;break}if(this.calculateDistance(e,i)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var h;const s=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((f,M)=>{if(c)r.push(f);else{const m=[];let P;for(let D=0;D<f.length;D++)if(u)m.push(f[D]);else{P={lng:f[D][0],lat:f[D][1]};const T=this.calculateDistance(e,P,!0,8,o);if(a+=T,a<t)d+=T,i.push(P),e=P;else{if(d=t,a===t)u=P,m.push([u.lng,u.lat]);else{const p=a-t,N=this.calculateBearing(P,e);u=this.calculateCoordinate(P,N,p,o),m.push([u.lng,u.lat]),m.push([P.lng,P.lat])}c=!0}}m.length&&r.push(m),M===n.length-1&&!u&&(u=P)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((h=r[0])==null?void 0:h.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),s=g.point([o,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),h=l.roundPrecision(d[1],6);return{lng:u,lat:h,inline:!(u===i&&h===t.lat)&&!(u===r&&h===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,s;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(o,c,!0);a&&a>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),s=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e)});for(let o=1;o<t.length;o++){const s=t[o-1],i=t[o];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let o=1;o<e.length;o++){const s=e[o-1],i=e[o];i.gcToPrevious?(s.bearing=this.calculateBearing(s,i,!1),i.distanceFromPrevious=this.calculateDistance(s,i,!1)):(s.bearing=this.calculateBearing(s,i,!0),i.distanceFromPrevious=this.calculateDistance(s,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const i of s)t.push(i);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let S;try{S=O.getLogger("vessel")}catch{}finally{}class W{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const s=(n=o.history)==null?void 0:n[0];for(const i of o.forecasts){const r=[],c=y(i.date).utc(),a=`${o.name}-${i.model}`;if(s){const d=y(s.updated).utc(),u=g.point([s.lng,s.lat],{model:i.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const h=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:o.name,date:h.format(),hour:Number(d),format:h.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:a,type:"forecast"});t.features.push(d)}}}if(o.history){const s=[];for(const r of o.history){const c=y(r.updated).utc(),a=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const i=o.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:o.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,i,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,u=a.properties.model,h=a.properties.showCircle,f=y(a.properties.date).utc();let M=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const m=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(T=>T.geometry.type==="Point"&&T.properties.type==="forecast"&&T.properties.category===`${d}-${u}`);let P,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(m,D),P<=m.length-1;){if(P>0){const T=m[P],p=P===0?void 0:m[P-1],N=(M/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(T.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),E=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],T.geometry.coordinates[0],N),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],T.geometry.coordinates[1],N),A=g.point([E,F],{name:d,model:u,category:T==null?void 0:T.properties.category,date:D.format(),format:D.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,T.properties.gusts,N),hour:this.computeNumber(p==null?void 0:p.properties.hour,T.properties.hour,N),movement:this.computeNumber(p==null?void 0:p.properties.movement,T.properties.movement,N),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,T.properties.pressure,N),wind:this.computeNumber(p==null?void 0:p.properties.wind,T.properties.wind,N),type:"forecast",showCircle:h});o.push(A)}M+=t*60,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=Math.abs(a-d);let h=0;u<180?h=u+90:u>=180&&(h=u-90);const f=v.calculateCoordinate(s,h,n);return S==null||S.info("[%s] the right tangent position: %j",o.requestId,{from:e,t1:s,t2:i,radius:n,bearing1:a,bearing2:d,right:f}),{at:f,t1:s,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=v.calculateDistance(e,s);return{at:v.calculateCoordinate(s,a-d+180,n<u?n:u),t1:s,t2:i,hr:Number(r),hours:c}}else return S==null||S.info("[%s] no need drift: %j",o.requestId,{from:e,t1:s,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var d,u,h,f,M;let o={};(d=e.forecasts)==null||d.forEach(m=>{o={...m.hours,...o}});const s=((u=e==null?void 0:e.history)==null?void 0:u[0])||(o==null?void 0:o[(h=Object.keys(o))==null?void 0:h[0]]);S==null||S.info("[%s] the first tropical center: %j",n.requestId,s);let i=(f=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);i||(i=(M=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:M.at(-1));const r=o==null?void 0:o[i||-1];S==null||S.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(o||{}).filter(m=>Number(m)<=Number(i)),a={0:s};for(const m of c)a[m]=o[m];return{t1:s,t2:r,hr:i,hours:a}}static pickIndex(e,t){let n=0;for(const o of e){if(y(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const s in e)o[s]=this.computeNumber(e[s],t[s],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=v,C.LngLatHelper=l,C.TropicalHelper=W,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(C,R){typeof exports=="object"&&typeof module<"u"?R(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"],R):(C=typeof globalThis<"u"?globalThis:C||self,R(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,R,y,B,$){"use strict";function k(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const g=k(R);function L(b){return b&&b.__esModule&&Object.prototype.hasOwnProperty.call(b,"default")?b.default:b}class x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(b=>{x.prototype[b.toLowerCase()]=()=>{},x.prototype[`is${b}Enabled`]=()=>!1});const I=(()=>{try{return require("log4js")}catch{return null}})();var O={getLogger:I?I.getLogger:()=>new x};const j=L(O);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),o=y().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=l.roundPrecision(c,t).toString().padStart(2,"0"):a=l.padNumber(c,2,2),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:h}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;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,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;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,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,s=Number(o.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${o}E`:s<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${s>0?"E":"W"}`:e=`${o}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${s}`}}class v{static calculateBearing(e,t,n=!0,o=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(s.features[0],s.features[1]):i=g.bearing(s.features[0],s.features[1]),i<0&&(i+=360),l.roundPrecision(i,o)}static calculateDistance(e,t,n=!0,o=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:s}):r=g.distance(i.features[0],i.features[1],{units:s}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,s;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&s&&(o+=this.calculateDistance(s,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};o+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",s=!0){const i=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(i,n,t,{units:o}):r=g.destination(i,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,s=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let s,i;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([s,e[r].lat]);const c=s-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const h=g.lineIntersect(d,u);let f;if(h.features.length){const M=g.getCoord(h.features[0]);f=l.roundPrecision(M[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),o.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),o.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((s,i)=>(s.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&s.push(i),s),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,s=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},h={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,h);n>f&&(n=f,s=d,o=a,i=this.calculateDistance(u,e),r=this.calculateDistance(h,e))}}),i!==0&&r!==0?t[o].splice(s+1,0,[e.lng,e.lat]):i===0?t[o].splice(s,1,[e.lng,e.lat]):r===0&&t[o].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=v.convertRouteToCoordinates(t);return n.push(e),v.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=v.convertRouteToCoordinates(t);return n.unshift(e),v.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let s=0;return n.forEach(i=>{if(s===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const s=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...o],s),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,s=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,o=c,s=r)}}),{minDist:n,segIndex:s,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let i=!0;for(let r=n;r<t.length;r++)if(i){const c=[];c.push([e.lng,e.lat]);for(let a=o+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),i=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,o=i)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let i=o+1;i<t.length;i++)s.push(t[i]);return s}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],s=e[n+1],i=this.calculateRangeRoute(o,s,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(i),s.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,s=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,d);o>=u&&(o=u,s=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<o||i===o&&s===0?t.unshift(e):r<o||r===o&&s===t.length-2?t.push(e):t.splice(s+1,0,e):i===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],s=e[n];if(n===1&&t.push(o),s.gcToPrevious){const i=this.interpolateCoordinates(o,s,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),s=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),i=g.lineString(s),r=g.nearestPointOnLine(i,n),c=g.getCoord(r);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const s=t[o],i=t[o+1];if(this.calculateDistance(e,s)===0){n=o;break}if(this.calculateDistance(e,i)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var h;const s=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((f,M)=>{if(c)r.push(f);else{const m=[];let P;for(let D=0;D<f.length;D++)if(u)m.push(f[D]);else{P={lng:f[D][0],lat:f[D][1]};const T=this.calculateDistance(e,P,!0,8,o);if(a+=T,a<t)d+=T,i.push(P),e=P;else{if(d=t,a===t)u=P,m.push([u.lng,u.lat]);else{const p=a-t,N=this.calculateBearing(P,e);u=this.calculateCoordinate(P,N,p,o),m.push([u.lng,u.lat]),m.push([P.lng,P.lat])}c=!0}}m.length&&r.push(m),M===n.length-1&&!u&&(u=P)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((h=r[0])==null?void 0:h.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),s=g.point([o,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),h=l.roundPrecision(d[1],6);return{lng:u,lat:h,inline:!(u===i&&h===t.lat)&&!(u===r&&h===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,s;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(o,c,!0);a&&a>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),s=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e,!0)});for(let o=1;o<t.length;o++){const s=t[o-1],i=t[o];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let o=1;o<e.length;o++){const s=e[o-1],i=e[o];i.gcToPrevious?(s.bearing=this.calculateBearing(s,i,!1),i.distanceFromPrevious=this.calculateDistance(s,i,!1)):(s.bearing=this.calculateBearing(s,i,!0),i.distanceFromPrevious=this.calculateDistance(s,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const i of s)t.push(i);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let S;try{S=j.getLogger("vessel")}catch{}finally{}class W{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const s=(n=o.history)==null?void 0:n[0];for(const i of o.forecasts){const r=[],c=y(i.date).utc(),a=`${o.name}-${i.model}`;if(s){const d=y(s.updated).utc(),u=g.point([s.lng,s.lat],{model:i.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const h=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:o.name,date:h.format(),hour:Number(d),format:h.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:a,type:"forecast"});t.features.push(d)}}}if(o.history){const s=[];for(const r of o.history){const c=y(r.updated).utc(),a=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const i=o.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:o.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,i,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,u=a.properties.model,h=a.properties.showCircle,f=y(a.properties.date).utc();let M=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const m=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(T=>T.geometry.type==="Point"&&T.properties.type==="forecast"&&T.properties.category===`${d}-${u}`);let P,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(m,D),P<=m.length-1;){if(P>0){const T=m[P],p=P===0?void 0:m[P-1],N=(M/60-((r=p==null?void 0:p.properties)==null?void 0:r.hour))/(T.properties.hour-((c=p==null?void 0:p.properties)==null?void 0:c.hour)),E=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],T.geometry.coordinates[0],N),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],T.geometry.coordinates[1],N),A=g.point([E,F],{name:d,model:u,category:T==null?void 0:T.properties.category,date:D.format(),format:D.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,T.properties.gusts,N),hour:this.computeNumber(p==null?void 0:p.properties.hour,T.properties.hour,N),movement:this.computeNumber(p==null?void 0:p.properties.movement,T.properties.movement,N),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,T.properties.pressure,N),wind:this.computeNumber(p==null?void 0:p.properties.wind,T.properties.wind,N),type:"forecast",showCircle:h});o.push(A)}M+=t*60,D=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=Math.abs(a-d);let h=0;u<180?h=u+90:u>=180&&(h=u-90);const f=v.calculateCoordinate(s,h,n);return S==null||S.info("[%s] the right tangent position: %j",o.requestId,{from:e,t1:s,t2:i,radius:n,bearing1:a,bearing2:d,right:f}),{at:f,t1:s,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,o={}){const{t1:s,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,o);if(s&&i){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,i),u=v.calculateDistance(e,s);return{at:v.calculateCoordinate(s,a-d+180,n<u?n:u),t1:s,t2:i,hr:Number(r),hours:c}}else return S==null||S.info("[%s] no need drift: %j",o.requestId,{from:e,t1:s,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var d,u,h,f,M;let o={};(d=e.forecasts)==null||d.forEach(m=>{o={...m.hours,...o}});const s=((u=e==null?void 0:e.history)==null?void 0:u[0])||(o==null?void 0:o[(h=Object.keys(o))==null?void 0:h[0]]);S==null||S.info("[%s] the first tropical center: %j",n.requestId,s);let i=(f=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);i||(i=(M=Object.keys(o||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:M.at(-1));const r=o==null?void 0:o[i||-1];S==null||S.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(o||{}).filter(m=>Number(m)<=Number(i)),a={0:s};for(const m of c)a[m]=o[m];return{t1:s,t2:r,hr:i,hours:a}}static pickIndex(e,t){let n=0;for(const o of e){if(y(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const s in e)o[s]=this.computeNumber(e[s],t[s],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=v,C.LngLatHelper=l,C.TropicalHelper=W,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|