@idm-plugin/geo 2.3.7 → 2.3.8
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 +355 -282
- package/dist/index.umd.cjs +7 -7
- package/dist/lane/src/index.d.ts +39 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as T from "@turf/turf";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import P from "moment";
|
|
3
|
+
import G from "@log4js-node/log4js-api";
|
|
4
4
|
import "moment-timezone";
|
|
5
5
|
import V from "tz-lookup";
|
|
6
6
|
import J from "shpjs";
|
|
7
|
-
class
|
|
7
|
+
class f {
|
|
8
8
|
/**
|
|
9
9
|
* 基于输入的经度,计算出时区
|
|
10
10
|
* @param lng
|
|
11
11
|
* @param lat
|
|
12
12
|
*/
|
|
13
13
|
static guessTimeZoneOffset(t, e) {
|
|
14
|
-
t =
|
|
15
|
-
const n = V(e, t), s =
|
|
16
|
-
return
|
|
14
|
+
t = f.convertToStdLng(t);
|
|
15
|
+
const n = V(e, t), s = P().tz(n).utcOffset();
|
|
16
|
+
return f.roundPrecision(s / 60, 1);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* 将时间offset转换为时区,例如:8.5 => +08:30
|
|
@@ -30,17 +30,17 @@ class h {
|
|
|
30
30
|
* @param format
|
|
31
31
|
*/
|
|
32
32
|
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
33
|
-
t =
|
|
33
|
+
t = f.convertToStdLng(t, 6);
|
|
34
34
|
let s = "E";
|
|
35
35
|
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
36
36
|
let c = t * 3600, i, r, o, a, l, u;
|
|
37
|
-
i = c % 3600 % 60, n.indexOf("S") !== -1 && (c = c - i, r =
|
|
37
|
+
i = c % 3600 % 60, n.indexOf("S") !== -1 && (c = c - i, r = f.padNumber(i, 2, 2)), o = c / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = f.roundPrecision(o, e).toString().padStart(2, "0") : a = f.padNumber(o, 2, 3), c = c - o * 60), l = c / 3600, n.indexOf("M") !== -1 ? u = f.roundPrecision(l, e).toString().padStart(3, "0") : u = f.padNumber(l, 3, 6), Number(r) >= 60 && (a = Number(a) + 1, r = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
38
38
|
const g = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
39
39
|
return {
|
|
40
40
|
direction: s,
|
|
41
|
-
degree:
|
|
42
|
-
minute:
|
|
43
|
-
second:
|
|
41
|
+
degree: f.roundPrecision(l, e),
|
|
42
|
+
minute: f.roundPrecision(o, e),
|
|
43
|
+
second: f.roundPrecision(i, e),
|
|
44
44
|
pretty: g,
|
|
45
45
|
S: r,
|
|
46
46
|
M: a,
|
|
@@ -58,13 +58,13 @@ class h {
|
|
|
58
58
|
let s = "N";
|
|
59
59
|
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
60
60
|
let c = t * 3600, i, r, o, a, l, u;
|
|
61
|
-
i = c % 3600 % 60, n.indexOf("S") !== -1 && (c = c - i, r =
|
|
61
|
+
i = c % 3600 % 60, n.indexOf("S") !== -1 && (c = c - i, r = f.padNumber(i, 2, 2)), o = c / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = f.roundPrecision(o, e).toString().padStart(2, "0") : a = f.padNumber(o, 2, 3), c = c - o * 60), l = c / 3600, n.indexOf("M") !== -1 ? u = f.roundPrecision(l, e).toString().padStart(2, "0") : u = f.padNumber(l, 2, 6), Number(r) >= 60 && (a = Number(a) + 1, r = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
62
62
|
const g = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
63
63
|
return {
|
|
64
64
|
direction: s,
|
|
65
|
-
degree:
|
|
66
|
-
minute:
|
|
67
|
-
second:
|
|
65
|
+
degree: f.roundPrecision(l, e),
|
|
66
|
+
minute: f.roundPrecision(o, e),
|
|
67
|
+
second: f.roundPrecision(i, e),
|
|
68
68
|
pretty: g,
|
|
69
69
|
S: r,
|
|
70
70
|
M: a,
|
|
@@ -74,7 +74,7 @@ class h {
|
|
|
74
74
|
static str2Lng(t, e = 6) {
|
|
75
75
|
let n;
|
|
76
76
|
if (isNaN(t)) {
|
|
77
|
-
t =
|
|
77
|
+
t = f.strReplace(t, "LNG");
|
|
78
78
|
const s = t[t.length - 1].toUpperCase();
|
|
79
79
|
t = t.substring(0, t.length - 1).trim();
|
|
80
80
|
const c = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
@@ -86,12 +86,12 @@ class h {
|
|
|
86
86
|
n = i + r / 60 + o / 3600, s === "W" && (n = n * -1);
|
|
87
87
|
} else
|
|
88
88
|
n = Number(t);
|
|
89
|
-
return
|
|
89
|
+
return f.convertToStdLng(n, e);
|
|
90
90
|
}
|
|
91
91
|
static str2Lat(t, e = 6) {
|
|
92
92
|
let n;
|
|
93
93
|
if (isNaN(t)) {
|
|
94
|
-
t =
|
|
94
|
+
t = f.strReplace(t, "LAT");
|
|
95
95
|
const s = t[t.length - 1].toUpperCase();
|
|
96
96
|
t = t.substring(0, t.length - 1).trim();
|
|
97
97
|
const c = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
@@ -105,19 +105,19 @@ class h {
|
|
|
105
105
|
s === "S" && (n = n * -1);
|
|
106
106
|
} else
|
|
107
107
|
n = Number(t);
|
|
108
|
-
return
|
|
108
|
+
return f.roundPrecision(n, e);
|
|
109
109
|
}
|
|
110
110
|
static str2LngOrLat(t, e = 6, n = "LAT") {
|
|
111
|
-
t =
|
|
111
|
+
t = f.strReplace(t, n);
|
|
112
112
|
const s = t[t.length - 1].toUpperCase();
|
|
113
113
|
return ["N", "S"].includes(s) ? {
|
|
114
|
-
lat:
|
|
114
|
+
lat: f.str2Lat(t, e)
|
|
115
115
|
} : {
|
|
116
|
-
lng:
|
|
116
|
+
lng: f.str2Lng(t, e)
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
static convertToStdLng(t, e = 6) {
|
|
120
|
-
return t > 180 ? (t = t % 360, t = t > 180 ? t - 360 : t) : t < -180 && (t = t % 360, t = t < -180 ? t + 360 : t),
|
|
120
|
+
return t > 180 ? (t = t % 360, t = t > 180 ? t - 360 : t) : t < -180 && (t = t % 360, t = t < -180 ? t + 360 : t), f.roundPrecision(t, e);
|
|
121
121
|
}
|
|
122
122
|
static roundPrecision(t, e = 6) {
|
|
123
123
|
const n = Number("1".padEnd(e + 1, "0"));
|
|
@@ -160,7 +160,7 @@ class h {
|
|
|
160
160
|
* @param dcmPrecision 小数位数
|
|
161
161
|
*/
|
|
162
162
|
static padNumber(t, e = 2, n = 2) {
|
|
163
|
-
const s =
|
|
163
|
+
const s = f.roundPrecision(t - Math.trunc(t), n), c = s >= 1 ? Math.trunc(t + 1).toString().padStart(e, "0") : Math.trunc(t).toString().padStart(e, "0");
|
|
164
164
|
return s >= 1 ? c : n > 0 ? `${c}.${Math.trunc(s * Math.pow(10, n)).toString().padStart(n, "0")}` : c;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -202,7 +202,7 @@ class K {
|
|
|
202
202
|
if (n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))
|
|
203
203
|
continue;
|
|
204
204
|
const d = g.positionTime - u.positionTime;
|
|
205
|
-
if (
|
|
205
|
+
if (v.calculateDistance(g, u, !0, 4) / (d / 3600) < e)
|
|
206
206
|
i || (i = a), l === t.length - 1 && (r = g, o = l);
|
|
207
207
|
else {
|
|
208
208
|
i && (r = t[l - 1], o = l);
|
|
@@ -216,18 +216,18 @@ class K {
|
|
|
216
216
|
lng: i.lng,
|
|
217
217
|
sog: i.sog,
|
|
218
218
|
positionTime: i.positionTime,
|
|
219
|
-
utc:
|
|
219
|
+
utc: P.unix(i.positionTime).utc().format()
|
|
220
220
|
},
|
|
221
221
|
end: {
|
|
222
222
|
lat: r.lat,
|
|
223
223
|
lng: r.lng,
|
|
224
224
|
sog: r.sog,
|
|
225
225
|
positionTime: r.positionTime,
|
|
226
|
-
utc:
|
|
226
|
+
utc: P.unix(r.positionTime).utc().format()
|
|
227
227
|
},
|
|
228
228
|
duration: r.positionTime - i.positionTime
|
|
229
|
-
}, u = t.filter((d) => d.positionTime >= l.start.positionTime && d.positionTime <= l.end.positionTime), g =
|
|
230
|
-
l.distance =
|
|
229
|
+
}, u = t.filter((d) => d.positionTime >= l.start.positionTime && d.positionTime <= l.end.positionTime), g = v.divideAccordingToLng(u);
|
|
230
|
+
l.distance = v.calculateRouteDistance(g), l.hours = Math.round(l.duration / 3600 * 10) / 10, l.hours && (l.avgSog = Math.round(l.distance / l.hours * 10) / 10, c.push(l));
|
|
231
231
|
}
|
|
232
232
|
i = void 0, r = void 0;
|
|
233
233
|
}
|
|
@@ -241,12 +241,12 @@ class K {
|
|
|
241
241
|
* @param etm
|
|
242
242
|
*/
|
|
243
243
|
static inspectSummary(t, e, n) {
|
|
244
|
-
const s =
|
|
244
|
+
const s = P(e), c = P(n), i = t.filter((l) => l.positionTime >= s.unix() && l.positionTime <= c.unix());
|
|
245
245
|
let r = 0, o = 0;
|
|
246
246
|
if (i.length > 1)
|
|
247
247
|
for (let l = 0; l < i.length - 1; l++) {
|
|
248
248
|
const u = i[l], g = i[l + 1];
|
|
249
|
-
r +=
|
|
249
|
+
r += v.calculateDistance(u, g, !0, 4), o += Math.abs(g.positionTime - u.positionTime);
|
|
250
250
|
}
|
|
251
251
|
r = Math.round(r * 100) / 100, o = Math.round(o / 3600 * 100) / 100;
|
|
252
252
|
const a = o ? Math.round(r / o * 100) / 100 : 0;
|
|
@@ -255,7 +255,7 @@ class K {
|
|
|
255
255
|
}
|
|
256
256
|
let X;
|
|
257
257
|
try {
|
|
258
|
-
X =
|
|
258
|
+
X = G.getLogger("meteo");
|
|
259
259
|
} catch {
|
|
260
260
|
} finally {
|
|
261
261
|
}
|
|
@@ -279,14 +279,14 @@ function _(C) {
|
|
|
279
279
|
const t = new TextEncoder(), e = [], n = [];
|
|
280
280
|
let s = 0;
|
|
281
281
|
for (const d of C) {
|
|
282
|
-
const p = t.encode(d.name),
|
|
283
|
-
S.setUint32(0, 67324752, !0), S.setUint16(4, 20, !0), S.setUint16(8, 0, !0), S.setUint32(14,
|
|
282
|
+
const p = t.encode(d.name), h = Q(d.data), m = new Uint8Array(30 + p.length), S = new DataView(m.buffer);
|
|
283
|
+
S.setUint32(0, 67324752, !0), S.setUint16(4, 20, !0), S.setUint16(8, 0, !0), S.setUint32(14, h, !0), S.setUint32(18, d.data.length, !0), S.setUint32(22, d.data.length, !0), S.setUint16(26, p.length, !0), m.set(p, 30), e.push({ nameBytes: p, data: d.data, crc: h, offset: s }), s += m.length + d.data.length, n.push(m, d.data);
|
|
284
284
|
}
|
|
285
285
|
const c = s, i = [];
|
|
286
286
|
let r = 0;
|
|
287
287
|
for (const d of e) {
|
|
288
|
-
const p = new Uint8Array(46 + d.nameBytes.length),
|
|
289
|
-
|
|
288
|
+
const p = new Uint8Array(46 + d.nameBytes.length), h = new DataView(p.buffer);
|
|
289
|
+
h.setUint32(0, 33639248, !0), h.setUint16(4, 20, !0), h.setUint16(6, 20, !0), h.setUint16(10, 0, !0), h.setUint32(16, d.crc, !0), h.setUint32(20, d.data.length, !0), h.setUint32(24, d.data.length, !0), h.setUint16(28, d.nameBytes.length, !0), h.setUint32(42, d.offset, !0), p.set(d.nameBytes, 46), r += p.length, i.push(p);
|
|
290
290
|
}
|
|
291
291
|
const o = new Uint8Array(22), a = new DataView(o.buffer);
|
|
292
292
|
a.setUint32(0, 101010256, !0), a.setUint16(8, e.length, !0), a.setUint16(10, e.length, !0), a.setUint32(12, r, !0), a.setUint32(16, c, !0);
|
|
@@ -298,13 +298,13 @@ function _(C) {
|
|
|
298
298
|
u.set(d, g), g += d.length;
|
|
299
299
|
return u.set(o, g), u;
|
|
300
300
|
}
|
|
301
|
-
function
|
|
301
|
+
function z(C) {
|
|
302
302
|
let t = "", e = C;
|
|
303
303
|
for (; e >= 0; )
|
|
304
304
|
t = String.fromCharCode(65 + e % 26) + t, e = Math.floor(e / 26) - 1;
|
|
305
305
|
return t;
|
|
306
306
|
}
|
|
307
|
-
class
|
|
307
|
+
class v {
|
|
308
308
|
/**
|
|
309
309
|
* 计算方位角
|
|
310
310
|
* @param from 坐标 {lng, lat}
|
|
@@ -319,7 +319,7 @@ class b {
|
|
|
319
319
|
[e.lng, e.lat]
|
|
320
320
|
]);
|
|
321
321
|
let i;
|
|
322
|
-
return n ? i = T.rhumbBearing(c.features[0], c.features[1]) : i = T.bearing(c.features[0], c.features[1]), i < 0 && (i += 360),
|
|
322
|
+
return n ? i = T.rhumbBearing(c.features[0], c.features[1]) : i = T.bearing(c.features[0], c.features[1]), i < 0 && (i += 360), f.roundPrecision(i, s);
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
325
|
* 计算两点间距离
|
|
@@ -331,13 +331,13 @@ class b {
|
|
|
331
331
|
* @returns {number}
|
|
332
332
|
*/
|
|
333
333
|
static calculateDistance(t, e, n = !0, s = 4, c = "nauticalmiles") {
|
|
334
|
-
t = { ...t }, e = { ...e }, t.lng =
|
|
334
|
+
t = { ...t }, e = { ...e }, t.lng = f.convertToStdLng(t.lng, s), e.lng = f.convertToStdLng(e.lng, s);
|
|
335
335
|
const i = T.points([
|
|
336
336
|
[t.lng, t.lat],
|
|
337
337
|
[e.lng, e.lat]
|
|
338
338
|
]);
|
|
339
339
|
let r;
|
|
340
|
-
return n ? r = T.rhumbDistance(i.features[0], i.features[1], { units: c }) : r = T.distance(i.features[0], i.features[1], { units: c }),
|
|
340
|
+
return n ? r = T.rhumbDistance(i.features[0], i.features[1], { units: c }) : r = T.distance(i.features[0], i.features[1], { units: c }), f.roundPrecision(r, s);
|
|
341
341
|
}
|
|
342
342
|
/**
|
|
343
343
|
* 计算航线距离
|
|
@@ -354,7 +354,7 @@ class b {
|
|
|
354
354
|
const a = { lng: i[r + 1][0], lat: i[r + 1][1] };
|
|
355
355
|
s += this.calculateDistance(o, a, !0, e, n), c = a;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return f.roundPrecision(s, e);
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
360
|
* 计算坐标(基于方位角和距离)
|
|
@@ -369,7 +369,7 @@ class b {
|
|
|
369
369
|
let r;
|
|
370
370
|
c ? r = T.rhumbDestination(i, n, e, { units: s }) : r = T.destination(i, n, e, { units: s });
|
|
371
371
|
const o = r.geometry.coordinates;
|
|
372
|
-
return { lng:
|
|
372
|
+
return { lng: f.convertToStdLng(o[0], 8), lat: f.roundPrecision(o[1], 8) };
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
375
375
|
* 插值大圆坐标(基于两点方位角和间距)
|
|
@@ -408,10 +408,10 @@ class b {
|
|
|
408
408
|
const c = [];
|
|
409
409
|
let i, r;
|
|
410
410
|
for (let o = 0; o < t.length - 1; o++) {
|
|
411
|
-
i =
|
|
411
|
+
i = f.convertToStdLng(t[o].lng, 8), r = f.convertToStdLng(t[o + 1].lng, 8), t[o].lat = f.roundPrecision(t[o].lat, 8), t[o + 1].lat = f.roundPrecision(t[o + 1].lat, 8), s.push([i, t[o].lat]);
|
|
412
412
|
const a = i - r;
|
|
413
413
|
if (Math.abs(a) > 180) {
|
|
414
|
-
const l =
|
|
414
|
+
const l = f.convertToMonotonicLng2([
|
|
415
415
|
[i, t[o].lat],
|
|
416
416
|
[r, t[o + 1].lat]
|
|
417
417
|
]);
|
|
@@ -423,8 +423,8 @@ class b {
|
|
|
423
423
|
const d = T.lineIntersect(u, g);
|
|
424
424
|
let p;
|
|
425
425
|
if (d.features.length) {
|
|
426
|
-
const
|
|
427
|
-
p =
|
|
426
|
+
const h = T.getCoord(d.features[0]);
|
|
427
|
+
p = f.roundPrecision(h[1], 8);
|
|
428
428
|
} else
|
|
429
429
|
p = t[o].lat;
|
|
430
430
|
a > 0 ? (s.push([180 - 1e-6, p]), c.push([...s]), s = [], s.push([-(180 - 1e-6), p])) : (s.push([-(180 - 1e-6), p]), c.push([...s]), s = [], s.push([180 - 1e-6, p]));
|
|
@@ -458,10 +458,10 @@ class b {
|
|
|
458
458
|
* @param route 航线[[[lng, lat],[lng, lat]]]
|
|
459
459
|
*/
|
|
460
460
|
static removeCoordinateFromRoute(t, e) {
|
|
461
|
-
t.lng =
|
|
461
|
+
t.lng = f.convertToStdLng(t.lng, 8);
|
|
462
462
|
for (const n of e)
|
|
463
463
|
for (let s = n.length - 1; s >= 0; s--)
|
|
464
|
-
|
|
464
|
+
f.roundPrecision(n[s][0], 8) === t.lng && f.roundPrecision(n[s][1], 8) === f.roundPrecision(t.lat, 8) && n.splice(s, 1);
|
|
465
465
|
return e;
|
|
466
466
|
}
|
|
467
467
|
/**
|
|
@@ -470,9 +470,9 @@ class b {
|
|
|
470
470
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
471
471
|
*/
|
|
472
472
|
static removeCoordinateFromWaypoints(t, e) {
|
|
473
|
-
t.lng =
|
|
473
|
+
t.lng = f.convertToStdLng(t.lng, 8);
|
|
474
474
|
for (let n = e.length - 1; n >= 0; n--)
|
|
475
|
-
|
|
475
|
+
f.roundPrecision(e[n].lng, 8) === t.lng && f.roundPrecision(e[n].lat, 8) === f.roundPrecision(t.lat, 8) && e.splice(n, 1);
|
|
476
476
|
return e;
|
|
477
477
|
}
|
|
478
478
|
/**
|
|
@@ -487,7 +487,7 @@ class b {
|
|
|
487
487
|
* [[[120, 30], [120, 35], [125,40], [130, 37]], [[-150, 40], [-130, 30]]]
|
|
488
488
|
*/
|
|
489
489
|
static mergeCoordinateToRoute(t, e) {
|
|
490
|
-
t.lng =
|
|
490
|
+
t.lng = f.convertToStdLng(t.lng, 8);
|
|
491
491
|
let n = Number.MAX_VALUE, s = 0, c = 0, i, r;
|
|
492
492
|
return e.forEach((o, a) => {
|
|
493
493
|
for (let l = 0; l < o.length - 1; l++) {
|
|
@@ -502,9 +502,9 @@ class b {
|
|
|
502
502
|
* @param route
|
|
503
503
|
*/
|
|
504
504
|
static appendCoordinateToRoute(t, e) {
|
|
505
|
-
t.lng =
|
|
506
|
-
const n =
|
|
507
|
-
return n.push(t),
|
|
505
|
+
t.lng = f.convertToStdLng(t.lng, 8);
|
|
506
|
+
const n = v.convertRouteToCoordinates(e);
|
|
507
|
+
return n.push(t), v.divideAccordingToLng(n);
|
|
508
508
|
}
|
|
509
509
|
/**
|
|
510
510
|
* 向route头加1个坐标
|
|
@@ -512,8 +512,8 @@ class b {
|
|
|
512
512
|
* @param route
|
|
513
513
|
*/
|
|
514
514
|
static unshiftCoordinateToRoute(t, e) {
|
|
515
|
-
const n =
|
|
516
|
-
return n.unshift(t),
|
|
515
|
+
const n = v.convertRouteToCoordinates(e);
|
|
516
|
+
return n.unshift(t), v.divideAccordingToLng(n);
|
|
517
517
|
}
|
|
518
518
|
/**
|
|
519
519
|
* 合并多个waypoints进航线
|
|
@@ -541,11 +541,11 @@ class b {
|
|
|
541
541
|
return;
|
|
542
542
|
const r = [];
|
|
543
543
|
for (const o of i) {
|
|
544
|
-
if (
|
|
544
|
+
if (f.roundPrecision(e.lng, 8) === f.roundPrecision(o[0], 8) && f.roundPrecision(e.lat, 8) === f.roundPrecision(o[1], 8)) {
|
|
545
545
|
r.push(o), c === 0 && r.push([t.lng, t.lat]), c = 2;
|
|
546
546
|
break;
|
|
547
547
|
}
|
|
548
|
-
c === 1 ? r.push(o) :
|
|
548
|
+
c === 1 ? r.push(o) : f.roundPrecision(t.lng, 8) === f.roundPrecision(o[0], 8) && f.roundPrecision(t.lat, 8) === f.roundPrecision(o[1], 8) && (c = 1, r.push(o));
|
|
549
549
|
}
|
|
550
550
|
r.length && s.push(r);
|
|
551
551
|
}), s;
|
|
@@ -560,9 +560,9 @@ class b {
|
|
|
560
560
|
*/
|
|
561
561
|
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
562
562
|
const c = this.convertRouteToCoordinates(n, 0), i = this.mergeCoordinatesToWaypoints([t, e], c.length ? c : s), r = i.findIndex(
|
|
563
|
-
(l) =>
|
|
563
|
+
(l) => f.roundPrecision(t.lng, 8) === f.roundPrecision(l.lng, 8) && f.roundPrecision(t.lat, 8) === f.roundPrecision(l.lat, 8)
|
|
564
564
|
), o = i.findIndex(
|
|
565
|
-
(l) =>
|
|
565
|
+
(l) => f.roundPrecision(e.lng, 8) === f.roundPrecision(l.lng, 8) && f.roundPrecision(e.lat, 8) === f.roundPrecision(l.lat, 8)
|
|
566
566
|
);
|
|
567
567
|
return i.filter((l, u) => u >= r && u <= o);
|
|
568
568
|
}
|
|
@@ -587,10 +587,10 @@ class b {
|
|
|
587
587
|
* @return [[[lng, lat]]]
|
|
588
588
|
*/
|
|
589
589
|
static calculateSubRoute(t, e) {
|
|
590
|
-
const n =
|
|
591
|
-
|
|
590
|
+
const n = v.convertRouteToCoordinates(e);
|
|
591
|
+
v.mergeCoordinateToWaypoints(t, n, !0), e = v.divideAccordingToLng(n);
|
|
592
592
|
const { segIndex: s, minIndex: c } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
593
|
-
t.lng =
|
|
593
|
+
t.lng = f.convertToStdLng(t.lng);
|
|
594
594
|
const i = [];
|
|
595
595
|
let r = !0;
|
|
596
596
|
for (let o = s; o < e.length; o++)
|
|
@@ -621,7 +621,7 @@ class b {
|
|
|
621
621
|
const a = this.calculatePointToLineDistance(t, r, o);
|
|
622
622
|
n > a && (n = a, s = i);
|
|
623
623
|
}
|
|
624
|
-
t.lng =
|
|
624
|
+
t.lng = f.convertToStdLng(t.lng);
|
|
625
625
|
const c = [t];
|
|
626
626
|
for (let i = s + 1; i < e.length; i++)
|
|
627
627
|
c.push(e[i]);
|
|
@@ -635,14 +635,14 @@ class b {
|
|
|
635
635
|
* @param options
|
|
636
636
|
*/
|
|
637
637
|
static calculatePointToLineDistance(t, e, n, s = { units: "nauticalmiles", method: "geodesic" }) {
|
|
638
|
-
t.lng =
|
|
639
|
-
const c =
|
|
638
|
+
t.lng = f.convertToStdLng(t.lng, 8), e = { ...e }, n = { ...n }, e.lng = f.convertToStdLng(e.lng, 8), n.lng = f.convertToStdLng(n.lng, 8);
|
|
639
|
+
const c = f.convertToMonotonicLng([e, n]);
|
|
640
640
|
e = c[0], n = c[1];
|
|
641
641
|
const i = T.lineString([
|
|
642
642
|
[e.lng, e.lat],
|
|
643
643
|
[n.lng, n.lat]
|
|
644
644
|
]), r = T.pointToLineDistance(T.point([t.lng, t.lat]), i, s), o = T.pointToLineDistance(T.point([t.lng > 0 ? t.lng - 360 : t.lng + 360, t.lat]), i, s);
|
|
645
|
-
return
|
|
645
|
+
return f.roundPrecision(Math.min(r, o), 6);
|
|
646
646
|
}
|
|
647
647
|
/**
|
|
648
648
|
* 计算途经点的COG, Distance等属性
|
|
@@ -653,7 +653,7 @@ class b {
|
|
|
653
653
|
e = this.mergeWaypointsToRoute(t, e);
|
|
654
654
|
for (let n = 0; n < t.length - 1; n++) {
|
|
655
655
|
const s = t[n], c = t[n + 1], i = this.calculateRangeRoute(s, c, e);
|
|
656
|
-
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), c.distanceFromPrevious = this.calculateRouteDistance(i), c.distanceFromStart =
|
|
656
|
+
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), c.distanceFromPrevious = this.calculateRouteDistance(i), c.distanceFromStart = f.roundPrecision((s.distanceFromStart || 0) + c.distanceFromPrevious);
|
|
657
657
|
}
|
|
658
658
|
return t;
|
|
659
659
|
}
|
|
@@ -680,7 +680,7 @@ class b {
|
|
|
680
680
|
* [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: 179, lat: 50}, {lng: -170, lat: 40}, {lng: -160, lat: 30}]
|
|
681
681
|
*/
|
|
682
682
|
static mergeCoordinateToWaypoints(t, e, n = !0) {
|
|
683
|
-
t.lng =
|
|
683
|
+
t.lng = f.convertToStdLng(t.lng, 8);
|
|
684
684
|
let s = Number.MAX_VALUE, c = 0, i = 0, r = 0;
|
|
685
685
|
if (e.length < 2)
|
|
686
686
|
e.push(t);
|
|
@@ -692,11 +692,11 @@ class b {
|
|
|
692
692
|
i !== 0 && r !== 0 ? i <= s && c === 0 ? e.unshift(t) : r <= s && c === e.length - 2 ? e.push(t) : e.splice(c + 1, 0, t) : i === 0 ? n ? e.splice(c, 1, t) : e.splice(c + 1, 0, t) : r === 0 && (n ? e.splice(c + 1, 1, t) : e.splice(c + 1, 0, t));
|
|
693
693
|
}
|
|
694
694
|
return e.map((o, a) => {
|
|
695
|
-
o.lng =
|
|
695
|
+
o.lng = f.convertToStdLng(o.lng);
|
|
696
696
|
const l = e[a + 1];
|
|
697
697
|
if (l && ((o.bearing === null || o.bearing === void 0) && ((o.positionTime || 0) > (l.positionTime || 0) ? o.bearing = this.calculateBearing(l, o, !0) : o.bearing = this.calculateBearing(o, l, !0)), o.cog = o.cog || o.bearing, !o.sog && o.positionTime && l.positionTime)) {
|
|
698
698
|
const u = this.calculateDistance(o, l, !0), g = Math.abs(l.positionTime - o.positionTime) / 3600;
|
|
699
|
-
o.sog =
|
|
699
|
+
o.sog = f.roundPrecision(u / g, 2);
|
|
700
700
|
}
|
|
701
701
|
return o;
|
|
702
702
|
});
|
|
@@ -727,7 +727,7 @@ class b {
|
|
|
727
727
|
*/
|
|
728
728
|
static nearestCoordinateInRoute(t, e) {
|
|
729
729
|
const n = T.point([t.lng, t.lat]), c = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]), i = T.lineString(c), r = T.nearestPointOnLine(i, n), o = T.getCoord(r);
|
|
730
|
-
return { lng:
|
|
730
|
+
return { lng: f.roundPrecision(o[0], 8), lat: f.roundPrecision(o[1], 8) };
|
|
731
731
|
}
|
|
732
732
|
/**
|
|
733
733
|
* 计算经过方向上的最后一个waypoint
|
|
@@ -766,27 +766,27 @@ class b {
|
|
|
766
766
|
if (o)
|
|
767
767
|
r.push(d);
|
|
768
768
|
else {
|
|
769
|
-
const
|
|
769
|
+
const h = [];
|
|
770
770
|
let m;
|
|
771
771
|
for (let S = 0; S < d.length; S++)
|
|
772
772
|
if (u)
|
|
773
|
-
|
|
773
|
+
h.push(d[S]);
|
|
774
774
|
else {
|
|
775
775
|
m = { lng: d[S][0], lat: d[S][1] };
|
|
776
|
-
const
|
|
777
|
-
if (a +=
|
|
778
|
-
l +=
|
|
776
|
+
const b = this.calculateDistance(t, m, !0, 8, s);
|
|
777
|
+
if (a += b, a < e)
|
|
778
|
+
l += b, b && i.push(m), t = m;
|
|
779
779
|
else {
|
|
780
780
|
if (l = e, a === e)
|
|
781
|
-
u = m,
|
|
781
|
+
u = m, h.push([u.lng, u.lat]);
|
|
782
782
|
else {
|
|
783
|
-
const
|
|
784
|
-
u = this.calculateCoordinate(m, y,
|
|
783
|
+
const x = a - e, y = this.calculateBearing(m, t);
|
|
784
|
+
u = this.calculateCoordinate(m, y, x, s), h.push([u.lng, u.lat]), h.push([m.lng, m.lat]);
|
|
785
785
|
}
|
|
786
786
|
o = !0;
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
|
-
|
|
789
|
+
h.length && r.push(h), p === n.length - 1 && !u && (u = m);
|
|
790
790
|
}
|
|
791
791
|
})) : (r = n, u = { ...t }), u)
|
|
792
792
|
if (i.push(u), u.distanceFromPrevious = Math.round(l * 1e4) / 1e4, u.hourFromPrevious = Math.round(l / c * 1e4) / 1e4, ((g = r[0]) == null ? void 0 : g.length) > 1) {
|
|
@@ -803,10 +803,10 @@ class b {
|
|
|
803
803
|
* @param to {lng, lat}
|
|
804
804
|
*/
|
|
805
805
|
static nearestCoordinateInLine(t, e, n) {
|
|
806
|
-
const s =
|
|
806
|
+
const s = f.convertToStdLng(t.lng, 6), c = T.point([s, t.lat]), i = f.convertToStdLng(e.lng, 6), r = f.convertToStdLng(n.lng, 6), o = T.lineString([
|
|
807
807
|
[i, e.lat],
|
|
808
808
|
[r, n.lat]
|
|
809
|
-
]), a = T.nearestPointOnLine(o, c), l = T.getCoord(a), u =
|
|
809
|
+
]), a = T.nearestPointOnLine(o, c), l = T.getCoord(a), u = f.roundPrecision(l[0], 6), g = f.roundPrecision(l[1], 6);
|
|
810
810
|
return { lng: u, lat: g, inline: !(u === i && g === e.lat) && !(u === r && g === n.lat) };
|
|
811
811
|
}
|
|
812
812
|
/**
|
|
@@ -819,7 +819,7 @@ class b {
|
|
|
819
819
|
let s, c;
|
|
820
820
|
return t.forEach((i) => {
|
|
821
821
|
i.forEach((r) => {
|
|
822
|
-
const o = { lng:
|
|
822
|
+
const o = { lng: f.roundPrecision(r[0], 8), lat: f.roundPrecision(r[1], 8) };
|
|
823
823
|
if (!c)
|
|
824
824
|
n.push(o), c = o;
|
|
825
825
|
else if (c.bearing === void 0 || c.bearing === null)
|
|
@@ -843,9 +843,9 @@ class b {
|
|
|
843
843
|
return s = this.simplifyGCCoordinates(s, e), s;
|
|
844
844
|
}
|
|
845
845
|
/**
|
|
846
|
-
*
|
|
847
|
-
* @param coordinates
|
|
848
|
-
* @param waypoints
|
|
846
|
+
* 基于大圆标识抽稀, 将 waypoints 中的 gcToPrevious 标记的点作为关键点,移除这些点之间的冗余点
|
|
847
|
+
* @param coordinates 航路点
|
|
848
|
+
* @param waypoints 关键航路点
|
|
849
849
|
*/
|
|
850
850
|
static simplifyGCCoordinates(t, e) {
|
|
851
851
|
e.forEach((s) => {
|
|
@@ -862,9 +862,9 @@ class b {
|
|
|
862
862
|
let n = 0;
|
|
863
863
|
for (let s = 1; s < t.length; s++) {
|
|
864
864
|
const c = t[s - 1], i = t[s];
|
|
865
|
-
i.gcToPrevious ? (c.bearing = this.calculateBearing(c, i, !1), i.distanceFromPrevious = this.calculateDistance(c, i, !1)) : (c.bearing = this.calculateBearing(c, i, !0), i.distanceFromPrevious = this.calculateDistance(c, i, !0)), n =
|
|
865
|
+
i.gcToPrevious ? (c.bearing = this.calculateBearing(c, i, !1), i.distanceFromPrevious = this.calculateDistance(c, i, !1)) : (c.bearing = this.calculateBearing(c, i, !0), i.distanceFromPrevious = this.calculateDistance(c, i, !0)), n = f.roundPrecision(n + i.distanceFromPrevious), i.distanceFromStart = n;
|
|
866
866
|
}
|
|
867
|
-
return t.map((s) => (s.lng =
|
|
867
|
+
return t.map((s) => (s.lng = f.convertToStdLng(s.lng), s));
|
|
868
868
|
}
|
|
869
869
|
/**
|
|
870
870
|
* 计算轨迹中心点
|
|
@@ -875,11 +875,11 @@ class b {
|
|
|
875
875
|
for (const r of t)
|
|
876
876
|
for (const o of r)
|
|
877
877
|
e.push(o);
|
|
878
|
-
const n = T.featureCollection([]), s =
|
|
878
|
+
const n = T.featureCollection([]), s = f.convertToMonotonicLng2(e);
|
|
879
879
|
for (const r of s)
|
|
880
880
|
n.features.push(T.point(r));
|
|
881
881
|
const i = T.center(n).geometry.coordinates;
|
|
882
|
-
return { lng:
|
|
882
|
+
return { lng: f.convertToStdLng(i[0], 8), lat: f.roundPrecision(i[1], 8) };
|
|
883
883
|
}
|
|
884
884
|
/**
|
|
885
885
|
* 计算中心点
|
|
@@ -898,7 +898,7 @@ class b {
|
|
|
898
898
|
for (const c of t)
|
|
899
899
|
for (const i of c)
|
|
900
900
|
e.push(i);
|
|
901
|
-
const n =
|
|
901
|
+
const n = f.convertToMonotonicLng2(e), s = T.lineString(n);
|
|
902
902
|
return T.bbox(s);
|
|
903
903
|
}
|
|
904
904
|
/**
|
|
@@ -910,35 +910,108 @@ class b {
|
|
|
910
910
|
return this.calculateBBox(e);
|
|
911
911
|
}
|
|
912
912
|
/**
|
|
913
|
-
*
|
|
914
|
-
* - 保留首尾点、重要标记点(important/pilot/suspend/velocity/gcToPrevious
|
|
915
|
-
* -
|
|
913
|
+
* 抽稀:基于 Ramer-Douglas-Peucker(RDP)横向偏差移除冗余点
|
|
914
|
+
* - 保留首尾点、重要标记点(important/pilot/suspend/velocity/gcToPrevious),并以其为分段锚点
|
|
915
|
+
* - 每个锚点段内,点相对首尾弦的横向偏差超过 epsilon 才保留,否则整段内部点一次性剔除
|
|
916
|
+
* - 抽稀后若指定 maxLeg,对超过 maxLeg 的腿在原始轨迹上均匀补点,保证航路点密度
|
|
916
917
|
* @param coordinates 原始坐标序列
|
|
917
|
-
* @param
|
|
918
|
-
* @param
|
|
918
|
+
* @param epsilon 最大允许横向偏差阈值(nm),默认 1
|
|
919
|
+
* @param maxLeg 最大允许腿长(nm),默认 0 不限制
|
|
919
920
|
*/
|
|
920
|
-
static simplifyCoordinates(t, e = 1, n =
|
|
921
|
+
static simplifyCoordinates(t, e = 1, n = 0) {
|
|
921
922
|
if (t.length <= 2)
|
|
922
923
|
return [...t];
|
|
923
|
-
const s =
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
924
|
+
const s = v.rdpSimplify(t, e), i = (n > 0 ? v.splitLongLegs(t, s, n) : s).map((r) => t[r]);
|
|
925
|
+
return X.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)", t.length, i.length, e, n), i;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* RDP 主循环:首尾点与强制标记点作为锚点分段,段内迭代栈求最大横向偏差
|
|
929
|
+
* @param coordinates 原始坐标序列
|
|
930
|
+
* @param epsilon 最大允许横向偏差阈值(nm)
|
|
931
|
+
* @returns 升序保留点索引数组
|
|
932
|
+
*/
|
|
933
|
+
static rdpSimplify(t, e) {
|
|
934
|
+
const n = new Array(t.length).fill(!1);
|
|
935
|
+
n[0] = !0, n[t.length - 1] = !0;
|
|
936
|
+
const s = [0];
|
|
937
|
+
for (let o = 1; o < t.length - 1; o++) {
|
|
938
|
+
const a = t[o];
|
|
939
|
+
(a.important || a.pilot || a.suspend || a.velocity || a.gcToPrevious) && (n[o] = !0, s.push(o));
|
|
940
|
+
}
|
|
941
|
+
s.push(t.length - 1);
|
|
942
|
+
const c = t.map((o) => v.toUnitVector(o)), i = T.convertLength(1, "radians", "nauticalmiles");
|
|
943
|
+
for (let o = 0; o < s.length - 1; o++) {
|
|
944
|
+
const a = [[s[o], s[o + 1]]];
|
|
945
|
+
for (; a.length; ) {
|
|
946
|
+
const [l, u] = a.pop(), g = c[l], d = c[u];
|
|
947
|
+
let p = g[1] * d[2] - g[2] * d[1], h = g[2] * d[0] - g[0] * d[2], m = g[0] * d[1] - g[1] * d[0];
|
|
948
|
+
const S = Math.sqrt(p * p + h * h + m * m), b = S < 1e-12;
|
|
949
|
+
b || (p /= S, h /= S, m /= S);
|
|
950
|
+
let x = 0, y = -1;
|
|
951
|
+
for (let M = l + 1; M < u; M++) {
|
|
952
|
+
const D = b ? v.calculateDistance(t[M], t[l]) : Math.asin(Math.min(1, Math.abs(c[M][0] * p + c[M][1] * h + c[M][2] * m))) * i;
|
|
953
|
+
D > x && (x = D, y = M);
|
|
954
|
+
}
|
|
955
|
+
x > e && (n[y] = !0, a.push([l, y], [y, u]));
|
|
930
956
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
957
|
+
}
|
|
958
|
+
const r = [];
|
|
959
|
+
for (let o = 0; o < n.length; o++)
|
|
960
|
+
n[o] && r.push(o);
|
|
961
|
+
return r;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* 最大腿长后处理:超过 maxLeg 的腿按腿内原始点累计里程均分为 ceil(leg/maxLeg) 段取点
|
|
965
|
+
* @param coordinates 原始坐标序列
|
|
966
|
+
* @param keptIndices RDP 保留点索引(升序)
|
|
967
|
+
* @param maxLeg 最大允许腿长(nm)
|
|
968
|
+
* @returns 补点后的升序索引数组
|
|
969
|
+
*/
|
|
970
|
+
static splitLongLegs(t, e, n) {
|
|
971
|
+
const s = [e[0]];
|
|
972
|
+
for (let c = 1; c < e.length; c++) {
|
|
973
|
+
const i = s[s.length - 1], r = e[c], o = v.calculateDistance(t[i], t[r]);
|
|
974
|
+
if (o > n && r - i >= 2) {
|
|
975
|
+
const a = Math.ceil(o / n), l = [0];
|
|
976
|
+
for (let u = i + 1; u <= r; u++)
|
|
977
|
+
l.push(l[l.length - 1] + v.calculateDistance(t[u - 1], t[u]));
|
|
978
|
+
for (let u = 1; u < a; u++) {
|
|
979
|
+
const g = o / a * u;
|
|
980
|
+
let d = i + 1;
|
|
981
|
+
for (; d < r - 1 && l[d - i] < g; )
|
|
982
|
+
d++;
|
|
983
|
+
d > i && d < r && s[s.length - 1] !== d && s.push(d);
|
|
984
|
+
}
|
|
938
985
|
}
|
|
939
|
-
s.push(r)
|
|
986
|
+
s.push(r);
|
|
940
987
|
}
|
|
941
|
-
return s
|
|
988
|
+
return s;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* 经纬度转三维单位向量
|
|
992
|
+
* @param c 坐标 {lng, lat}
|
|
993
|
+
* @returns [x, y, z] 单位向量
|
|
994
|
+
*/
|
|
995
|
+
static toUnitVector(t) {
|
|
996
|
+
const e = t.lat * Math.PI / 180, n = t.lng * Math.PI / 180;
|
|
997
|
+
return [Math.cos(e) * Math.cos(n), Math.cos(e) * Math.sin(n), Math.sin(e)];
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* 计算点 p 相对弦 start->end 的横向偏差(真实球面大圆偏差,天然兼容跨180°经线)
|
|
1001
|
+
* @param p 待测点
|
|
1002
|
+
* @param start 弦起点
|
|
1003
|
+
* @param end 弦终点
|
|
1004
|
+
* @returns {number} 单位 nm
|
|
1005
|
+
*/
|
|
1006
|
+
static perpendicularDeviation(t, e, n) {
|
|
1007
|
+
const s = v.toUnitVector(e), c = v.toUnitVector(n), i = v.toUnitVector(t);
|
|
1008
|
+
let r = s[1] * c[2] - s[2] * c[1], o = s[2] * c[0] - s[0] * c[2], a = s[0] * c[1] - s[1] * c[0];
|
|
1009
|
+
const l = Math.sqrt(r * r + o * o + a * a);
|
|
1010
|
+
if (l < 1e-12)
|
|
1011
|
+
return v.calculateDistance(t, e);
|
|
1012
|
+
r /= l, o /= l, a /= l;
|
|
1013
|
+
const u = T.convertLength(1, "radians", "nauticalmiles");
|
|
1014
|
+
return Math.asin(Math.min(1, Math.abs(i[0] * r + i[1] * o + i[2] * a))) * u;
|
|
942
1015
|
}
|
|
943
1016
|
/**
|
|
944
1017
|
* 在时间轨迹上寻找ts最近的点
|
|
@@ -947,7 +1020,7 @@ class b {
|
|
|
947
1020
|
* @param waypoints 带时间的轨迹, 单位秒
|
|
948
1021
|
*/
|
|
949
1022
|
static nearestTSPointInWaypoints(t, e, n) {
|
|
950
|
-
const s =
|
|
1023
|
+
const s = P.unix(t), c = n.filter(
|
|
951
1024
|
(i) => s.clone().subtract(e, "hour").unix() <= (i.positionTime || 0) && s.clone().add(e, "h").unix() >= (i.positionTime || 0)
|
|
952
1025
|
);
|
|
953
1026
|
return c.sort((i, r) => (i.positionTime || 0) - (r.positionTime || 0)), c.at(-1);
|
|
@@ -960,15 +1033,15 @@ class b {
|
|
|
960
1033
|
static deadReckoning(t, e) {
|
|
961
1034
|
var c, i, r, o;
|
|
962
1035
|
t > 1e12 && (t = Math.round(t / 1e3));
|
|
963
|
-
const n =
|
|
1036
|
+
const n = P.unix(t);
|
|
964
1037
|
let s = e.find((a) => a.positionTime === n.unix());
|
|
965
1038
|
if (!s) {
|
|
966
1039
|
const a = (i = (c = e.filter((u) => (u == null ? void 0 : u.positionTime) < n.unix())) == null ? void 0 : c.sort((u, g) => (u.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : i.at(-1), l = (o = (r = e.filter((u) => (u == null ? void 0 : u.positionTime) > n.unix())) == null ? void 0 : r.sort((u, g) => (u.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : o.at(0);
|
|
967
1040
|
if (a && l) {
|
|
968
|
-
const u =
|
|
969
|
-
s =
|
|
1041
|
+
const u = v.calculateBearing(a, l, !0), g = v.calculateDistance(a, l), d = (n.unix() - a.positionTime) / (l.positionTime - a.positionTime);
|
|
1042
|
+
s = v.calculateCoordinate(a, u, g * d), s.positionTime = n.unix(), s.utc = n.utc().format(), s.cog = u, s.sog = Math.round(g / ((l.positionTime - a.positionTime) / 3600) * 100) / 100;
|
|
970
1043
|
} else
|
|
971
|
-
s = a || l, s && (s.utc =
|
|
1044
|
+
s = a || l, s && (s.utc = P.unix(s == null ? void 0 : s.positionTime).utc().format());
|
|
972
1045
|
}
|
|
973
1046
|
return s;
|
|
974
1047
|
}
|
|
@@ -981,19 +1054,19 @@ class b {
|
|
|
981
1054
|
e = JSON.parse(JSON.stringify(e)), e.sort((a, l) => (a.positionTime || 0) - (l.positionTime || 0));
|
|
982
1055
|
let n = Number.MAX_SAFE_INTEGER, s = Number.MAX_SAFE_INTEGER;
|
|
983
1056
|
for (let a = 0; a < e.length - 1; a++) {
|
|
984
|
-
const l = e[a], u = e[a + 1], g =
|
|
1057
|
+
const l = e[a], u = e[a + 1], g = v.calculatePointToLineDistance(t, l, u);
|
|
985
1058
|
g < n && (n = g, s = a);
|
|
986
1059
|
}
|
|
987
|
-
const c = e[s], i = e[s + 1], r =
|
|
1060
|
+
const c = e[s], i = e[s + 1], r = v.calculateDistance(c, t), o = v.calculateDistance(i, t);
|
|
988
1061
|
if (r === 0)
|
|
989
1062
|
t = c;
|
|
990
1063
|
else if (o === 0)
|
|
991
1064
|
t = i;
|
|
992
1065
|
else {
|
|
993
|
-
const a = c.positionTime || 0, l = i.positionTime || 0, u =
|
|
1066
|
+
const a = c.positionTime || 0, l = i.positionTime || 0, u = v.calculateDistance(c, i);
|
|
994
1067
|
t.positionTime = Math.round(a + (l - a) * (r / u));
|
|
995
1068
|
}
|
|
996
|
-
return t.utc = t.positionTime ?
|
|
1069
|
+
return t.utc = t.positionTime ? P.unix(t.positionTime).utc().format() : void 0, t.positionTime ? t : void 0;
|
|
997
1070
|
}
|
|
998
1071
|
/**
|
|
999
1072
|
* 翻转轨迹
|
|
@@ -1029,7 +1102,7 @@ class b {
|
|
|
1029
1102
|
*/
|
|
1030
1103
|
static waypoints2RTZ(t, e) {
|
|
1031
1104
|
const s = [];
|
|
1032
|
-
return s.push('<?xml version="1.0" encoding="UTF-8"?>'), s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), s.push(` <routeInfo routeName="${
|
|
1105
|
+
return s.push('<?xml version="1.0" encoding="UTF-8"?>'), s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), s.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), s.push(...v.toRTZWaypoints(e, 6)), s.push("</route>"), s.join(`
|
|
1033
1106
|
`) + `
|
|
1034
1107
|
`;
|
|
1035
1108
|
}
|
|
@@ -1041,7 +1114,7 @@ class b {
|
|
|
1041
1114
|
*/
|
|
1042
1115
|
static waypoints2RTZ10(t, e, n = !0) {
|
|
1043
1116
|
const c = [];
|
|
1044
|
-
return c.push('<?xml version="1.0" encoding="UTF-8"?>'), c.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), c.push(` <routeInfo routeName="${
|
|
1117
|
+
return c.push('<?xml version="1.0" encoding="UTF-8"?>'), c.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), c.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), c.push(...v.toRTZWaypoints(e, 6, n)), c.push("</route>"), c.join(`
|
|
1045
1118
|
`) + `
|
|
1046
1119
|
`;
|
|
1047
1120
|
}
|
|
@@ -1050,20 +1123,20 @@ class b {
|
|
|
1050
1123
|
s.push(" <waypoints>");
|
|
1051
1124
|
for (let c = 0; c < t.length; c++) {
|
|
1052
1125
|
const i = t[c], r = c + 1, o = (i.lat ?? "").toFixed ? i.lat.toFixed(e).padEnd(e + 2, "0") : i.lat, a = (i.lng ?? "").toFixed ? i.lng.toFixed(e).padEnd(e + 2, "0") : i.lng, l = [`id="${r}"`, 'revision="0"'];
|
|
1053
|
-
if (i.name && l.push(`name="${
|
|
1126
|
+
if (i.name && l.push(`name="${v.xmlEscape(i.name)}"`), s.push(` <waypoint ${l.join(" ")}>`), s.push(` <position lat="${v.xmlEscape(o)}" lon="${v.xmlEscape(a)}" />`), c > 0) {
|
|
1054
1127
|
const u = i.gcToPrevious ? "Orthodrome" : "Loxodrome";
|
|
1055
1128
|
s.push(` <leg geometryType="${u}" />`);
|
|
1056
1129
|
}
|
|
1057
1130
|
if (n) {
|
|
1058
1131
|
const u = [];
|
|
1059
|
-
if (i.description && u.push(` <description>${
|
|
1060
|
-
u.push(` <time>${
|
|
1132
|
+
if (i.description && u.push(` <description>${v.xmlEscape(i.description)}</description>`), i.utc)
|
|
1133
|
+
u.push(` <time>${v.xmlEscape(i.utc)}</time>`);
|
|
1061
1134
|
else if (i.positionTime)
|
|
1062
1135
|
try {
|
|
1063
|
-
u.push(` <time>${
|
|
1136
|
+
u.push(` <time>${v.xmlEscape(P.unix(i.positionTime).utc().format())}</time>`);
|
|
1064
1137
|
} catch {
|
|
1065
1138
|
}
|
|
1066
|
-
i.cog !== void 0 && u.push(` <cog>${
|
|
1139
|
+
i.cog !== void 0 && u.push(` <cog>${v.xmlEscape(i.cog)}</cog>`), i.sog !== void 0 && u.push(` <sog>${v.xmlEscape(i.sog)}</sog>`), u.length && (s.push(" <extensions>"), s.push(...u), s.push(" </extensions>"));
|
|
1067
1140
|
}
|
|
1068
1141
|
s.push(" </waypoint>");
|
|
1069
1142
|
}
|
|
@@ -1080,13 +1153,13 @@ class b {
|
|
|
1080
1153
|
X.debug("keep name for waypoints2CSV for legacy compatibility only", t);
|
|
1081
1154
|
const s = (n == null ? void 0 : n.precision) ?? 6, c = e.some((m) => m.name), i = e.some((m) => m.description), r = e.some((m) => m.port != null), o = e.some((m) => m.stbd != null), a = e.some((m) => m.arrRad != null), l = e.some((m) => m.speed != null), u = e.some((m, S) => S > 0 && m.gcToPrevious != null), g = e.some((m) => m.bearing != null), d = e.some((m) => m.distanceFromPrevious != null), p = ["WPT No.", "Latitude", "Longitude"];
|
|
1082
1155
|
c && p.push("Name"), i && p.push("Description"), u && p.push("Leg"), g && p.push("Bearing[deg]"), d && p.push("Distance[NM]"), l && p.push("Speed[kn]"), r && p.push("PORT XTD[NM]"), o && p.push("STBD XTD[NM]"), a && p.push("Arr.Rad[NM]");
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1156
|
+
const h = [];
|
|
1157
|
+
h.push(p.map((m) => v.csvEscapeField(m)).join(","));
|
|
1085
1158
|
for (let m = 0; m < e.length; m++) {
|
|
1086
|
-
const S = e[m],
|
|
1087
|
-
|
|
1159
|
+
const S = e[m], b = [];
|
|
1160
|
+
b.push((m + 1).toString()), b.push(S.lat.toFixed(s)), b.push(S.lng.toFixed(s)), c && b.push(S.name ?? ""), i && b.push(S.description ?? ""), u && b.push(m === 0 ? "" : S.gcToPrevious ? "GC" : "RL"), g && b.push(S.bearing != null ? String(S.bearing) : ""), d && b.push(S.distanceFromPrevious != null ? String(S.distanceFromPrevious) : ""), l && b.push(S.speed != null ? String(S.speed) : ""), r && b.push(S.port != null ? String(S.port) : ""), o && b.push(S.stbd != null ? String(S.stbd) : ""), a && b.push(S.arrRad != null ? String(S.arrRad) : ""), h.push(b.map((x) => v.csvEscapeField(x)).join(","));
|
|
1088
1161
|
}
|
|
1089
|
-
return
|
|
1162
|
+
return h.join(`
|
|
1090
1163
|
`);
|
|
1091
1164
|
}
|
|
1092
1165
|
/**
|
|
@@ -1097,13 +1170,13 @@ class b {
|
|
|
1097
1170
|
* @param options.precision 经纬度分钟小数位数,默认3
|
|
1098
1171
|
*/
|
|
1099
1172
|
static waypoints2JRCCSV(t, e, n) {
|
|
1100
|
-
const s = (n == null ? void 0 : n.precision) ?? 3, c = e.some((
|
|
1173
|
+
const s = (n == null ? void 0 : n.precision) ?? 3, c = e.some((h) => h.name), i = e.some((h) => h.port != null), r = e.some((h) => h.stbd != null), o = e.some((h) => h.arrRad != null), a = e.some((h) => h.speed != null), l = e.some((h, m) => m > 0 && h.gcToPrevious != null), u = e.some((h) => h.rot != null), g = e.some((h) => h.turnRad != null), d = ["// WPT No.", "LAT", "", "", "LON", "", ""];
|
|
1101
1174
|
i && d.push("PORT[NM]"), r && d.push("STBD[NM]"), o && d.push("Arr. Rad[NM]"), a && d.push("Speed[kn]"), l && d.push("Sail(RL/GC)"), u && d.push("ROT[deg/min]"), g && d.push("Turn Rad[NM]"), c && d.push("Name");
|
|
1102
1175
|
const p = [];
|
|
1103
|
-
p.push("// ROUTE SHEET exported by JRC ECDIS."), p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."), p.push(`// ${
|
|
1104
|
-
for (let
|
|
1105
|
-
const m = e[
|
|
1106
|
-
i &&
|
|
1176
|
+
p.push("// ROUTE SHEET exported by JRC ECDIS."), p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."), p.push(`// ${v.xmlEscape(t)}`), p.push(d.join(","));
|
|
1177
|
+
for (let h = 0; h < e.length; h++) {
|
|
1178
|
+
const m = e[h], S = String(h).padStart(3, "0"), b = f.lat2pretty(m.lat, 6), x = f.lng2pretty(m.lng, 6), y = b.degree, M = Number(b.minute).toFixed(s), D = b.direction, E = x.degree, F = Number(x.minute).toFixed(s), $ = x.direction, R = [S, String(y), M, D, String(E), F, $];
|
|
1179
|
+
i && R.push(h === 0 ? "***" : m.port != null ? String(m.port) : "***"), r && R.push(h === 0 ? "***" : m.stbd != null ? String(m.stbd) : "***"), o && R.push(h === 0 ? "***" : m.arrRad != null ? String(m.arrRad) : "***"), a && R.push(h === 0 ? "***" : m.speed != null ? Number(m.speed).toFixed(1).padStart(5, "0") : "***"), l && R.push(h === 0 ? "***" : m.gcToPrevious ? "GC" : "RL"), u && R.push(h === 0 ? "***" : m.rot != null ? String(m.rot) : "***"), g && R.push(h === 0 ? "***" : m.turnRad != null ? String(m.turnRad) : "***"), c && R.push(m.name ?? ""), p.push(R.join(","));
|
|
1107
1180
|
}
|
|
1108
1181
|
return p.join(`
|
|
1109
1182
|
`);
|
|
@@ -1120,26 +1193,26 @@ class b {
|
|
|
1120
1193
|
* @returns Uint8Array 二进制数据,可直接用于 new Blob([result], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
|
|
1121
1194
|
*/
|
|
1122
1195
|
static waypoints2XLSX(t, e, n) {
|
|
1123
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, c = t || "Route", i = e.some((N) => N.name), r = e.some((N) => N.description), o = e.some((N) => N.port != null), a = e.some((N) => N.stbd != null), l = e.some((N) => N.arrRad != null), u = e.some((N) => N.speed != null), g = e.some((N, k) => k > 0 && N.gcToPrevious != null), d = e.some((N) => N.bearing != null), p = e.some((N) => N.distanceFromPrevious != null),
|
|
1124
|
-
i &&
|
|
1196
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, c = t || "Route", i = e.some((N) => N.name), r = e.some((N) => N.description), o = e.some((N) => N.port != null), a = e.some((N) => N.stbd != null), l = e.some((N) => N.arrRad != null), u = e.some((N) => N.speed != null), g = e.some((N, k) => k > 0 && N.gcToPrevious != null), d = e.some((N) => N.bearing != null), p = e.some((N) => N.distanceFromPrevious != null), h = ["WPT No.", "Latitude", "Longitude"];
|
|
1197
|
+
i && h.push("Name"), r && h.push("Description"), g && h.push("Leg"), d && h.push("Bearing[deg]"), p && h.push("Distance[NM]"), u && h.push("Speed[kn]"), o && h.push("PORT XTD[NM]"), a && h.push("STBD XTD[NM]"), l && h.push("Arr.Rad[NM]");
|
|
1125
1198
|
const m = (N) => N == null ? "" : String(N).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1126
|
-
let
|
|
1199
|
+
let b = `<row r="1">${h.map((N, k) => `<c r="${z(k)}1" s="1" t="inlineStr"><is><t>${m(N)}</t></is></c>`).join("")}</row>`;
|
|
1127
1200
|
for (let N = 0; N < e.length; N++) {
|
|
1128
|
-
const k = e[N], j = N + 2, U = [], Z = (
|
|
1129
|
-
|
|
1201
|
+
const k = e[N], j = N + 2, U = [], Z = (q, L) => U.push(`<c r="${z(q)}${j}"><v>${L}</v></c>`), B = (q, L) => U.push(`<c r="${z(q)}${j}" t="inlineStr"><is><t>${m(L)}</t></is></c>`), w = (q, L) => {
|
|
1202
|
+
L != null ? Z(q, L) : B(q, "");
|
|
1130
1203
|
};
|
|
1131
|
-
Z(0, N + 1), B(1,
|
|
1204
|
+
Z(0, N + 1), B(1, f.lat2pretty(k.lat, s).pretty), B(2, f.lng2pretty(k.lng, s).pretty);
|
|
1132
1205
|
let I = 3;
|
|
1133
|
-
i && (B(I, k.name ?? ""), I++), r && (B(I, k.description ?? ""), I++), g && (B(I, N === 0 ? "" : k.gcToPrevious ? "GC" : "RL"), I++), d && (w(I, k.bearing), I++), p && (w(I, k.distanceFromPrevious), I++), u && (w(I, k.speed), I++), o && (w(I, k.port), I++), a && (w(I, k.stbd), I++), l && (w(I, k.arrRad), I++),
|
|
1206
|
+
i && (B(I, k.name ?? ""), I++), r && (B(I, k.description ?? ""), I++), g && (B(I, N === 0 ? "" : k.gcToPrevious ? "GC" : "RL"), I++), d && (w(I, k.bearing), I++), p && (w(I, k.distanceFromPrevious), I++), u && (w(I, k.speed), I++), o && (w(I, k.port), I++), a && (w(I, k.stbd), I++), l && (w(I, k.arrRad), I++), b += `<row r="${j}">${U.join("")}</row>`;
|
|
1134
1207
|
}
|
|
1135
|
-
const
|
|
1208
|
+
const x = "0." + "0".repeat(s), y = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>' + b + "</sheetData></worksheet>", M = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>', D = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>', E = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="' + m(c) + '" sheetId="1" r:id="rId1"/></sheets></workbook>', F = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>', $ = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><numFmts count="1"><numFmt numFmtId="164" formatCode="' + x + '"/></numFmts><fonts count="2"><font><sz val="11"/><name val="Arial"/></font><font><b/><sz val="11"/><name val="Arial"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="2"><border><left/><right/><top/><bottom/><diagonal/></border><border><bottom style="thin"><color auto="1"/></bottom></border></borders><cellStyleXfs count="1"><xf/></cellStyleXfs><cellXfs count="3"><xf/><xf fontId="1" fillId="0" borderId="1" applyFont="1" applyBorder="1"/><xf numFmtId="164" fontId="0" applyNumberFormat="1"/></cellXfs></styleSheet>', R = new TextEncoder();
|
|
1136
1209
|
return _([
|
|
1137
|
-
{ name: "[Content_Types].xml", data:
|
|
1138
|
-
{ name: "_rels/.rels", data:
|
|
1139
|
-
{ name: "xl/workbook.xml", data:
|
|
1140
|
-
{ name: "xl/_rels/workbook.xml.rels", data:
|
|
1141
|
-
{ name: "xl/worksheets/sheet1.xml", data:
|
|
1142
|
-
{ name: "xl/styles.xml", data:
|
|
1210
|
+
{ name: "[Content_Types].xml", data: R.encode(M) },
|
|
1211
|
+
{ name: "_rels/.rels", data: R.encode(D) },
|
|
1212
|
+
{ name: "xl/workbook.xml", data: R.encode(E) },
|
|
1213
|
+
{ name: "xl/_rels/workbook.xml.rels", data: R.encode(F) },
|
|
1214
|
+
{ name: "xl/worksheets/sheet1.xml", data: R.encode(y) },
|
|
1215
|
+
{ name: "xl/styles.xml", data: R.encode($) }
|
|
1143
1216
|
]);
|
|
1144
1217
|
}
|
|
1145
1218
|
/**
|
|
@@ -1179,7 +1252,7 @@ class b {
|
|
|
1179
1252
|
static waypoints2NMEA(t) {
|
|
1180
1253
|
const e = [];
|
|
1181
1254
|
for (let n = 0; n < t.length; n++) {
|
|
1182
|
-
const s = t[n], c =
|
|
1255
|
+
const s = t[n], c = v.decimalToNmeaDm(s.lat, !0), i = v.decimalToNmeaDm(s.lng, !1), r = s.name ? String(s.name).slice(0, 6) : `WPT${(n + 1).toString().padStart(3, "0")}`, o = `GPWPL,${c.dm},${c.dir},${i.dm},${i.dir},${r}`, a = v.nmeaChecksum(o);
|
|
1183
1256
|
e.push(`$${o}*${a}`);
|
|
1184
1257
|
}
|
|
1185
1258
|
return e.join(`\r
|
|
@@ -1199,7 +1272,7 @@ class b {
|
|
|
1199
1272
|
*/
|
|
1200
1273
|
static coordinatesSummary(t, e = 3) {
|
|
1201
1274
|
if (t.length > 1) {
|
|
1202
|
-
const n = t[0], s = t[t.length - 1], c = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ?
|
|
1275
|
+
const n = t[0], s = t[t.length - 1], c = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ? P.unix(n == null ? void 0 : n.positionTime) : P.unix(s == null ? void 0 : s.positionTime), i = (n == null ? void 0 : n.positionTime) > (s == null ? void 0 : s.positionTime) ? P.unix(n == null ? void 0 : n.positionTime) : P.unix(s == null ? void 0 : s.positionTime), r = Math.round(i.diff(c, "hours", !0) * 100) / 100, o = this.generateRouteAccordingToWaypoints(t, !0, !0), a = this.calculateRouteDistance(o), u = K.inspectStoppages(t, e).reduce(
|
|
1203
1276
|
(d, p) => (d.duration += p.duration, d.distance += p.distance, d),
|
|
1204
1277
|
{ hours: 0, distance: 0, spd: 0, duration: 0 }
|
|
1205
1278
|
);
|
|
@@ -1235,21 +1308,21 @@ class b {
|
|
|
1235
1308
|
var l, u, g;
|
|
1236
1309
|
if (!((u = (l = e == null ? void 0 : e.sample) == null ? void 0 : l.hours) != null && u.length))
|
|
1237
1310
|
return { routes: [], hour: void 0 };
|
|
1238
|
-
const n = e.sample.hours.at(0), s =
|
|
1311
|
+
const n = e.sample.hours.at(0), s = P.utc(t), c = P.utc(e.eta), i = s.isAfter(c) ? c : s;
|
|
1239
1312
|
let r = e.sample.all.find((d) => d.eta === i.format());
|
|
1240
1313
|
if (!r) {
|
|
1241
|
-
const d = e.sample.all.filter((M) =>
|
|
1242
|
-
r = (g = this.calculateNextCoordinateAlongRoute(d, d.speed * i.diff(
|
|
1243
|
-
const { cFactor:
|
|
1314
|
+
const d = e.sample.all.filter((M) => P.utc(M.eta).isBefore(i)).at(-1), p = this.calculateSubRoute(d, e.route);
|
|
1315
|
+
r = (g = this.calculateNextCoordinateAlongRoute(d, d.speed * i.diff(P(d.etd), "hours", !0), p)) == null ? void 0 : g.coordinate;
|
|
1316
|
+
const { cFactor: h, cog: m, wxFactor: S, meteo: b } = d, x = Math.round(r.distanceFromPrevious * 1e4) / 1e4, y = Math.round((x + d.distanceFromStart) * 1e4) / 1e4;
|
|
1244
1317
|
r = {
|
|
1245
1318
|
...r,
|
|
1246
|
-
cFactor:
|
|
1319
|
+
cFactor: h,
|
|
1247
1320
|
cog: m,
|
|
1248
1321
|
speed: d.speed,
|
|
1249
1322
|
wxFactor: S,
|
|
1250
1323
|
distanceFromStart: y,
|
|
1251
|
-
distanceFromPrevious:
|
|
1252
|
-
meteo:
|
|
1324
|
+
distanceFromPrevious: x,
|
|
1325
|
+
meteo: b,
|
|
1253
1326
|
eta: i.format(),
|
|
1254
1327
|
etd: i.format()
|
|
1255
1328
|
};
|
|
@@ -1273,10 +1346,10 @@ class b {
|
|
|
1273
1346
|
*/
|
|
1274
1347
|
static pickUTCSampleFromRoute(t, e, n) {
|
|
1275
1348
|
var d;
|
|
1276
|
-
const s = this.calculateSubRoute(e, n), c = this.calculateRouteDistance(s), i = c / e.speed, r =
|
|
1349
|
+
const s = this.calculateSubRoute(e, n), c = this.calculateRouteDistance(s), i = c / e.speed, r = P.utc(t), o = P(e.etd), a = (d = this.calculateNextCoordinateAlongRoute(e, e.speed * r.diff(P(e.etd), "hours", !0), s)) == null ? void 0 : d.coordinate;
|
|
1277
1350
|
a.speed = e.speed;
|
|
1278
1351
|
const l = o.clone().add(a.hourFromPrevious, "hour");
|
|
1279
|
-
a.eta = Math.abs(l.diff(r, "second")) < 2 ? r.format() : l.format(), a.etd = a.eta, a.distanceFromStart = Math.round(a.distanceFromPrevious * 100) / 100, a.distanceToGo = Math.round((c - a.distanceFromStart) * 100) / 100, a.timeToGo = Math.round(o.clone().add(i, "hour").diff(
|
|
1352
|
+
a.eta = Math.abs(l.diff(r, "second")) < 2 ? r.format() : l.format(), a.etd = a.eta, a.distanceFromStart = Math.round(a.distanceFromPrevious * 100) / 100, a.distanceToGo = Math.round((c - a.distanceFromStart) * 100) / 100, a.timeToGo = Math.round(o.clone().add(i, "hour").diff(P(a.etd), "hour") * 100) / 100;
|
|
1280
1353
|
const u = this.calculateRangeWaypoints(e, a, n);
|
|
1281
1354
|
return {
|
|
1282
1355
|
routes: this.generateRouteAccordingToWaypoints(u),
|
|
@@ -1324,37 +1397,37 @@ class b {
|
|
|
1324
1397
|
}));
|
|
1325
1398
|
for (const u of o) {
|
|
1326
1399
|
const g = u.geometry.coordinates, d = this.convertRouteToCoordinates([g]), p = T.bbox(u);
|
|
1327
|
-
for (const { polygon:
|
|
1400
|
+
for (const { polygon: h, bbox: m } of l) {
|
|
1328
1401
|
if (p[0] > m[2] || p[2] < m[0] || p[1] > m[3] || p[3] < m[1])
|
|
1329
1402
|
continue;
|
|
1330
1403
|
let S = [];
|
|
1331
|
-
const
|
|
1332
|
-
(c =
|
|
1333
|
-
const
|
|
1334
|
-
return { lng:
|
|
1404
|
+
const b = T.lineIntersect(u, h);
|
|
1405
|
+
(c = b == null ? void 0 : b.features) != null && c.length && (S = T.getCoords(b.features).map((M) => {
|
|
1406
|
+
const D = T.getCoord(M);
|
|
1407
|
+
return { lng: D[0], lat: D[1] };
|
|
1335
1408
|
}));
|
|
1336
|
-
const
|
|
1409
|
+
const x = [...d];
|
|
1337
1410
|
if (S.length > 0)
|
|
1338
1411
|
for (const y of S)
|
|
1339
|
-
this.mergeCoordinateToWaypoints(y,
|
|
1340
|
-
for (let y = 0; y <
|
|
1341
|
-
const M =
|
|
1342
|
-
for (const
|
|
1343
|
-
const
|
|
1344
|
-
Math.min(
|
|
1345
|
-
Math.min(
|
|
1346
|
-
Math.max(
|
|
1347
|
-
Math.max(
|
|
1412
|
+
this.mergeCoordinateToWaypoints(y, x, !0);
|
|
1413
|
+
for (let y = 0; y < x.length - 1; y++) {
|
|
1414
|
+
const M = x[y], D = x[y + 1], E = this.calculateRangeWaypoints(M, D, [], x), F = this.divideAccordingToLng(E);
|
|
1415
|
+
for (const $ of F) {
|
|
1416
|
+
const R = [
|
|
1417
|
+
Math.min($[0][0], $[$.length - 1][0]),
|
|
1418
|
+
Math.min($[0][1], $[$.length - 1][1]),
|
|
1419
|
+
Math.max($[0][0], $[$.length - 1][0]),
|
|
1420
|
+
Math.max($[0][1], $[$.length - 1][1])
|
|
1348
1421
|
];
|
|
1349
|
-
if (
|
|
1422
|
+
if (R[0] > m[2] || R[2] < m[0] || R[1] > m[3] || R[3] < m[1])
|
|
1350
1423
|
continue;
|
|
1351
|
-
const N = T.lineString(
|
|
1352
|
-
if (T.booleanContains(
|
|
1353
|
-
const k =
|
|
1424
|
+
const N = T.lineString($);
|
|
1425
|
+
if (T.booleanContains(h, N)) {
|
|
1426
|
+
const k = $.map((U) => ({ lng: U[0], lat: U[1] })), j = this.calculateRouteDistance([$]);
|
|
1354
1427
|
a.push({
|
|
1355
1428
|
distance: j,
|
|
1356
1429
|
waypoints: k,
|
|
1357
|
-
eca: (i =
|
|
1430
|
+
eca: (i = h == null ? void 0 : h.properties) == null ? void 0 : i.name
|
|
1358
1431
|
});
|
|
1359
1432
|
}
|
|
1360
1433
|
}
|
|
@@ -1368,7 +1441,7 @@ class b {
|
|
|
1368
1441
|
}
|
|
1369
1442
|
let A;
|
|
1370
1443
|
try {
|
|
1371
|
-
A =
|
|
1444
|
+
A = G.getLogger("vessel");
|
|
1372
1445
|
} catch {
|
|
1373
1446
|
} finally {
|
|
1374
1447
|
}
|
|
@@ -1386,44 +1459,44 @@ class rt {
|
|
|
1386
1459
|
r && r.wind && (r.wind.kts = r.kts);
|
|
1387
1460
|
for (const o of i.forecasts) {
|
|
1388
1461
|
let a;
|
|
1389
|
-
const l = [], u = [], g =
|
|
1390
|
-
for (const
|
|
1391
|
-
const m = o.hours[
|
|
1462
|
+
const l = [], u = [], g = P(o.date).utc(), d = `${i.name}-${o.model}`;
|
|
1463
|
+
for (const h in o == null ? void 0 : o.hours) {
|
|
1464
|
+
const m = o.hours[h];
|
|
1392
1465
|
a = a || m;
|
|
1393
|
-
const S = g.clone().add(Number(
|
|
1466
|
+
const S = g.clone().add(Number(h), "hour"), b = T.point([m.lng, m.lat], {
|
|
1394
1467
|
model: o.model,
|
|
1395
1468
|
name: i.name,
|
|
1396
1469
|
nameCn: i.nameCn,
|
|
1397
1470
|
date: S.format(),
|
|
1398
|
-
hour: Number(
|
|
1471
|
+
hour: Number(h),
|
|
1399
1472
|
format: S.format("MMM-DD/HHmm[Z]"),
|
|
1400
|
-
pressure: m.pressure > 1e4 ?
|
|
1473
|
+
pressure: m.pressure > 1e4 ? f.roundPrecision(m.pressure / 100, 0) : f.roundPrecision(m.pressure, 0),
|
|
1401
1474
|
gusts: m.gusts,
|
|
1402
1475
|
wind: m.wind || {},
|
|
1403
1476
|
movement: m.movement,
|
|
1404
1477
|
category: d,
|
|
1405
1478
|
type: "forecast"
|
|
1406
1479
|
});
|
|
1407
|
-
u.push(
|
|
1480
|
+
u.push(b), l.push(b.geometry.coordinates);
|
|
1408
1481
|
}
|
|
1409
1482
|
const p = {
|
|
1410
1483
|
kts: void 0,
|
|
1411
1484
|
deg: void 0
|
|
1412
1485
|
};
|
|
1413
1486
|
if (r) {
|
|
1414
|
-
const
|
|
1487
|
+
const h = P(r.updated).utc();
|
|
1415
1488
|
if (a) {
|
|
1416
|
-
const S =
|
|
1417
|
-
p.kts = Math.round(S /
|
|
1489
|
+
const S = v.calculateDistance(r, a), b = P(a.utc || a.updated).diff(h, "h", !0);
|
|
1490
|
+
p.kts = Math.round(S / b * 100) / 100, p.deg = v.calculateBearing(r, a, !0, 0);
|
|
1418
1491
|
}
|
|
1419
1492
|
const m = T.point([r.lng, r.lat], {
|
|
1420
1493
|
model: o.model,
|
|
1421
1494
|
name: i.name,
|
|
1422
1495
|
nameCn: i.nameCn,
|
|
1423
|
-
date:
|
|
1496
|
+
date: h.format(),
|
|
1424
1497
|
hour: 0,
|
|
1425
|
-
format:
|
|
1426
|
-
pressure: r.pressure > 1e4 ?
|
|
1498
|
+
format: h.format("MMM-DD/HHmm[Z]"),
|
|
1499
|
+
pressure: r.pressure > 1e4 ? f.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : f.roundPrecision(r.pressure, 0),
|
|
1427
1500
|
wind: r.wind,
|
|
1428
1501
|
movement: p,
|
|
1429
1502
|
category: d,
|
|
@@ -1434,7 +1507,7 @@ class rt {
|
|
|
1434
1507
|
u.unshift(m), l.unshift(m.geometry.coordinates);
|
|
1435
1508
|
}
|
|
1436
1509
|
if (e.features.push(...u), (l == null ? void 0 : l.length) > 1) {
|
|
1437
|
-
const
|
|
1510
|
+
const h = T.lineString(f.convertToMonotonicLng2(l), {
|
|
1438
1511
|
date: (r == null ? void 0 : r.updated) || (g == null ? void 0 : g.format()),
|
|
1439
1512
|
id: i.id || i.name,
|
|
1440
1513
|
model: o.model,
|
|
@@ -1443,21 +1516,21 @@ class rt {
|
|
|
1443
1516
|
type: "forecast",
|
|
1444
1517
|
movement: p
|
|
1445
1518
|
});
|
|
1446
|
-
e.features.push(
|
|
1519
|
+
e.features.push(h);
|
|
1447
1520
|
}
|
|
1448
1521
|
}
|
|
1449
1522
|
}
|
|
1450
|
-
if (e.features.sort((o, a) => o.properties.type === "forecast" && a.properties.type === "forecast" && o.geometry.type === "Point" && a.geometry.type === "Point" ?
|
|
1451
|
-
const o = [], a =
|
|
1523
|
+
if (e.features.sort((o, a) => o.properties.type === "forecast" && a.properties.type === "forecast" && o.geometry.type === "Point" && a.geometry.type === "Point" ? P(o.properties.date).valueOf() - P(a.properties.date).valueOf() : 0), (s = i.history) != null && s.length) {
|
|
1524
|
+
const o = [], a = P(r == null ? void 0 : r.updated).utc(), l = P((c = i.history) == null ? void 0 : c.at(-1).updated).utc(), u = a.diff(l, "h") % 24 > 2 ? 24 : 12;
|
|
1452
1525
|
for (const g of i.history) {
|
|
1453
|
-
const d =
|
|
1526
|
+
const d = P(g.updated).utc(), p = d.isSameOrBefore(a) || d.isSame(l);
|
|
1454
1527
|
p && a.add(-u, "h");
|
|
1455
|
-
const
|
|
1528
|
+
const h = T.point([g.lng, g.lat], {
|
|
1456
1529
|
name: i.name,
|
|
1457
1530
|
nameCn: i.nameCn,
|
|
1458
1531
|
date: d.format(),
|
|
1459
1532
|
format: d.format("MMM-DD/HHmm[Z]"),
|
|
1460
|
-
pressure: g.pressure > 1e4 ?
|
|
1533
|
+
pressure: g.pressure > 1e4 ? f.roundPrecision(g.pressure / 100, 0) : f.roundPrecision(g.pressure, 0),
|
|
1461
1534
|
kts: g.kts,
|
|
1462
1535
|
level: g.type,
|
|
1463
1536
|
type: "history",
|
|
@@ -1466,14 +1539,14 @@ class rt {
|
|
|
1466
1539
|
movement: g.movement,
|
|
1467
1540
|
important: p
|
|
1468
1541
|
});
|
|
1469
|
-
e.features.push(
|
|
1542
|
+
e.features.push(h), o.push(h.geometry.coordinates);
|
|
1470
1543
|
}
|
|
1471
1544
|
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
1472
|
-
const g = T.lineString(
|
|
1545
|
+
const g = T.lineString(f.convertToMonotonicLng2(o), {
|
|
1473
1546
|
name: i.name,
|
|
1474
1547
|
type: "history",
|
|
1475
1548
|
updated: r == null ? void 0 : r.updated,
|
|
1476
|
-
pressure: (r == null ? void 0 : r.pressure) > 1e4 ?
|
|
1549
|
+
pressure: (r == null ? void 0 : r.pressure) > 1e4 ? f.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : f.roundPrecision(r == null ? void 0 : r.pressure, 0),
|
|
1477
1550
|
kts: r == null ? void 0 : r.kts,
|
|
1478
1551
|
level: r == null ? void 0 : r.type
|
|
1479
1552
|
});
|
|
@@ -1492,32 +1565,32 @@ class rt {
|
|
|
1492
1565
|
var c, i, r, o;
|
|
1493
1566
|
const n = (c = t == null ? void 0 : t.data) == null ? void 0 : c.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
|
|
1494
1567
|
for (const a of n) {
|
|
1495
|
-
const l = a.properties.name, u = a.properties.model, g = a.properties.showCircle, d = a.properties.disabled, p =
|
|
1496
|
-
let
|
|
1568
|
+
const l = a.properties.name, u = a.properties.model, g = a.properties.showCircle, d = a.properties.disabled, p = P(a.properties.date).utc();
|
|
1569
|
+
let h = e * 60;
|
|
1497
1570
|
const m = (i = t == null ? void 0 : t.data) == null ? void 0 : i.features.filter(
|
|
1498
|
-
(
|
|
1571
|
+
(x) => x.geometry.type === "Point" && x.properties.type === "forecast" && x.properties.category === `${l}-${u}`
|
|
1499
1572
|
);
|
|
1500
|
-
let S,
|
|
1501
|
-
for (; S = this.pickIndex(m,
|
|
1573
|
+
let S, b = p.clone().add(h, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1574
|
+
for (; S = this.pickIndex(m, b), S <= m.length - 1; ) {
|
|
1502
1575
|
if (S > 0) {
|
|
1503
|
-
const
|
|
1576
|
+
const x = m[S], y = S === 0 ? void 0 : m[S - 1], M = (h / 60 - ((r = y == null ? void 0 : y.properties) == null ? void 0 : r.hour)) / (x.properties.hour - ((o = y == null ? void 0 : y.properties) == null ? void 0 : o.hour)), D = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[0], x.geometry.coordinates[0], M), E = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[1], x.geometry.coordinates[1], M), F = T.point([D, E], {
|
|
1504
1577
|
name: l,
|
|
1505
1578
|
model: u,
|
|
1506
|
-
category:
|
|
1507
|
-
date:
|
|
1508
|
-
format:
|
|
1509
|
-
gusts: this.computeNumber(y == null ? void 0 : y.properties.gusts,
|
|
1510
|
-
hour: this.computeNumber(y == null ? void 0 : y.properties.hour,
|
|
1511
|
-
movement: this.computeNumber(y == null ? void 0 : y.properties.movement,
|
|
1512
|
-
pressure: this.computeNumber(y == null ? void 0 : y.properties.pressure,
|
|
1513
|
-
wind: this.computeNumber(y == null ? void 0 : y.properties.wind,
|
|
1579
|
+
category: x == null ? void 0 : x.properties.category,
|
|
1580
|
+
date: b.format(),
|
|
1581
|
+
format: b.format("MMM-DD/HHmm[Z]"),
|
|
1582
|
+
gusts: this.computeNumber(y == null ? void 0 : y.properties.gusts, x.properties.gusts, M),
|
|
1583
|
+
hour: this.computeNumber(y == null ? void 0 : y.properties.hour, x.properties.hour, M),
|
|
1584
|
+
movement: this.computeNumber(y == null ? void 0 : y.properties.movement, x.properties.movement, M),
|
|
1585
|
+
pressure: this.computeNumber(y == null ? void 0 : y.properties.pressure, x.properties.pressure, M),
|
|
1586
|
+
wind: this.computeNumber(y == null ? void 0 : y.properties.wind, x.properties.wind, M),
|
|
1514
1587
|
type: "forecast",
|
|
1515
1588
|
disabled: d,
|
|
1516
1589
|
showCircle: g
|
|
1517
1590
|
});
|
|
1518
1591
|
s.push(F);
|
|
1519
1592
|
}
|
|
1520
|
-
|
|
1593
|
+
h += e * 60, b = p.clone().add(h, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1521
1594
|
}
|
|
1522
1595
|
}
|
|
1523
1596
|
return s;
|
|
@@ -1547,19 +1620,19 @@ class rt {
|
|
|
1547
1620
|
const { t1: c, t2: i, hr: r, hours: o } = this.tropicalCenterTwin(e, 24, s);
|
|
1548
1621
|
if (c && i) {
|
|
1549
1622
|
if (!s.debug) {
|
|
1550
|
-
const p =
|
|
1551
|
-
if (p > 2 * n &&
|
|
1552
|
-
return A == null || A.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, p,
|
|
1623
|
+
const p = v.calculateDistance(t, c), h = v.calculateDistance(t, i);
|
|
1624
|
+
if (p > 2 * n && h > 2 * n)
|
|
1625
|
+
return A == null || A.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, p, h, {
|
|
1553
1626
|
from: t,
|
|
1554
1627
|
t1: c,
|
|
1555
1628
|
t2: i,
|
|
1556
1629
|
hr: r
|
|
1557
1630
|
}), {};
|
|
1558
1631
|
}
|
|
1559
|
-
const a =
|
|
1632
|
+
const a = v.calculateBearing(t, c), l = v.calculateBearing(c, i), u = Math.abs(a - l);
|
|
1560
1633
|
let g = 0;
|
|
1561
1634
|
u < 180 ? g = u + 90 : u >= 180 && (g = u - 90);
|
|
1562
|
-
const d =
|
|
1635
|
+
const d = v.calculateCoordinate(c, g, n);
|
|
1563
1636
|
return A == null || A.info("[%s] the right tangent position: %j", s.requestId, {
|
|
1564
1637
|
from: t,
|
|
1565
1638
|
t1: c,
|
|
@@ -1586,7 +1659,7 @@ class rt {
|
|
|
1586
1659
|
const { t1: c, t2: i, hr: r, hours: o } = this.tropicalCenterTwin(e, 24, s);
|
|
1587
1660
|
if (c && i) {
|
|
1588
1661
|
if (!s.debug) {
|
|
1589
|
-
const d =
|
|
1662
|
+
const d = v.calculateDistance(t, c), p = v.calculateDistance(t, i);
|
|
1590
1663
|
if (d > 2 * n && p > 2 * n)
|
|
1591
1664
|
return A == null || A.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", s.requestId, d, p, {
|
|
1592
1665
|
from: t,
|
|
@@ -1595,8 +1668,8 @@ class rt {
|
|
|
1595
1668
|
hr: r
|
|
1596
1669
|
}), {};
|
|
1597
1670
|
}
|
|
1598
|
-
const a =
|
|
1599
|
-
return { at:
|
|
1671
|
+
const a = v.calculateBearing(t, c), l = v.calculateBearing(c, i), u = v.calculateDistance(t, c);
|
|
1672
|
+
return { at: v.calculateCoordinate(c, a - l + 180, n < u ? n : u), t1: c, t2: i, hr: Number(r), hours: o };
|
|
1600
1673
|
} else
|
|
1601
1674
|
return A == null || A.info("[%s] no need drift: %j", s.requestId, { from: t, t1: c, t2: i, hr: r }), {};
|
|
1602
1675
|
}
|
|
@@ -1611,24 +1684,24 @@ class rt {
|
|
|
1611
1684
|
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
1612
1685
|
var l, u, g, d, p;
|
|
1613
1686
|
let s = {};
|
|
1614
|
-
(l = t.forecasts) == null || l.forEach((
|
|
1615
|
-
s = { ...
|
|
1687
|
+
(l = t.forecasts) == null || l.forEach((h) => {
|
|
1688
|
+
s = { ...h.hours, ...s };
|
|
1616
1689
|
});
|
|
1617
1690
|
const c = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (s == null ? void 0 : s[(g = Object.keys(s)) == null ? void 0 : g[0]]);
|
|
1618
1691
|
A == null || A.info("[%s] the first tropical center: %j", n.requestId, c);
|
|
1619
|
-
let i = (d = Object.keys(s || {}).filter((
|
|
1620
|
-
i || (i = (p = Object.keys(s || {}).filter((
|
|
1692
|
+
let i = (d = Object.keys(s || {}).filter((h) => Number(h) <= (e < 0 ? 24 : e))) == null ? void 0 : d.at(-1);
|
|
1693
|
+
i || (i = (p = Object.keys(s || {}).filter((h) => Number(h) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : p.at(-1));
|
|
1621
1694
|
const r = s == null ? void 0 : s[i || -1];
|
|
1622
1695
|
A == null || A.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, i);
|
|
1623
|
-
const o = Object.keys(s || {}).filter((
|
|
1624
|
-
for (const
|
|
1625
|
-
a[
|
|
1696
|
+
const o = Object.keys(s || {}).filter((h) => Number(h) <= Number(i)), a = { 0: c };
|
|
1697
|
+
for (const h of o)
|
|
1698
|
+
a[h] = s[h];
|
|
1626
1699
|
return { t1: c, t2: r, hr: Number(i), hours: a };
|
|
1627
1700
|
}
|
|
1628
1701
|
static pickIndex(t, e) {
|
|
1629
1702
|
let n = 0;
|
|
1630
1703
|
for (const s of t) {
|
|
1631
|
-
if (
|
|
1704
|
+
if (P(s.properties.date).isAfter(e))
|
|
1632
1705
|
return n === 0 ? -1 : n;
|
|
1633
1706
|
n++;
|
|
1634
1707
|
}
|
|
@@ -1666,7 +1739,7 @@ typeof globalThis < "u" && typeof globalThis.Buffer > "u" && (globalThis.Buffer
|
|
|
1666
1739
|
});
|
|
1667
1740
|
let O;
|
|
1668
1741
|
try {
|
|
1669
|
-
O =
|
|
1742
|
+
O = G.getLogger("meteo");
|
|
1670
1743
|
} catch {
|
|
1671
1744
|
} finally {
|
|
1672
1745
|
}
|
|
@@ -1695,10 +1768,10 @@ class W {
|
|
|
1695
1768
|
* @param options 步数、单位等选项
|
|
1696
1769
|
*/
|
|
1697
1770
|
static drawCircle(t, e, n, s = {}) {
|
|
1698
|
-
const c = (s == null ? void 0 : s.steps) ?? 64, i = (s == null ? void 0 : s.units) ?? "nauticalmiles", r = (s == null ? void 0 : s.properties) ?? {}, o = T.point([t, e]), a = T.destination(o, n, 90, { units: i }), l =
|
|
1771
|
+
const c = (s == null ? void 0 : s.steps) ?? 64, i = (s == null ? void 0 : s.units) ?? "nauticalmiles", r = (s == null ? void 0 : s.properties) ?? {}, o = T.point([t, e]), a = T.destination(o, n, 90, { units: i }), l = P.utc();
|
|
1699
1772
|
r.id = (s == null ? void 0 : s.id) || l.valueOf().toString();
|
|
1700
1773
|
const u = "circle";
|
|
1701
|
-
return r.name = (s == null ? void 0 : s.name) || `${u}_${l.format()}`, r.radius = n, r.center = [t, e], r.end = a.geometry.coordinates.map((g) =>
|
|
1774
|
+
return r.name = (s == null ? void 0 : s.name) || `${u}_${l.format()}`, r.radius = n, r.center = [t, e], r.end = a.geometry.coordinates.map((g) => f.roundPrecision(g, 9)), r.units = i, r.steps = c, r.shape = "circle", O.info("[%s] draw circle with %j", s == null ? void 0 : s.requestId, r), T.circle(o, n, { steps: c, units: i, properties: r });
|
|
1702
1775
|
}
|
|
1703
1776
|
/**
|
|
1704
1777
|
* 基于turf画矩形,返回GeoJSON Feature<Polygon>
|
|
@@ -1707,11 +1780,11 @@ class W {
|
|
|
1707
1780
|
* @param options 选项
|
|
1708
1781
|
*/
|
|
1709
1782
|
static drawRect(t, e, n = {}) {
|
|
1710
|
-
const s = (n == null ? void 0 : n.properties) ?? {}, c =
|
|
1783
|
+
const s = (n == null ? void 0 : n.properties) ?? {}, c = P.utc();
|
|
1711
1784
|
s.id = (n == null ? void 0 : n.id) || c.valueOf().toString();
|
|
1712
1785
|
const i = "rect";
|
|
1713
|
-
s.name = (n == null ? void 0 : n.name) || `${i}_${c.format()}`, s.start = t.map((l) =>
|
|
1714
|
-
const [r, o] =
|
|
1786
|
+
s.name = (n == null ? void 0 : n.name) || `${i}_${c.format()}`, s.start = t.map((l) => f.roundPrecision(l, 9)), s.end = e.map((l) => f.roundPrecision(l, 9)), s.shape = "rect", O.info("[%s] draw rect with %j", n == null ? void 0 : n.requestId, s);
|
|
1787
|
+
const [r, o] = f.convertToMonotonicLng2([t, e]), a = [Math.min(r[0], o[0]), Math.min(r[1], o[1]), Math.max(r[0], o[0]), Math.max(r[1], o[1])];
|
|
1715
1788
|
return T.bboxPolygon(a, { properties: s });
|
|
1716
1789
|
}
|
|
1717
1790
|
/**
|
|
@@ -1722,11 +1795,11 @@ class W {
|
|
|
1722
1795
|
* @returns
|
|
1723
1796
|
*/
|
|
1724
1797
|
static drawLine(t, e = {}) {
|
|
1725
|
-
const n = (e == null ? void 0 : e.properties) ?? {}, s =
|
|
1798
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = P.utc();
|
|
1726
1799
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1727
1800
|
const c = "line";
|
|
1728
1801
|
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.shape = "line", O.info("[%s] draw line with %j", e == null ? void 0 : e.requestId, n);
|
|
1729
|
-
const i =
|
|
1802
|
+
const i = f.convertToMonotonicLng2(t);
|
|
1730
1803
|
return T.lineString(i, n);
|
|
1731
1804
|
}
|
|
1732
1805
|
/**
|
|
@@ -1736,11 +1809,11 @@ class W {
|
|
|
1736
1809
|
* @returns
|
|
1737
1810
|
*/
|
|
1738
1811
|
static drawPolygon(t, e = {}) {
|
|
1739
|
-
const n = (e == null ? void 0 : e.properties) ?? {}, s =
|
|
1812
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = P.utc();
|
|
1740
1813
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1741
1814
|
const c = "polygon";
|
|
1742
|
-
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.coordinates = t.map((r) => r.map((o) =>
|
|
1743
|
-
const i =
|
|
1815
|
+
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.coordinates = t.map((r) => r.map((o) => f.roundPrecision(o, 9))), n.shape = "polygon", O.info("[%s] draw polygon with %j", e == null ? void 0 : e.requestId, n);
|
|
1816
|
+
const i = f.convertToMonotonicLng2(t);
|
|
1744
1817
|
return T.polygon([i], n);
|
|
1745
1818
|
}
|
|
1746
1819
|
/**
|
|
@@ -1751,7 +1824,7 @@ class W {
|
|
|
1751
1824
|
* @returns
|
|
1752
1825
|
*/
|
|
1753
1826
|
static drawPoint(t, e, n = {}) {
|
|
1754
|
-
const s = (n == null ? void 0 : n.properties) ?? {}, c =
|
|
1827
|
+
const s = (n == null ? void 0 : n.properties) ?? {}, c = P.utc();
|
|
1755
1828
|
s.id = (n == null ? void 0 : n.id) || c.valueOf().toString();
|
|
1756
1829
|
const i = "point";
|
|
1757
1830
|
return s.name = (n == null ? void 0 : n.name) || `${i}_${c.format()}`, s.shape = "point", O.info("[%s] draw point with %j", n == null ? void 0 : n.requestId, s), T.point([e, t], s);
|
|
@@ -1768,7 +1841,7 @@ class W {
|
|
|
1768
1841
|
O.info("[%s] parse circle with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1769
1842
|
const n = t.properties || {};
|
|
1770
1843
|
if (n.shape == "circle") {
|
|
1771
|
-
const i =
|
|
1844
|
+
const i = P.utc();
|
|
1772
1845
|
n.id = (n == null ? void 0 : n.id) || i.valueOf().toString();
|
|
1773
1846
|
const r = n == null ? void 0 : n.id, o = ((s = n == null ? void 0 : n.center) == null ? void 0 : s.length) == 2 ? T.point(n.center) : T.centroid(t);
|
|
1774
1847
|
let a = "center";
|
|
@@ -1798,7 +1871,7 @@ class W {
|
|
|
1798
1871
|
O.info("[%s] parse rect with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1799
1872
|
const n = t.properties || {};
|
|
1800
1873
|
if (n.shape == "rect") {
|
|
1801
|
-
const s =
|
|
1874
|
+
const s = P.utc();
|
|
1802
1875
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1803
1876
|
const c = n == null ? void 0 : n.id, i = t.geometry.coordinates[0], o = ["sw", "nw", "ne", "se"].map((a, l) => {
|
|
1804
1877
|
const u = T.point(i[l]);
|
|
@@ -1819,7 +1892,7 @@ class W {
|
|
|
1819
1892
|
O.info("[%s] parse line with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1820
1893
|
const n = t.properties || {};
|
|
1821
1894
|
if (n.shape == "line") {
|
|
1822
|
-
const s =
|
|
1895
|
+
const s = P.utc();
|
|
1823
1896
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1824
1897
|
const c = n == null ? void 0 : n.id, r = t.geometry.coordinates.map((o, a) => {
|
|
1825
1898
|
const l = `point_${a}`, u = T.point(o);
|
|
@@ -1840,7 +1913,7 @@ class W {
|
|
|
1840
1913
|
O.info("[%s] parse polygon with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1841
1914
|
const n = t.properties || {};
|
|
1842
1915
|
if (n.shape == "polygon") {
|
|
1843
|
-
const s =
|
|
1916
|
+
const s = P.utc();
|
|
1844
1917
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1845
1918
|
const c = n == null ? void 0 : n.id, r = t.geometry.coordinates[0].map((o, a) => {
|
|
1846
1919
|
const l = T.point(o), u = `corner_${a}`;
|
|
@@ -1887,13 +1960,13 @@ class W {
|
|
|
1887
1960
|
for (; l < u; ) {
|
|
1888
1961
|
if (s.getUint32(l, !0) !== 33639248)
|
|
1889
1962
|
throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);
|
|
1890
|
-
const p = s.getUint16(l + 10, !0),
|
|
1963
|
+
const p = s.getUint16(l + 10, !0), h = s.getUint32(l + 20, !0), m = s.getUint16(l + 28, !0), S = s.getUint16(l + 30, !0), b = s.getUint16(l + 32, !0), x = s.getUint32(l + 42, !0), y = c.slice(l + 46, l + 46 + m), M = new TextDecoder().decode(y), D = s.getUint16(x + 26, !0), E = s.getUint16(x + 28, !0), F = x + 30 + D + E, $ = c.slice(F, F + h);
|
|
1891
1964
|
if (p === 0)
|
|
1892
|
-
i.set(M,
|
|
1965
|
+
i.set(M, $);
|
|
1893
1966
|
else if (p === 8) {
|
|
1894
1967
|
if (typeof DecompressionStream < "u") {
|
|
1895
|
-
const
|
|
1896
|
-
N.write(
|
|
1968
|
+
const R = new DecompressionStream("deflate-raw"), N = R.writable.getWriter(), k = R.readable.getReader();
|
|
1969
|
+
N.write($), N.close();
|
|
1897
1970
|
const j = [];
|
|
1898
1971
|
let U = 0;
|
|
1899
1972
|
for (; ; ) {
|
|
@@ -1909,11 +1982,11 @@ class W {
|
|
|
1909
1982
|
i.set(M, Z);
|
|
1910
1983
|
} else if (typeof process < "u" && ((g = process.versions) != null && g.node))
|
|
1911
1984
|
try {
|
|
1912
|
-
i.set(M, W._inflateRawSync(
|
|
1985
|
+
i.set(M, W._inflateRawSync($));
|
|
1913
1986
|
} catch {
|
|
1914
1987
|
}
|
|
1915
1988
|
}
|
|
1916
|
-
l += 46 + m + S +
|
|
1989
|
+
l += 46 + m + S + b;
|
|
1917
1990
|
}
|
|
1918
1991
|
return i;
|
|
1919
1992
|
}
|
|
@@ -1933,35 +2006,35 @@ class W {
|
|
|
1933
2006
|
for (const a of c) {
|
|
1934
2007
|
const l = {}, u = Array.from(a.querySelectorAll("ExtendedData > Data"));
|
|
1935
2008
|
for (const y of u) {
|
|
1936
|
-
const M = y.getAttribute("name"),
|
|
1937
|
-
M &&
|
|
2009
|
+
const M = y.getAttribute("name"), D = (o = (r = y.querySelector("value")) == null ? void 0 : r.textContent) == null ? void 0 : o.trim();
|
|
2010
|
+
M && D !== void 0 && D !== null && (l[M] = D);
|
|
1938
2011
|
}
|
|
1939
|
-
const g =
|
|
1940
|
-
const
|
|
1941
|
-
return [
|
|
2012
|
+
const g = P.utc(), d = Object.keys(l).find((y) => y.toLowerCase().indexOf("name") !== -1), p = d ? l[d] : void 0, h = `${g.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, m = (y) => y.trim().split(/[\s\n]+/).filter((M) => M.length > 0).map((M) => {
|
|
2013
|
+
const D = M.split(",").map(Number);
|
|
2014
|
+
return [D[0], D[1]];
|
|
1942
2015
|
}), S = a.querySelector("LineString > coordinates");
|
|
1943
2016
|
if (S) {
|
|
1944
2017
|
const y = m(S.textContent || "");
|
|
1945
2018
|
if (y.length >= 2) {
|
|
1946
|
-
const M = T.lineString(y, { ...l, shape: "line", id:
|
|
2019
|
+
const M = T.lineString(y, { ...l, shape: "line", id: h, name: p });
|
|
1947
2020
|
i.push(M);
|
|
1948
2021
|
}
|
|
1949
2022
|
continue;
|
|
1950
2023
|
}
|
|
1951
|
-
const
|
|
1952
|
-
if (
|
|
1953
|
-
const y = m(
|
|
2024
|
+
const b = a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");
|
|
2025
|
+
if (b) {
|
|
2026
|
+
const y = m(b.textContent || "");
|
|
1954
2027
|
if (y.length >= 4) {
|
|
1955
|
-
const M = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]],
|
|
1956
|
-
i.push(
|
|
2028
|
+
const M = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]], D = T.polygon([M], { ...l, shape: "polygon", id: h, name: p });
|
|
2029
|
+
i.push(D);
|
|
1957
2030
|
}
|
|
1958
2031
|
continue;
|
|
1959
2032
|
}
|
|
1960
|
-
const
|
|
1961
|
-
if (
|
|
1962
|
-
const y = m(
|
|
2033
|
+
const x = a.querySelector("Point > coordinates");
|
|
2034
|
+
if (x) {
|
|
2035
|
+
const y = m(x.textContent || "");
|
|
1963
2036
|
if (y.length >= 1) {
|
|
1964
|
-
const M = T.point(y[0], { ...l, shape: "point", id:
|
|
2037
|
+
const M = T.point(y[0], { ...l, shape: "point", id: h, name: p });
|
|
1965
2038
|
i.push(M);
|
|
1966
2039
|
}
|
|
1967
2040
|
continue;
|
|
@@ -2021,7 +2094,7 @@ class W {
|
|
|
2021
2094
|
typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
2022
2095
|
const n = await J(t);
|
|
2023
2096
|
if (Array.isArray(n)) {
|
|
2024
|
-
const s = n.flatMap((o) => o.features || []), c =
|
|
2097
|
+
const s = n.flatMap((o) => o.features || []), c = P.utc(), i = (e == null ? void 0 : e.id) || c.valueOf().toString(), r = {
|
|
2025
2098
|
Point: "point",
|
|
2026
2099
|
MultiPoint: "point",
|
|
2027
2100
|
LineString: "line",
|
|
@@ -2033,7 +2106,7 @@ class W {
|
|
|
2033
2106
|
var p;
|
|
2034
2107
|
const l = ((p = o.geometry) == null ? void 0 : p.type) || "", u = r[l] || l.toLowerCase();
|
|
2035
2108
|
o.properties = o.properties || {}, o.properties.shape = u, o.properties.parentId = i, o.properties.id = `${i}_${a}`;
|
|
2036
|
-
const g = Object.keys(o.properties).find((
|
|
2109
|
+
const g = Object.keys(o.properties).find((h) => h.toLowerCase().indexOf("name") !== -1), d = g ? o.properties[g] : void 0;
|
|
2037
2110
|
o.properties.name = d || `${u}_${c.format()}_${a}`;
|
|
2038
2111
|
}), T.featureCollection(s);
|
|
2039
2112
|
}
|
|
@@ -2046,7 +2119,7 @@ class W {
|
|
|
2046
2119
|
export {
|
|
2047
2120
|
K as AisHelper,
|
|
2048
2121
|
W as GeoJsonHelper,
|
|
2049
|
-
|
|
2050
|
-
|
|
2122
|
+
v as LaneHelper,
|
|
2123
|
+
f as LngLatHelper,
|
|
2051
2124
|
rt as TropicalHelper
|
|
2052
2125
|
};
|