@idm-plugin/geo 2.3.1 → 2.3.4
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 +440 -366
- package/dist/index.umd.cjs +8 -6
- package/dist/lane/src/index.d.ts +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as T from "@turf/turf";
|
|
2
|
-
import
|
|
2
|
+
import x from "moment";
|
|
3
3
|
import z 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 h {
|
|
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 = h.convertToStdLng(t);
|
|
15
|
+
const n = V(e, t), s = x().tz(n).utcOffset();
|
|
16
|
+
return h.roundPrecision(s / 60, 1);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* 将时间offset转换为时区,例如:8.5 => +08:30
|
|
@@ -30,18 +30,18 @@ class d {
|
|
|
30
30
|
* @param format
|
|
31
31
|
*/
|
|
32
32
|
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
33
|
-
t =
|
|
33
|
+
t = h.convertToStdLng(t, 6);
|
|
34
34
|
let s = "E";
|
|
35
35
|
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
36
36
|
let o = t * 3600, r, i, c, a, l, u;
|
|
37
|
-
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i =
|
|
38
|
-
const
|
|
37
|
+
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i = h.padNumber(r, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = h.roundPrecision(c, e).toString().padStart(2, "0") : a = h.padNumber(c, 2, 3), o = o - c * 60), l = o / 3600, n.indexOf("M") !== -1 ? u = h.roundPrecision(l, e).toString().padStart(3, "0") : u = h.padNumber(l, 3, 6), Number(i) >= 60 && (a = Number(a) + 1, i = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
38
|
+
const g = `${n.replace(/S+/gi, i).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
39
39
|
return {
|
|
40
40
|
direction: s,
|
|
41
|
-
degree:
|
|
42
|
-
minute:
|
|
43
|
-
second:
|
|
44
|
-
pretty:
|
|
41
|
+
degree: h.roundPrecision(l, e),
|
|
42
|
+
minute: h.roundPrecision(c, e),
|
|
43
|
+
second: h.roundPrecision(r, e),
|
|
44
|
+
pretty: g,
|
|
45
45
|
S: i,
|
|
46
46
|
M: a,
|
|
47
47
|
H: u
|
|
@@ -58,14 +58,14 @@ class d {
|
|
|
58
58
|
let s = "N";
|
|
59
59
|
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
60
60
|
let o = t * 3600, r, i, c, a, l, u;
|
|
61
|
-
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i =
|
|
62
|
-
const
|
|
61
|
+
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i = h.padNumber(r, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = h.roundPrecision(c, e).toString().padStart(2, "0") : a = h.padNumber(c, 2, 3), o = o - c * 60), l = o / 3600, n.indexOf("M") !== -1 ? u = h.roundPrecision(l, e).toString().padStart(2, "0") : u = h.padNumber(l, 2, 6), Number(i) >= 60 && (a = Number(a) + 1, i = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
62
|
+
const g = `${n.replace(/S+/gi, i).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
63
63
|
return {
|
|
64
64
|
direction: s,
|
|
65
|
-
degree:
|
|
66
|
-
minute:
|
|
67
|
-
second:
|
|
68
|
-
pretty:
|
|
65
|
+
degree: h.roundPrecision(l, e),
|
|
66
|
+
minute: h.roundPrecision(c, e),
|
|
67
|
+
second: h.roundPrecision(r, e),
|
|
68
|
+
pretty: g,
|
|
69
69
|
S: i,
|
|
70
70
|
M: a,
|
|
71
71
|
H: u
|
|
@@ -74,7 +74,7 @@ class d {
|
|
|
74
74
|
static str2Lng(t, e = 6) {
|
|
75
75
|
let n;
|
|
76
76
|
if (isNaN(t)) {
|
|
77
|
-
t =
|
|
77
|
+
t = h.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 o = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
@@ -86,12 +86,12 @@ class d {
|
|
|
86
86
|
n = r + i / 60 + c / 3600, s === "W" && (n = n * -1);
|
|
87
87
|
} else
|
|
88
88
|
n = Number(t);
|
|
89
|
-
return
|
|
89
|
+
return h.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 = h.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 o = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
@@ -105,19 +105,19 @@ class d {
|
|
|
105
105
|
s === "S" && (n = n * -1);
|
|
106
106
|
} else
|
|
107
107
|
n = Number(t);
|
|
108
|
-
return
|
|
108
|
+
return h.roundPrecision(n, e);
|
|
109
109
|
}
|
|
110
110
|
static str2LngOrLat(t, e = 6, n = "LAT") {
|
|
111
|
-
t =
|
|
111
|
+
t = h.strReplace(t, n);
|
|
112
112
|
const s = t[t.length - 1].toUpperCase();
|
|
113
113
|
return ["N", "S"].includes(s) ? {
|
|
114
|
-
lat:
|
|
114
|
+
lat: h.str2Lat(t, e)
|
|
115
115
|
} : {
|
|
116
|
-
lng:
|
|
116
|
+
lng: h.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), h.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 d {
|
|
|
160
160
|
* @param dcmPrecision 小数位数
|
|
161
161
|
*/
|
|
162
162
|
static padNumber(t, e = 2, n = 2) {
|
|
163
|
-
const s =
|
|
163
|
+
const s = h.roundPrecision(t - Math.trunc(t), n), o = s >= 1 ? Math.trunc(t + 1).toString().padStart(e, "0") : Math.trunc(t).toString().padStart(e, "0");
|
|
164
164
|
return s >= 1 ? o : n > 0 ? `${o}.${Math.trunc(s * Math.pow(10, n)).toString().padStart(n, "0")}` : o;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -170,7 +170,7 @@ class K {
|
|
|
170
170
|
return `${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo || {})}|${t.vendor}|${t.deleted}`;
|
|
171
171
|
}
|
|
172
172
|
static str2Json(t) {
|
|
173
|
-
const [e, n, s, o, r, i, c, a, l, u,
|
|
173
|
+
const [e, n, s, o, r, i, c, a, l, u, g] = t.split("|");
|
|
174
174
|
return {
|
|
175
175
|
lat: Number(e),
|
|
176
176
|
lng: Number(n),
|
|
@@ -184,7 +184,7 @@ class K {
|
|
|
184
184
|
important: a !== "A",
|
|
185
185
|
meteo: l ? JSON.parse(l) : void 0,
|
|
186
186
|
vendor: u,
|
|
187
|
-
deleted:
|
|
187
|
+
deleted: g === "true"
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
static inspectStoppages(t, e = 1, n = !0) {
|
|
@@ -198,12 +198,12 @@ class K {
|
|
|
198
198
|
const a = t[c];
|
|
199
199
|
if (!(n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))) {
|
|
200
200
|
for (let l = c + 1; l < t.length; l++) {
|
|
201
|
-
const u = t[l - 1],
|
|
201
|
+
const u = t[l - 1], g = t[l];
|
|
202
202
|
if (n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))
|
|
203
203
|
continue;
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
r || (r = a), l === t.length - 1 && (i =
|
|
204
|
+
const d = g.positionTime - u.positionTime;
|
|
205
|
+
if (b.calculateDistance(g, u, !0, 4) / (d / 3600) < e)
|
|
206
|
+
r || (r = a), l === t.length - 1 && (i = g, c = l);
|
|
207
207
|
else {
|
|
208
208
|
r && (i = t[l - 1], c = l);
|
|
209
209
|
break;
|
|
@@ -216,18 +216,18 @@ class K {
|
|
|
216
216
|
lng: r.lng,
|
|
217
217
|
sog: r.sog,
|
|
218
218
|
positionTime: r.positionTime,
|
|
219
|
-
utc:
|
|
219
|
+
utc: x.unix(r.positionTime).utc().format()
|
|
220
220
|
},
|
|
221
221
|
end: {
|
|
222
222
|
lat: i.lat,
|
|
223
223
|
lng: i.lng,
|
|
224
224
|
sog: i.sog,
|
|
225
225
|
positionTime: i.positionTime,
|
|
226
|
-
utc:
|
|
226
|
+
utc: x.unix(i.positionTime).utc().format()
|
|
227
227
|
},
|
|
228
228
|
duration: i.positionTime - r.positionTime
|
|
229
|
-
}, u = t.filter((
|
|
230
|
-
l.distance =
|
|
229
|
+
}, u = t.filter((d) => d.positionTime >= l.start.positionTime && d.positionTime <= l.end.positionTime), g = b.divideAccordingToLng(u);
|
|
230
|
+
l.distance = b.calculateRouteDistance(g), l.hours = Math.round(l.duration / 3600 * 10) / 10, l.hours && (l.avgSog = Math.round(l.distance / l.hours * 10) / 10, o.push(l));
|
|
231
231
|
}
|
|
232
232
|
r = void 0, i = void 0;
|
|
233
233
|
}
|
|
@@ -241,21 +241,21 @@ class K {
|
|
|
241
241
|
* @param etm
|
|
242
242
|
*/
|
|
243
243
|
static inspectSummary(t, e, n) {
|
|
244
|
-
const s =
|
|
244
|
+
const s = x(e), o = x(n), r = t.filter((l) => l.positionTime >= s.unix() && l.positionTime <= o.unix());
|
|
245
245
|
let i = 0, c = 0;
|
|
246
246
|
if (r.length > 1)
|
|
247
247
|
for (let l = 0; l < r.length - 1; l++) {
|
|
248
|
-
const u = r[l],
|
|
249
|
-
i +=
|
|
248
|
+
const u = r[l], g = r[l + 1];
|
|
249
|
+
i += b.calculateDistance(u, g, !0, 4), c += Math.abs(g.positionTime - u.positionTime);
|
|
250
250
|
}
|
|
251
251
|
i = Math.round(i * 100) / 100, c = Math.round(c / 3600 * 100) / 100;
|
|
252
252
|
const a = c ? Math.round(i / c * 100) / 100 : 0;
|
|
253
253
|
return { distance: i, interval: c, avgSpd: a };
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
let
|
|
256
|
+
let Z;
|
|
257
257
|
try {
|
|
258
|
-
|
|
258
|
+
Z = z.getLogger("meteo");
|
|
259
259
|
} catch {
|
|
260
260
|
} finally {
|
|
261
261
|
}
|
|
@@ -278,25 +278,25 @@ function Q(C) {
|
|
|
278
278
|
function _(C) {
|
|
279
279
|
const t = new TextEncoder(), e = [], n = [];
|
|
280
280
|
let s = 0;
|
|
281
|
-
for (const
|
|
282
|
-
const p = t.encode(
|
|
283
|
-
|
|
281
|
+
for (const d of C) {
|
|
282
|
+
const p = t.encode(d.name), f = 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, f, !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: f, offset: s }), s += m.length + d.data.length, n.push(m, d.data);
|
|
284
284
|
}
|
|
285
285
|
const o = s, r = [];
|
|
286
286
|
let i = 0;
|
|
287
|
-
for (const
|
|
288
|
-
const p = new Uint8Array(46 +
|
|
289
|
-
f.setUint32(0, 33639248, !0), f.setUint16(4, 20, !0), f.setUint16(6, 20, !0), f.setUint16(10, 0, !0), f.setUint32(16,
|
|
287
|
+
for (const d of e) {
|
|
288
|
+
const p = new Uint8Array(46 + d.nameBytes.length), f = new DataView(p.buffer);
|
|
289
|
+
f.setUint32(0, 33639248, !0), f.setUint16(4, 20, !0), f.setUint16(6, 20, !0), f.setUint16(10, 0, !0), f.setUint32(16, d.crc, !0), f.setUint32(20, d.data.length, !0), f.setUint32(24, d.data.length, !0), f.setUint16(28, d.nameBytes.length, !0), f.setUint32(42, d.offset, !0), p.set(d.nameBytes, 46), i += p.length, r.push(p);
|
|
290
290
|
}
|
|
291
291
|
const c = new Uint8Array(22), a = new DataView(c.buffer);
|
|
292
292
|
a.setUint32(0, 101010256, !0), a.setUint16(8, e.length, !0), a.setUint16(10, e.length, !0), a.setUint32(12, i, !0), a.setUint32(16, o, !0);
|
|
293
|
-
const l = n.reduce((
|
|
294
|
-
let
|
|
295
|
-
for (const
|
|
296
|
-
u.set(
|
|
297
|
-
for (const
|
|
298
|
-
u.set(
|
|
299
|
-
return u.set(c,
|
|
293
|
+
const l = n.reduce((d, p) => d + p.length, 0) + i + 22, u = new Uint8Array(l);
|
|
294
|
+
let g = 0;
|
|
295
|
+
for (const d of n)
|
|
296
|
+
u.set(d, g), g += d.length;
|
|
297
|
+
for (const d of r)
|
|
298
|
+
u.set(d, g), g += d.length;
|
|
299
|
+
return u.set(c, g), u;
|
|
300
300
|
}
|
|
301
301
|
function G(C) {
|
|
302
302
|
let t = "", e = C;
|
|
@@ -304,7 +304,7 @@ function G(C) {
|
|
|
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 b {
|
|
308
308
|
/**
|
|
309
309
|
* 计算方位角
|
|
310
310
|
* @param from 坐标 {lng, lat}
|
|
@@ -319,7 +319,7 @@ class v {
|
|
|
319
319
|
[e.lng, e.lat]
|
|
320
320
|
]);
|
|
321
321
|
let r;
|
|
322
|
-
return n ? r = T.rhumbBearing(o.features[0], o.features[1]) : r = T.bearing(o.features[0], o.features[1]), r < 0 && (r += 360),
|
|
322
|
+
return n ? r = T.rhumbBearing(o.features[0], o.features[1]) : r = T.bearing(o.features[0], o.features[1]), r < 0 && (r += 360), h.roundPrecision(r, s);
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
325
|
* 计算两点间距离
|
|
@@ -331,13 +331,13 @@ class v {
|
|
|
331
331
|
* @returns {number}
|
|
332
332
|
*/
|
|
333
333
|
static calculateDistance(t, e, n = !0, s = 4, o = "nauticalmiles") {
|
|
334
|
-
t = { ...t }, e = { ...e }, t.lng =
|
|
334
|
+
t = { ...t }, e = { ...e }, t.lng = h.convertToStdLng(t.lng, s), e.lng = h.convertToStdLng(e.lng, s);
|
|
335
335
|
const r = T.points([
|
|
336
336
|
[t.lng, t.lat],
|
|
337
337
|
[e.lng, e.lat]
|
|
338
338
|
]);
|
|
339
339
|
let i;
|
|
340
|
-
return n ? i = T.rhumbDistance(r.features[0], r.features[1], { units: o }) : i = T.distance(r.features[0], r.features[1], { units: o }),
|
|
340
|
+
return n ? i = T.rhumbDistance(r.features[0], r.features[1], { units: o }) : i = T.distance(r.features[0], r.features[1], { units: o }), h.roundPrecision(i, s);
|
|
341
341
|
}
|
|
342
342
|
/**
|
|
343
343
|
* 计算航线距离
|
|
@@ -354,7 +354,7 @@ class v {
|
|
|
354
354
|
const a = { lng: r[i + 1][0], lat: r[i + 1][1] };
|
|
355
355
|
s += this.calculateDistance(c, a, !0, e, n), o = a;
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return h.roundPrecision(s, e);
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
360
|
* 计算坐标(基于方位角和距离)
|
|
@@ -369,7 +369,7 @@ class v {
|
|
|
369
369
|
let i;
|
|
370
370
|
o ? i = T.rhumbDestination(r, n, e, { units: s }) : i = T.destination(r, n, e, { units: s });
|
|
371
371
|
const c = i.geometry.coordinates;
|
|
372
|
-
return { lng:
|
|
372
|
+
return { lng: h.convertToStdLng(c[0], 8), lat: h.roundPrecision(c[1], 8) };
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
375
375
|
* 插值大圆坐标(基于两点方位角和间距)
|
|
@@ -408,23 +408,23 @@ class v {
|
|
|
408
408
|
const o = [];
|
|
409
409
|
let r, i;
|
|
410
410
|
for (let c = 0; c < t.length - 1; c++) {
|
|
411
|
-
r =
|
|
411
|
+
r = h.convertToStdLng(t[c].lng, 8), i = h.convertToStdLng(t[c + 1].lng, 8), t[c].lat = h.roundPrecision(t[c].lat, 8), t[c + 1].lat = h.roundPrecision(t[c + 1].lat, 8), s.push([r, t[c].lat]);
|
|
412
412
|
const a = r - i;
|
|
413
413
|
if (Math.abs(a) > 180) {
|
|
414
|
-
const l =
|
|
414
|
+
const l = h.convertToMonotonicLng2([
|
|
415
415
|
[r, t[c].lat],
|
|
416
416
|
[i, t[c + 1].lat]
|
|
417
417
|
]);
|
|
418
|
-
let u,
|
|
419
|
-
e ? (u = T.lineString(l),
|
|
418
|
+
let u, g;
|
|
419
|
+
e ? (u = T.lineString(l), g = T.lineString([
|
|
420
420
|
[a > 0 ? 180 : -180, 89],
|
|
421
421
|
[a > 0 ? 180 : -180, -89]
|
|
422
|
-
])) : (u = T.greatCircle(l[0], l[1]),
|
|
423
|
-
const
|
|
422
|
+
])) : (u = T.greatCircle(l[0], l[1]), g = T.greatCircle([a > 0 ? 180 : -180, 89], [a > 0 ? 180 : -180, -89]));
|
|
423
|
+
const d = T.lineIntersect(u, g);
|
|
424
424
|
let p;
|
|
425
|
-
if (
|
|
426
|
-
const f = T.getCoord(
|
|
427
|
-
p =
|
|
425
|
+
if (d.features.length) {
|
|
426
|
+
const f = T.getCoord(d.features[0]);
|
|
427
|
+
p = h.roundPrecision(f[1], 8);
|
|
428
428
|
} else
|
|
429
429
|
p = t[c].lat;
|
|
430
430
|
a > 0 ? (s.push([180 - 1e-6, p]), o.push([...s]), s = [], s.push([-(180 - 1e-6), p])) : (s.push([-(180 - 1e-6), p]), o.push([...s]), s = [], s.push([180 - 1e-6, p]));
|
|
@@ -458,10 +458,10 @@ class v {
|
|
|
458
458
|
* @param route 航线[[[lng, lat],[lng, lat]]]
|
|
459
459
|
*/
|
|
460
460
|
static removeCoordinateFromRoute(t, e) {
|
|
461
|
-
t.lng =
|
|
461
|
+
t.lng = h.convertToStdLng(t.lng, 8);
|
|
462
462
|
for (const n of e)
|
|
463
463
|
for (let s = n.length - 1; s >= 0; s--)
|
|
464
|
-
|
|
464
|
+
h.roundPrecision(n[s][0], 8) === t.lng && h.roundPrecision(n[s][1], 8) === h.roundPrecision(t.lat, 8) && n.splice(s, 1);
|
|
465
465
|
return e;
|
|
466
466
|
}
|
|
467
467
|
/**
|
|
@@ -470,9 +470,9 @@ class v {
|
|
|
470
470
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
471
471
|
*/
|
|
472
472
|
static removeCoordinateFromWaypoints(t, e) {
|
|
473
|
-
t.lng =
|
|
473
|
+
t.lng = h.convertToStdLng(t.lng, 8);
|
|
474
474
|
for (let n = e.length - 1; n >= 0; n--)
|
|
475
|
-
|
|
475
|
+
h.roundPrecision(e[n].lng, 8) === t.lng && h.roundPrecision(e[n].lat, 8) === h.roundPrecision(t.lat, 8) && e.splice(n, 1);
|
|
476
476
|
return e;
|
|
477
477
|
}
|
|
478
478
|
/**
|
|
@@ -487,12 +487,12 @@ class v {
|
|
|
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 = h.convertToStdLng(t.lng, 8);
|
|
491
491
|
let n = Number.MAX_VALUE, s = 0, o = 0, r, i;
|
|
492
492
|
return e.forEach((c, a) => {
|
|
493
493
|
for (let l = 0; l < c.length - 1; l++) {
|
|
494
|
-
const u = { lng: c[l][0], lat: c[l][1] },
|
|
495
|
-
n >
|
|
494
|
+
const u = { lng: c[l][0], lat: c[l][1] }, g = { lng: c[l + 1][0], lat: c[l + 1][1] }, d = this.calculatePointToLineDistance(t, u, g);
|
|
495
|
+
n > d && (n = d, o = l, s = a, r = this.calculateDistance(u, t), i = this.calculateDistance(g, t));
|
|
496
496
|
}
|
|
497
497
|
}), r !== 0 && i !== 0 ? e[s].splice(o + 1, 0, [t.lng, t.lat]) : r === 0 ? e[s].splice(o, 1, [t.lng, t.lat]) : i === 0 && e[s].splice(o + 1, 1, [t.lng, t.lat]), e;
|
|
498
498
|
}
|
|
@@ -502,9 +502,9 @@ class v {
|
|
|
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 = h.convertToStdLng(t.lng, 8);
|
|
506
|
+
const n = b.convertRouteToCoordinates(e);
|
|
507
|
+
return n.push(t), b.divideAccordingToLng(n);
|
|
508
508
|
}
|
|
509
509
|
/**
|
|
510
510
|
* 向route头加1个坐标
|
|
@@ -512,8 +512,8 @@ class v {
|
|
|
512
512
|
* @param route
|
|
513
513
|
*/
|
|
514
514
|
static unshiftCoordinateToRoute(t, e) {
|
|
515
|
-
const n =
|
|
516
|
-
return n.unshift(t),
|
|
515
|
+
const n = b.convertRouteToCoordinates(e);
|
|
516
|
+
return n.unshift(t), b.divideAccordingToLng(n);
|
|
517
517
|
}
|
|
518
518
|
/**
|
|
519
519
|
* 合并多个waypoints进航线
|
|
@@ -541,11 +541,11 @@ class v {
|
|
|
541
541
|
return;
|
|
542
542
|
const i = [];
|
|
543
543
|
for (const c of r) {
|
|
544
|
-
if (
|
|
544
|
+
if (h.roundPrecision(e.lng, 8) === h.roundPrecision(c[0], 8) && h.roundPrecision(e.lat, 8) === h.roundPrecision(c[1], 8)) {
|
|
545
545
|
i.push(c), o === 0 && i.push([t.lng, t.lat]), o = 2;
|
|
546
546
|
break;
|
|
547
547
|
}
|
|
548
|
-
o === 1 ? i.push(c) :
|
|
548
|
+
o === 1 ? i.push(c) : h.roundPrecision(t.lng, 8) === h.roundPrecision(c[0], 8) && h.roundPrecision(t.lat, 8) === h.roundPrecision(c[1], 8) && (o = 1, i.push(c));
|
|
549
549
|
}
|
|
550
550
|
i.length && s.push(i);
|
|
551
551
|
}), s;
|
|
@@ -560,9 +560,9 @@ class v {
|
|
|
560
560
|
*/
|
|
561
561
|
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
562
562
|
const o = this.convertRouteToCoordinates(n, 0), r = this.mergeCoordinatesToWaypoints([t, e], o.length ? o : s), i = r.findIndex(
|
|
563
|
-
(l) =>
|
|
563
|
+
(l) => h.roundPrecision(t.lng, 8) === h.roundPrecision(l.lng, 8) && h.roundPrecision(t.lat, 8) === h.roundPrecision(l.lat, 8)
|
|
564
564
|
), c = r.findIndex(
|
|
565
|
-
(l) =>
|
|
565
|
+
(l) => h.roundPrecision(e.lng, 8) === h.roundPrecision(l.lng, 8) && h.roundPrecision(e.lat, 8) === h.roundPrecision(l.lat, 8)
|
|
566
566
|
);
|
|
567
567
|
return r.filter((l, u) => u >= i && u <= c);
|
|
568
568
|
}
|
|
@@ -587,10 +587,10 @@ class v {
|
|
|
587
587
|
* @return [[[lng, lat]]]
|
|
588
588
|
*/
|
|
589
589
|
static calculateSubRoute(t, e) {
|
|
590
|
-
const n =
|
|
591
|
-
|
|
590
|
+
const n = b.convertRouteToCoordinates(e);
|
|
591
|
+
b.mergeCoordinateToWaypoints(t, n, !0), e = b.divideAccordingToLng(n);
|
|
592
592
|
const { segIndex: s, minIndex: o } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
593
|
-
t.lng =
|
|
593
|
+
t.lng = h.convertToStdLng(t.lng);
|
|
594
594
|
const r = [];
|
|
595
595
|
let i = !0;
|
|
596
596
|
for (let c = s; c < e.length; c++)
|
|
@@ -621,7 +621,7 @@ class v {
|
|
|
621
621
|
const a = this.calculatePointToLineDistance(t, i, c);
|
|
622
622
|
n > a && (n = a, s = r);
|
|
623
623
|
}
|
|
624
|
-
t.lng =
|
|
624
|
+
t.lng = h.convertToStdLng(t.lng);
|
|
625
625
|
const o = [t];
|
|
626
626
|
for (let r = s + 1; r < e.length; r++)
|
|
627
627
|
o.push(e[r]);
|
|
@@ -635,14 +635,14 @@ class v {
|
|
|
635
635
|
* @param options
|
|
636
636
|
*/
|
|
637
637
|
static calculatePointToLineDistance(t, e, n, s = { units: "nauticalmiles", method: "geodesic" }) {
|
|
638
|
-
t.lng =
|
|
639
|
-
const o =
|
|
638
|
+
t.lng = h.convertToStdLng(t.lng, 8), e = { ...e }, n = { ...n }, e.lng = h.convertToStdLng(e.lng, 8), n.lng = h.convertToStdLng(n.lng, 8);
|
|
639
|
+
const o = h.convertToMonotonicLng([e, n]);
|
|
640
640
|
e = o[0], n = o[1];
|
|
641
641
|
const r = T.lineString([
|
|
642
642
|
[e.lng, e.lat],
|
|
643
643
|
[n.lng, n.lat]
|
|
644
644
|
]), i = T.pointToLineDistance(T.point([t.lng, t.lat]), r, s), c = T.pointToLineDistance(T.point([t.lng > 0 ? t.lng - 360 : t.lng + 360, t.lat]), r, s);
|
|
645
|
-
return
|
|
645
|
+
return h.roundPrecision(Math.min(i, c), 6);
|
|
646
646
|
}
|
|
647
647
|
/**
|
|
648
648
|
* 计算途经点的COG, Distance等属性
|
|
@@ -653,7 +653,7 @@ class v {
|
|
|
653
653
|
e = this.mergeWaypointsToRoute(t, e);
|
|
654
654
|
for (let n = 0; n < t.length - 1; n++) {
|
|
655
655
|
const s = t[n], o = t[n + 1], r = this.calculateRangeRoute(s, o, e);
|
|
656
|
-
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(r), o.distanceFromStart =
|
|
656
|
+
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(r), o.distanceFromStart = h.roundPrecision((s.distanceFromStart || 0) + o.distanceFromPrevious);
|
|
657
657
|
}
|
|
658
658
|
return t;
|
|
659
659
|
}
|
|
@@ -680,7 +680,7 @@ class v {
|
|
|
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 = h.convertToStdLng(t.lng, 8);
|
|
684
684
|
let s = Number.MAX_VALUE, o = 0, r = 0, i = 0;
|
|
685
685
|
if (e.length < 2)
|
|
686
686
|
e.push(t);
|
|
@@ -692,11 +692,11 @@ class v {
|
|
|
692
692
|
r !== 0 && i !== 0 ? r <= s && o === 0 ? e.unshift(t) : i <= s && o === e.length - 2 ? e.push(t) : e.splice(o + 1, 0, t) : r === 0 ? n ? e.splice(o, 1, t) : e.splice(o + 1, 0, t) : i === 0 && (n ? e.splice(o + 1, 1, t) : e.splice(o + 1, 0, t));
|
|
693
693
|
}
|
|
694
694
|
return e.map((c, a) => {
|
|
695
|
-
c.lng =
|
|
695
|
+
c.lng = h.convertToStdLng(c.lng);
|
|
696
696
|
const l = e[a + 1];
|
|
697
697
|
if (l && ((c.bearing === null || c.bearing === void 0) && ((c.positionTime || 0) > (l.positionTime || 0) ? c.bearing = this.calculateBearing(l, c, !0) : c.bearing = this.calculateBearing(c, l, !0)), c.cog = c.cog || c.bearing, !c.sog && c.positionTime && l.positionTime)) {
|
|
698
|
-
const u = this.calculateDistance(c, l, !0),
|
|
699
|
-
c.sog =
|
|
698
|
+
const u = this.calculateDistance(c, l, !0), g = Math.abs(l.positionTime - c.positionTime) / 3600;
|
|
699
|
+
c.sog = h.roundPrecision(u / g, 2);
|
|
700
700
|
}
|
|
701
701
|
return c;
|
|
702
702
|
});
|
|
@@ -727,7 +727,7 @@ class v {
|
|
|
727
727
|
*/
|
|
728
728
|
static nearestCoordinateInRoute(t, e) {
|
|
729
729
|
const n = T.point([t.lng, t.lat]), o = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]), r = T.lineString(o), i = T.nearestPointOnLine(r, n), c = T.getCoord(i);
|
|
730
|
-
return { lng:
|
|
730
|
+
return { lng: h.roundPrecision(c[0], 8), lat: h.roundPrecision(c[1], 8) };
|
|
731
731
|
}
|
|
732
732
|
/**
|
|
733
733
|
* 计算经过方向上的最后一个waypoint
|
|
@@ -759,39 +759,39 @@ class v {
|
|
|
759
759
|
* @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
|
|
760
760
|
*/
|
|
761
761
|
static calculateNextCoordinateAlongRoute(t, e, n, s = "nauticalmiles") {
|
|
762
|
-
var
|
|
762
|
+
var g;
|
|
763
763
|
const o = t.speed || 12, r = [];
|
|
764
764
|
let i = [], c = !1, a = 0, l = 0, u;
|
|
765
|
-
if (e && n.length ? (r.push(t), n.forEach((
|
|
765
|
+
if (e && n.length ? (r.push(t), n.forEach((d, p) => {
|
|
766
766
|
if (c)
|
|
767
|
-
i.push(
|
|
767
|
+
i.push(d);
|
|
768
768
|
else {
|
|
769
769
|
const f = [];
|
|
770
|
-
let
|
|
771
|
-
for (let
|
|
770
|
+
let m;
|
|
771
|
+
for (let S = 0; S < d.length; S++)
|
|
772
772
|
if (u)
|
|
773
|
-
f.push(
|
|
773
|
+
f.push(d[S]);
|
|
774
774
|
else {
|
|
775
|
-
|
|
776
|
-
const
|
|
777
|
-
if (a +=
|
|
778
|
-
l +=
|
|
775
|
+
m = { lng: d[S][0], lat: d[S][1] };
|
|
776
|
+
const v = this.calculateDistance(t, m, !0, 8, s);
|
|
777
|
+
if (a += v, a < e)
|
|
778
|
+
l += v, v && r.push(m), t = m;
|
|
779
779
|
else {
|
|
780
780
|
if (l = e, a === e)
|
|
781
|
-
u =
|
|
781
|
+
u = m, f.push([u.lng, u.lat]);
|
|
782
782
|
else {
|
|
783
|
-
const P = a - e,
|
|
784
|
-
u = this.calculateCoordinate(
|
|
783
|
+
const P = a - e, y = this.calculateBearing(m, t);
|
|
784
|
+
u = this.calculateCoordinate(m, y, P, s), f.push([u.lng, u.lat]), f.push([m.lng, m.lat]);
|
|
785
785
|
}
|
|
786
786
|
c = !0;
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
|
-
f.length && i.push(f), p === n.length - 1 && !u && (u =
|
|
789
|
+
f.length && i.push(f), p === n.length - 1 && !u && (u = m);
|
|
790
790
|
}
|
|
791
791
|
})) : (i = n, u = { ...t }), u)
|
|
792
|
-
if (r.push(u), u.distanceFromPrevious = Math.round(l * 1e4) / 1e4, u.hourFromPrevious = Math.round(l / o * 1e4) / 1e4, ((
|
|
793
|
-
const
|
|
794
|
-
u.bearing = this.calculateBearing(u,
|
|
792
|
+
if (r.push(u), u.distanceFromPrevious = Math.round(l * 1e4) / 1e4, u.hourFromPrevious = Math.round(l / o * 1e4) / 1e4, ((g = i[0]) == null ? void 0 : g.length) > 1) {
|
|
793
|
+
const d = { lng: i[0][1][0], lat: i[0][1][1] };
|
|
794
|
+
u.bearing = this.calculateBearing(u, d);
|
|
795
795
|
} else
|
|
796
796
|
u.bearing = 0;
|
|
797
797
|
return { coordinate: u, nextRoute: i, prevRoute: r };
|
|
@@ -803,11 +803,11 @@ class v {
|
|
|
803
803
|
* @param to {lng, lat}
|
|
804
804
|
*/
|
|
805
805
|
static nearestCoordinateInLine(t, e, n) {
|
|
806
|
-
const s =
|
|
806
|
+
const s = h.convertToStdLng(t.lng, 6), o = T.point([s, t.lat]), r = h.convertToStdLng(e.lng, 6), i = h.convertToStdLng(n.lng, 6), c = T.lineString([
|
|
807
807
|
[r, e.lat],
|
|
808
808
|
[i, n.lat]
|
|
809
|
-
]), a = T.nearestPointOnLine(c, o), l = T.getCoord(a), u =
|
|
810
|
-
return { lng: u, lat:
|
|
809
|
+
]), a = T.nearestPointOnLine(c, o), l = T.getCoord(a), u = h.roundPrecision(l[0], 6), g = h.roundPrecision(l[1], 6);
|
|
810
|
+
return { lng: u, lat: g, inline: !(u === r && g === e.lat) && !(u === i && g === n.lat) };
|
|
811
811
|
}
|
|
812
812
|
/**
|
|
813
813
|
* 将route转coordinate
|
|
@@ -819,7 +819,7 @@ class v {
|
|
|
819
819
|
let s, o;
|
|
820
820
|
return t.forEach((r) => {
|
|
821
821
|
r.forEach((i) => {
|
|
822
|
-
const c = { lng:
|
|
822
|
+
const c = { lng: h.roundPrecision(i[0], 8), lat: h.roundPrecision(i[1], 8) };
|
|
823
823
|
if (!o)
|
|
824
824
|
n.push(c), o = c;
|
|
825
825
|
else if (o.bearing === void 0 || o.bearing === null)
|
|
@@ -862,9 +862,9 @@ class v {
|
|
|
862
862
|
let n = 0;
|
|
863
863
|
for (let s = 1; s < t.length; s++) {
|
|
864
864
|
const o = t[s - 1], r = t[s];
|
|
865
|
-
r.gcToPrevious ? (o.bearing = this.calculateBearing(o, r, !1), r.distanceFromPrevious = this.calculateDistance(o, r, !1)) : (o.bearing = this.calculateBearing(o, r, !0), r.distanceFromPrevious = this.calculateDistance(o, r, !0)), n =
|
|
865
|
+
r.gcToPrevious ? (o.bearing = this.calculateBearing(o, r, !1), r.distanceFromPrevious = this.calculateDistance(o, r, !1)) : (o.bearing = this.calculateBearing(o, r, !0), r.distanceFromPrevious = this.calculateDistance(o, r, !0)), n = h.roundPrecision(n + r.distanceFromPrevious), r.distanceFromStart = n;
|
|
866
866
|
}
|
|
867
|
-
return t.map((s) => (s.lng =
|
|
867
|
+
return t.map((s) => (s.lng = h.convertToStdLng(s.lng), s));
|
|
868
868
|
}
|
|
869
869
|
/**
|
|
870
870
|
* 计算轨迹中心点
|
|
@@ -875,11 +875,11 @@ class v {
|
|
|
875
875
|
for (const i of t)
|
|
876
876
|
for (const c of i)
|
|
877
877
|
e.push(c);
|
|
878
|
-
const n = T.featureCollection([]), s =
|
|
878
|
+
const n = T.featureCollection([]), s = h.convertToMonotonicLng2(e);
|
|
879
879
|
for (const i of s)
|
|
880
880
|
n.features.push(T.point(i));
|
|
881
881
|
const r = T.center(n).geometry.coordinates;
|
|
882
|
-
return { lng:
|
|
882
|
+
return { lng: h.convertToStdLng(r[0], 8), lat: h.roundPrecision(r[1], 8) };
|
|
883
883
|
}
|
|
884
884
|
/**
|
|
885
885
|
* 计算中心点
|
|
@@ -898,7 +898,7 @@ class v {
|
|
|
898
898
|
for (const o of t)
|
|
899
899
|
for (const r of o)
|
|
900
900
|
e.push(r);
|
|
901
|
-
const n =
|
|
901
|
+
const n = h.convertToMonotonicLng2(e), s = T.lineString(n);
|
|
902
902
|
return T.bbox(s);
|
|
903
903
|
}
|
|
904
904
|
/**
|
|
@@ -921,8 +921,8 @@ class v {
|
|
|
921
921
|
const r = t[o - 1], i = t[o], c = t[o + 1];
|
|
922
922
|
let a = !1, l = !1;
|
|
923
923
|
if ((r.velocity || r.suspend || r.important || r.pilot || o === 1) && (a = !0, s.push(r)), i.gcToPrevious && (a || (a = !0, s.push(r)), l = !0, s.push(i), o++), c) {
|
|
924
|
-
const u =
|
|
925
|
-
Math.round(Math.acos(p) * 180 / Math.PI) < n &&
|
|
924
|
+
const u = b.calculateDistance(r, i, !0), g = b.calculateDistance(i, c, !0), d = b.calculateDistance(r, c, !0), p = (Math.pow(u, 2) + Math.pow(g, 2) - Math.pow(d, 2)) / (2 * u * g);
|
|
925
|
+
Math.round(Math.acos(p) * 180 / Math.PI) < n && d > e && !l && (s.push(i), o++);
|
|
926
926
|
}
|
|
927
927
|
if (o >= t.length - 1) {
|
|
928
928
|
const u = t.at(-1);
|
|
@@ -938,7 +938,7 @@ class v {
|
|
|
938
938
|
* @param waypoints 带时间的轨迹, 单位秒
|
|
939
939
|
*/
|
|
940
940
|
static nearestTSPointInWaypoints(t, e, n) {
|
|
941
|
-
const s =
|
|
941
|
+
const s = x.unix(t), o = n.filter(
|
|
942
942
|
(r) => s.clone().subtract(e, "hour").unix() <= (r.positionTime || 0) && s.clone().add(e, "h").unix() >= (r.positionTime || 0)
|
|
943
943
|
);
|
|
944
944
|
return o.sort((r, i) => (r.positionTime || 0) - (i.positionTime || 0)), o.at(-1);
|
|
@@ -951,15 +951,15 @@ class v {
|
|
|
951
951
|
static deadReckoning(t, e) {
|
|
952
952
|
var o, r, i, c;
|
|
953
953
|
t > 1e12 && (t = Math.round(t / 1e3));
|
|
954
|
-
const n =
|
|
954
|
+
const n = x.unix(t);
|
|
955
955
|
let s = e.find((a) => a.positionTime === n.unix());
|
|
956
956
|
if (!s) {
|
|
957
|
-
const a = (r = (o = e.filter((u) => (u == null ? void 0 : u.positionTime) < n.unix())) == null ? void 0 : o.sort((u,
|
|
957
|
+
const a = (r = (o = e.filter((u) => (u == null ? void 0 : u.positionTime) < n.unix())) == null ? void 0 : o.sort((u, g) => (u.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : r.at(-1), l = (c = (i = e.filter((u) => (u == null ? void 0 : u.positionTime) > n.unix())) == null ? void 0 : i.sort((u, g) => (u.positionTime || 0) - (g.positionTime || 0))) == null ? void 0 : c.at(0);
|
|
958
958
|
if (a && l) {
|
|
959
|
-
const u =
|
|
960
|
-
s =
|
|
959
|
+
const u = b.calculateBearing(a, l, !0), g = b.calculateDistance(a, l), d = (n.unix() - a.positionTime) / (l.positionTime - a.positionTime);
|
|
960
|
+
s = b.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;
|
|
961
961
|
} else
|
|
962
|
-
s = a || l, s && (s.utc =
|
|
962
|
+
s = a || l, s && (s.utc = x.unix(s == null ? void 0 : s.positionTime).utc().format());
|
|
963
963
|
}
|
|
964
964
|
return s;
|
|
965
965
|
}
|
|
@@ -972,19 +972,19 @@ class v {
|
|
|
972
972
|
e = JSON.parse(JSON.stringify(e)), e.sort((a, l) => (a.positionTime || 0) - (l.positionTime || 0));
|
|
973
973
|
let n = Number.MAX_SAFE_INTEGER, s = Number.MAX_SAFE_INTEGER;
|
|
974
974
|
for (let a = 0; a < e.length - 1; a++) {
|
|
975
|
-
const l = e[a], u = e[a + 1],
|
|
976
|
-
|
|
975
|
+
const l = e[a], u = e[a + 1], g = b.calculatePointToLineDistance(t, l, u);
|
|
976
|
+
g < n && (n = g, s = a);
|
|
977
977
|
}
|
|
978
|
-
const o = e[s], r = e[s + 1], i =
|
|
978
|
+
const o = e[s], r = e[s + 1], i = b.calculateDistance(o, t), c = b.calculateDistance(r, t);
|
|
979
979
|
if (i === 0)
|
|
980
980
|
t = o;
|
|
981
981
|
else if (c === 0)
|
|
982
982
|
t = r;
|
|
983
983
|
else {
|
|
984
|
-
const a = o.positionTime || 0, l = r.positionTime || 0, u =
|
|
984
|
+
const a = o.positionTime || 0, l = r.positionTime || 0, u = b.calculateDistance(o, r);
|
|
985
985
|
t.positionTime = Math.round(a + (l - a) * (i / u));
|
|
986
986
|
}
|
|
987
|
-
return t.utc = t.positionTime ?
|
|
987
|
+
return t.utc = t.positionTime ? x.unix(t.positionTime).utc().format() : void 0, t.positionTime ? t : void 0;
|
|
988
988
|
}
|
|
989
989
|
/**
|
|
990
990
|
* 翻转轨迹
|
|
@@ -1020,8 +1020,9 @@ class v {
|
|
|
1020
1020
|
*/
|
|
1021
1021
|
static waypoints2RTZ(t, e) {
|
|
1022
1022
|
const s = [];
|
|
1023
|
-
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="${
|
|
1024
|
-
`)
|
|
1023
|
+
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="${b.xmlEscape(t)}"></routeInfo>`), s.push(...b.toRTZWaypoints(e, 6)), s.push("</route>"), s.join(`
|
|
1024
|
+
`) + `
|
|
1025
|
+
`;
|
|
1025
1026
|
}
|
|
1026
1027
|
/**
|
|
1027
1028
|
* 路径转RTZ 1.0
|
|
@@ -1031,28 +1032,29 @@ class v {
|
|
|
1031
1032
|
*/
|
|
1032
1033
|
static waypoints2RTZ10(t, e, n = !0) {
|
|
1033
1034
|
const o = [];
|
|
1034
|
-
return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${
|
|
1035
|
-
`)
|
|
1035
|
+
return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${b.xmlEscape(t)}"></routeInfo>`), o.push(...b.toRTZWaypoints(e, 6, n)), o.push("</route>"), o.join(`
|
|
1036
|
+
`) + `
|
|
1037
|
+
`;
|
|
1036
1038
|
}
|
|
1037
1039
|
static toRTZWaypoints(t, e = 6, n = !0) {
|
|
1038
1040
|
const s = [];
|
|
1039
1041
|
s.push(" <waypoints>");
|
|
1040
1042
|
for (let o = 0; o < t.length; o++) {
|
|
1041
1043
|
const r = t[o], i = o + 1, c = (r.lat ?? "").toFixed ? r.lat.toFixed(e).padEnd(e + 2, "0") : r.lat, a = (r.lng ?? "").toFixed ? r.lng.toFixed(e).padEnd(e + 2, "0") : r.lng, l = [`id="${i}"`, 'revision="0"'];
|
|
1042
|
-
if (r.name && l.push(`name="${
|
|
1044
|
+
if (r.name && l.push(`name="${b.xmlEscape(r.name)}"`), s.push(` <waypoint ${l.join(" ")}>`), s.push(` <position lat="${b.xmlEscape(c)}" lon="${b.xmlEscape(a)}" />`), o > 0) {
|
|
1043
1045
|
const u = r.gcToPrevious ? "Orthodrome" : "Loxodrome";
|
|
1044
1046
|
s.push(` <leg geometryType="${u}" />`);
|
|
1045
1047
|
}
|
|
1046
1048
|
if (n) {
|
|
1047
1049
|
const u = [];
|
|
1048
|
-
if (r.description && u.push(` <description>${
|
|
1049
|
-
u.push(` <time>${
|
|
1050
|
+
if (r.description && u.push(` <description>${b.xmlEscape(r.description)}</description>`), r.utc)
|
|
1051
|
+
u.push(` <time>${b.xmlEscape(r.utc)}</time>`);
|
|
1050
1052
|
else if (r.positionTime)
|
|
1051
1053
|
try {
|
|
1052
|
-
u.push(` <time>${
|
|
1054
|
+
u.push(` <time>${b.xmlEscape(x.unix(r.positionTime).utc().format())}</time>`);
|
|
1053
1055
|
} catch {
|
|
1054
1056
|
}
|
|
1055
|
-
r.cog !== void 0 && u.push(` <cog>${
|
|
1057
|
+
r.cog !== void 0 && u.push(` <cog>${b.xmlEscape(r.cog)}</cog>`), r.sog !== void 0 && u.push(` <sog>${b.xmlEscape(r.sog)}</sog>`), u.length && (s.push(" <extensions>"), s.push(...u), s.push(" </extensions>"));
|
|
1056
1058
|
}
|
|
1057
1059
|
s.push(" </waypoint>");
|
|
1058
1060
|
}
|
|
@@ -1066,14 +1068,14 @@ class v {
|
|
|
1066
1068
|
* @param options.precision 经纬度小数位数,默认6
|
|
1067
1069
|
*/
|
|
1068
1070
|
static waypoints2CSV(t, e, n) {
|
|
1069
|
-
|
|
1070
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, o = e.some((
|
|
1071
|
-
o && p.push("Name"), r && p.push("Description"), u && p.push("Leg"),
|
|
1071
|
+
Z.debug("keep name for waypoints2CSV for legacy compatibility only", t);
|
|
1072
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, o = e.some((m) => m.name), r = e.some((m) => m.description), i = e.some((m) => m.port != null), c = 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"];
|
|
1073
|
+
o && p.push("Name"), r && p.push("Description"), u && p.push("Leg"), g && p.push("Bearing[deg]"), d && p.push("Distance[NM]"), l && p.push("Speed[kn]"), i && p.push("PORT XTD[NM]"), c && p.push("STBD XTD[NM]"), a && p.push("Arr.Rad[NM]");
|
|
1072
1074
|
const f = [];
|
|
1073
|
-
f.push(p.map((
|
|
1074
|
-
for (let
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1075
|
+
f.push(p.map((m) => b.csvEscapeField(m)).join(","));
|
|
1076
|
+
for (let m = 0; m < e.length; m++) {
|
|
1077
|
+
const S = e[m], v = [];
|
|
1078
|
+
v.push((m + 1).toString()), v.push(S.lat.toFixed(s)), v.push(S.lng.toFixed(s)), o && v.push(S.name ?? ""), r && v.push(S.description ?? ""), u && v.push(m === 0 ? "" : S.gcToPrevious ? "GC" : "RL"), g && v.push(S.bearing != null ? String(S.bearing) : ""), d && v.push(S.distanceFromPrevious != null ? String(S.distanceFromPrevious) : ""), l && v.push(S.speed != null ? String(S.speed) : ""), i && v.push(S.port != null ? String(S.port) : ""), c && v.push(S.stbd != null ? String(S.stbd) : ""), a && v.push(S.arrRad != null ? String(S.arrRad) : ""), f.push(v.map((P) => b.csvEscapeField(P)).join(","));
|
|
1077
1079
|
}
|
|
1078
1080
|
return f.join(`
|
|
1079
1081
|
`);
|
|
@@ -1086,13 +1088,13 @@ class v {
|
|
|
1086
1088
|
* @param options.precision 经纬度分钟小数位数,默认3
|
|
1087
1089
|
*/
|
|
1088
1090
|
static waypoints2JRCCSV(t, e, n) {
|
|
1089
|
-
const s = (n == null ? void 0 : n.precision) ?? 3, o = e.some((f) => f.name), r = e.some((f) => f.port != null), i = e.some((f) => f.stbd != null), c = e.some((f) => f.arrRad != null), a = e.some((f) => f.speed != null), l = e.some((f,
|
|
1090
|
-
r &&
|
|
1091
|
+
const s = (n == null ? void 0 : n.precision) ?? 3, o = e.some((f) => f.name), r = e.some((f) => f.port != null), i = e.some((f) => f.stbd != null), c = e.some((f) => f.arrRad != null), a = e.some((f) => f.speed != null), l = e.some((f, m) => m > 0 && f.gcToPrevious != null), u = e.some((f) => f.rot != null), g = e.some((f) => f.turnRad != null), d = ["// WPT No.", "LAT", "", "", "LON", "", ""];
|
|
1092
|
+
r && d.push("PORT[NM]"), i && d.push("STBD[NM]"), c && 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]"), o && d.push("Name");
|
|
1091
1093
|
const p = [];
|
|
1092
|
-
p.push("// ROUTE SHEET exported by JRC ECDIS."), p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."), p.push(`// ${
|
|
1094
|
+
p.push("// ROUTE SHEET exported by JRC ECDIS."), p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."), p.push(`// ${b.xmlEscape(t)}`), p.push(d.join(","));
|
|
1093
1095
|
for (let f = 0; f < e.length; f++) {
|
|
1094
|
-
const
|
|
1095
|
-
r &&
|
|
1096
|
+
const m = e[f], S = String(f).padStart(3, "0"), v = h.lat2pretty(m.lat, 6), P = h.lng2pretty(m.lng, 6), y = v.degree, N = Number(v.minute).toFixed(s), $ = v.direction, E = P.degree, F = Number(P.minute).toFixed(s), R = P.direction, D = [S, String(y), N, $, String(E), F, R];
|
|
1097
|
+
r && D.push(f === 0 ? "***" : m.port != null ? String(m.port) : "***"), i && D.push(f === 0 ? "***" : m.stbd != null ? String(m.stbd) : "***"), c && D.push(f === 0 ? "***" : m.arrRad != null ? String(m.arrRad) : "***"), a && D.push(f === 0 ? "***" : m.speed != null ? Number(m.speed).toFixed(1).padStart(5, "0") : "***"), l && D.push(f === 0 ? "***" : m.gcToPrevious ? "GC" : "RL"), u && D.push(f === 0 ? "***" : m.rot != null ? String(m.rot) : "***"), g && D.push(f === 0 ? "***" : m.turnRad != null ? String(m.turnRad) : "***"), o && D.push(m.name ?? ""), p.push(D.join(","));
|
|
1096
1098
|
}
|
|
1097
1099
|
return p.join(`
|
|
1098
1100
|
`);
|
|
@@ -1109,26 +1111,26 @@ class v {
|
|
|
1109
1111
|
* @returns Uint8Array 二进制数据,可直接用于 new Blob([result], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
|
|
1110
1112
|
*/
|
|
1111
1113
|
static waypoints2XLSX(t, e, n) {
|
|
1112
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, o = t || "Route", r = e.some((
|
|
1113
|
-
r && f.push("Name"), i && f.push("Description"),
|
|
1114
|
-
const
|
|
1115
|
-
let
|
|
1116
|
-
for (let
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1114
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, o = t || "Route", r = e.some((M) => M.name), i = e.some((M) => M.description), c = e.some((M) => M.port != null), a = e.some((M) => M.stbd != null), l = e.some((M) => M.arrRad != null), u = e.some((M) => M.speed != null), g = e.some((M, A) => A > 0 && M.gcToPrevious != null), d = e.some((M) => M.bearing != null), p = e.some((M) => M.distanceFromPrevious != null), f = ["WPT No.", "Latitude", "Longitude"];
|
|
1115
|
+
r && f.push("Name"), i && f.push("Description"), g && f.push("Leg"), d && f.push("Bearing[deg]"), p && f.push("Distance[NM]"), u && f.push("Speed[kn]"), c && f.push("PORT XTD[NM]"), a && f.push("STBD XTD[NM]"), l && f.push("Arr.Rad[NM]");
|
|
1116
|
+
const m = (M) => M == null ? "" : String(M).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1117
|
+
let v = `<row r="1">${f.map((M, A) => `<c r="${G(A)}1" s="1" t="inlineStr"><is><t>${m(M)}</t></is></c>`).join("")}</row>`;
|
|
1118
|
+
for (let M = 0; M < e.length; M++) {
|
|
1119
|
+
const A = e[M], j = M + 2, U = [], X = (L, q) => U.push(`<c r="${G(L)}${j}"><v>${q}</v></c>`), B = (L, q) => U.push(`<c r="${G(L)}${j}" t="inlineStr"><is><t>${m(q)}</t></is></c>`), w = (L, q) => {
|
|
1120
|
+
q != null ? X(L, q) : B(L, "");
|
|
1119
1121
|
};
|
|
1120
|
-
|
|
1121
|
-
let
|
|
1122
|
-
r && (
|
|
1122
|
+
X(0, M + 1), B(1, h.lat2pretty(A.lat, s).pretty), B(2, h.lng2pretty(A.lng, s).pretty);
|
|
1123
|
+
let I = 3;
|
|
1124
|
+
r && (B(I, A.name ?? ""), I++), i && (B(I, A.description ?? ""), I++), g && (B(I, M === 0 ? "" : A.gcToPrevious ? "GC" : "RL"), I++), d && (w(I, A.bearing), I++), p && (w(I, A.distanceFromPrevious), I++), u && (w(I, A.speed), I++), c && (w(I, A.port), I++), a && (w(I, A.stbd), I++), l && (w(I, A.arrRad), I++), v += `<row r="${j}">${U.join("")}</row>`;
|
|
1123
1125
|
}
|
|
1124
|
-
const P = "0." + "0".repeat(s),
|
|
1126
|
+
const P = "0." + "0".repeat(s), y = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>' + v + "</sheetData></worksheet>", N = '<?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>', $ = '<?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(o) + '" 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>', R = '<?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="' + P + '"/></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>', D = new TextEncoder();
|
|
1125
1127
|
return _([
|
|
1126
|
-
{ name: "[Content_Types].xml", data:
|
|
1127
|
-
{ name: "_rels/.rels", data:
|
|
1128
|
-
{ name: "xl/workbook.xml", data:
|
|
1129
|
-
{ name: "xl/_rels/workbook.xml.rels", data:
|
|
1130
|
-
{ name: "xl/worksheets/sheet1.xml", data:
|
|
1131
|
-
{ name: "xl/styles.xml", data:
|
|
1128
|
+
{ name: "[Content_Types].xml", data: D.encode(N) },
|
|
1129
|
+
{ name: "_rels/.rels", data: D.encode($) },
|
|
1130
|
+
{ name: "xl/workbook.xml", data: D.encode(E) },
|
|
1131
|
+
{ name: "xl/_rels/workbook.xml.rels", data: D.encode(F) },
|
|
1132
|
+
{ name: "xl/worksheets/sheet1.xml", data: D.encode(y) },
|
|
1133
|
+
{ name: "xl/styles.xml", data: D.encode(R) }
|
|
1132
1134
|
]);
|
|
1133
1135
|
}
|
|
1134
1136
|
/**
|
|
@@ -1168,7 +1170,7 @@ class v {
|
|
|
1168
1170
|
static waypoints2NMEA(t) {
|
|
1169
1171
|
const e = [];
|
|
1170
1172
|
for (let n = 0; n < t.length; n++) {
|
|
1171
|
-
const s = t[n], o =
|
|
1173
|
+
const s = t[n], o = b.decimalToNmeaDm(s.lat, !0), r = b.decimalToNmeaDm(s.lng, !1), i = s.name ? String(s.name).slice(0, 6) : `WPT${(n + 1).toString().padStart(3, "0")}`, c = `GPWPL,${o.dm},${o.dir},${r.dm},${r.dir},${i}`, a = b.nmeaChecksum(c);
|
|
1172
1174
|
e.push(`$${c}*${a}`);
|
|
1173
1175
|
}
|
|
1174
1176
|
return e.join(`\r
|
|
@@ -1188,18 +1190,18 @@ class v {
|
|
|
1188
1190
|
*/
|
|
1189
1191
|
static coordinatesSummary(t, e = 3) {
|
|
1190
1192
|
if (t.length > 1) {
|
|
1191
|
-
const n = t[0], s = t[t.length - 1], o = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ?
|
|
1192
|
-
(
|
|
1193
|
+
const n = t[0], s = t[t.length - 1], o = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ? x.unix(n == null ? void 0 : n.positionTime) : x.unix(s == null ? void 0 : s.positionTime), r = (n == null ? void 0 : n.positionTime) > (s == null ? void 0 : s.positionTime) ? x.unix(n == null ? void 0 : n.positionTime) : x.unix(s == null ? void 0 : s.positionTime), i = Math.round(r.diff(o, "hours", !0) * 100) / 100, c = this.generateRouteAccordingToWaypoints(t, !0, !0), a = this.calculateRouteDistance(c), u = K.inspectStoppages(t, e).reduce(
|
|
1194
|
+
(d, p) => (d.duration += p.duration, d.distance += p.distance, d),
|
|
1193
1195
|
{ hours: 0, distance: 0, spd: 0, duration: 0 }
|
|
1194
1196
|
);
|
|
1195
1197
|
u.hours = Math.round(u.duration / 3600 * 100) / 100, u.distance = Math.round(u.distance * 100) / 100, u.spd = u.hours ? Math.round(u.distance / u.hours * 100) / 100 : 0;
|
|
1196
|
-
const
|
|
1198
|
+
const g = i ? Math.round((a - u.distance) / (i - u.hours) * 100) / 100 : 0;
|
|
1197
1199
|
return {
|
|
1198
1200
|
begin: o.utc().format(),
|
|
1199
1201
|
end: r.utc().format(),
|
|
1200
1202
|
distance: Math.round((a - u.distance) * 100) / 100,
|
|
1201
1203
|
hours: Math.round((i - u.hours) * 100) / 100,
|
|
1202
|
-
avgSpeed:
|
|
1204
|
+
avgSpeed: g,
|
|
1203
1205
|
stoppage: u
|
|
1204
1206
|
};
|
|
1205
1207
|
}
|
|
@@ -1221,24 +1223,24 @@ class v {
|
|
|
1221
1223
|
* }
|
|
1222
1224
|
*/
|
|
1223
1225
|
static pickUTCSampleFromSpeed(t, e) {
|
|
1224
|
-
var l, u,
|
|
1226
|
+
var l, u, g;
|
|
1225
1227
|
if (!((u = (l = e == null ? void 0 : e.sample) == null ? void 0 : l.hours) != null && u.length))
|
|
1226
1228
|
return { routes: [], hour: void 0 };
|
|
1227
|
-
const n = e.sample.hours.at(0), s =
|
|
1228
|
-
let i = e.sample.all.find((
|
|
1229
|
+
const n = e.sample.hours.at(0), s = x.utc(t), o = x.utc(e.eta), r = s.isAfter(o) ? o : s;
|
|
1230
|
+
let i = e.sample.all.find((d) => d.eta === r.format());
|
|
1229
1231
|
if (!i) {
|
|
1230
|
-
const
|
|
1231
|
-
i = (
|
|
1232
|
-
const { cFactor: f, cog:
|
|
1232
|
+
const d = e.sample.all.filter((N) => x.utc(N.eta).isBefore(r)).at(-1), p = this.calculateSubRoute(d, e.route);
|
|
1233
|
+
i = (g = this.calculateNextCoordinateAlongRoute(d, d.speed * r.diff(x(d.etd), "hours", !0), p)) == null ? void 0 : g.coordinate;
|
|
1234
|
+
const { cFactor: f, cog: m, wxFactor: S, meteo: v } = d, P = Math.round(i.distanceFromPrevious * 1e4) / 1e4, y = Math.round((P + d.distanceFromStart) * 1e4) / 1e4;
|
|
1233
1235
|
i = {
|
|
1234
1236
|
...i,
|
|
1235
1237
|
cFactor: f,
|
|
1236
|
-
cog:
|
|
1237
|
-
speed:
|
|
1238
|
-
wxFactor:
|
|
1239
|
-
distanceFromStart:
|
|
1238
|
+
cog: m,
|
|
1239
|
+
speed: d.speed,
|
|
1240
|
+
wxFactor: S,
|
|
1241
|
+
distanceFromStart: y,
|
|
1240
1242
|
distanceFromPrevious: P,
|
|
1241
|
-
meteo:
|
|
1243
|
+
meteo: v,
|
|
1242
1244
|
eta: r.format(),
|
|
1243
1245
|
etd: r.format()
|
|
1244
1246
|
};
|
|
@@ -1261,11 +1263,11 @@ class v {
|
|
|
1261
1263
|
* }
|
|
1262
1264
|
*/
|
|
1263
1265
|
static pickUTCSampleFromRoute(t, e, n) {
|
|
1264
|
-
var
|
|
1265
|
-
const s = this.calculateSubRoute(e, n), o = this.calculateRouteDistance(s), r = o / e.speed, i =
|
|
1266
|
+
var d;
|
|
1267
|
+
const s = this.calculateSubRoute(e, n), o = this.calculateRouteDistance(s), r = o / e.speed, i = x.utc(t), c = x(e.etd), a = (d = this.calculateNextCoordinateAlongRoute(e, e.speed * i.diff(x(e.etd), "hours", !0), s)) == null ? void 0 : d.coordinate;
|
|
1266
1268
|
a.speed = e.speed;
|
|
1267
1269
|
const l = c.clone().add(a.hourFromPrevious, "hour");
|
|
1268
|
-
a.eta = Math.abs(l.diff(i, "second")) < 2 ? i.format() : l.format(), a.etd = a.eta, a.distanceFromStart = Math.round(a.distanceFromPrevious * 100) / 100, a.distanceToGo = Math.round((o - a.distanceFromStart) * 100) / 100, a.timeToGo = Math.round(c.clone().add(r, "hour").diff(
|
|
1270
|
+
a.eta = Math.abs(l.diff(i, "second")) < 2 ? i.format() : l.format(), a.etd = a.eta, a.distanceFromStart = Math.round(a.distanceFromPrevious * 100) / 100, a.distanceToGo = Math.round((o - a.distanceFromStart) * 100) / 100, a.timeToGo = Math.round(c.clone().add(r, "hour").diff(x(a.etd), "hour") * 100) / 100;
|
|
1269
1271
|
const u = this.calculateRangeWaypoints(e, a, n);
|
|
1270
1272
|
return {
|
|
1271
1273
|
routes: this.generateRouteAccordingToWaypoints(u),
|
|
@@ -1278,14 +1280,86 @@ class v {
|
|
|
1278
1280
|
* @param degree 要素角度,如 swell.degree
|
|
1279
1281
|
*/
|
|
1280
1282
|
static includedAngle(t, e) {
|
|
1281
|
-
|
|
1283
|
+
Z == null || Z.debug("calculate bearing via: %j", { bearing: t, degree: e });
|
|
1282
1284
|
let n = Math.abs(t % 360 - (e % 360 || 0));
|
|
1283
1285
|
return n = n > 180 ? 360 - n : n, n;
|
|
1284
1286
|
}
|
|
1287
|
+
/**
|
|
1288
|
+
* 判断路径是否与ECA区域相交
|
|
1289
|
+
* @param path
|
|
1290
|
+
* @param ecaZones
|
|
1291
|
+
* @see https://osshz.idmwx.com/layers/other/eca-zones.json
|
|
1292
|
+
* @return 返回相交的区域
|
|
1293
|
+
* [
|
|
1294
|
+
* {
|
|
1295
|
+
* distance: number,
|
|
1296
|
+
* waypoints: Coordinate[],
|
|
1297
|
+
* name: string
|
|
1298
|
+
* }
|
|
1299
|
+
* ]
|
|
1300
|
+
* 如果没有相交区域,返回空数组。
|
|
1301
|
+
*/
|
|
1302
|
+
static async intersectInECA(t, e) {
|
|
1303
|
+
var o, r;
|
|
1304
|
+
const s = (e instanceof Array ? e : e.features).filter((i) => {
|
|
1305
|
+
var c, a;
|
|
1306
|
+
return ((c = i.geometry) == null ? void 0 : c.type) === "Polygon" && !((a = i.properties) != null && a.disabled);
|
|
1307
|
+
});
|
|
1308
|
+
if (t != null && t.length) {
|
|
1309
|
+
let i = t;
|
|
1310
|
+
t.some((u) => u instanceof Array) ? t = this.convertRouteToCoordinates(t) : i = this.divideAccordingToLng(t);
|
|
1311
|
+
const c = i.map((u) => T.lineString(u)), a = [], l = s.map((u) => ({
|
|
1312
|
+
polygon: u,
|
|
1313
|
+
bbox: T.bbox(u)
|
|
1314
|
+
// [minX, minY, maxX, maxY]
|
|
1315
|
+
}));
|
|
1316
|
+
for (const u of c) {
|
|
1317
|
+
const g = u.geometry.coordinates, d = this.convertRouteToCoordinates([g]), p = T.bbox(u);
|
|
1318
|
+
for (const { polygon: f, bbox: m } of l) {
|
|
1319
|
+
if (p[0] > m[2] || p[2] < m[0] || p[1] > m[3] || p[3] < m[1])
|
|
1320
|
+
continue;
|
|
1321
|
+
let S = [];
|
|
1322
|
+
const v = T.lineIntersect(u, f);
|
|
1323
|
+
(o = v == null ? void 0 : v.features) != null && o.length && (S = T.getCoords(v.features).map((N) => {
|
|
1324
|
+
const $ = T.getCoord(N);
|
|
1325
|
+
return { lng: $[0], lat: $[1] };
|
|
1326
|
+
}));
|
|
1327
|
+
const P = [...d];
|
|
1328
|
+
if (S.length > 0)
|
|
1329
|
+
for (const y of S)
|
|
1330
|
+
this.mergeCoordinateToWaypoints(y, P, !0);
|
|
1331
|
+
for (let y = 0; y < P.length - 1; y++) {
|
|
1332
|
+
const N = P[y], $ = P[y + 1], E = this.calculateRangeWaypoints(N, $, [], P), F = this.divideAccordingToLng(E);
|
|
1333
|
+
for (const R of F) {
|
|
1334
|
+
const D = [
|
|
1335
|
+
Math.min(R[0][0], R[R.length - 1][0]),
|
|
1336
|
+
Math.min(R[0][1], R[R.length - 1][1]),
|
|
1337
|
+
Math.max(R[0][0], R[R.length - 1][0]),
|
|
1338
|
+
Math.max(R[0][1], R[R.length - 1][1])
|
|
1339
|
+
];
|
|
1340
|
+
if (D[0] > m[2] || D[2] < m[0] || D[1] > m[3] || D[3] < m[1])
|
|
1341
|
+
continue;
|
|
1342
|
+
const M = T.lineString(R);
|
|
1343
|
+
if (T.booleanContains(f, M)) {
|
|
1344
|
+
const A = R.map((U) => ({ lng: U[0], lat: U[1] })), j = this.calculateRouteDistance([R]);
|
|
1345
|
+
a.push({
|
|
1346
|
+
distance: j,
|
|
1347
|
+
waypoints: A,
|
|
1348
|
+
eca: (r = f == null ? void 0 : f.properties) == null ? void 0 : r.name
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
return a;
|
|
1356
|
+
}
|
|
1357
|
+
return [];
|
|
1358
|
+
}
|
|
1285
1359
|
}
|
|
1286
|
-
let
|
|
1360
|
+
let k;
|
|
1287
1361
|
try {
|
|
1288
|
-
|
|
1362
|
+
k = z.getLogger("vessel");
|
|
1289
1363
|
} catch {
|
|
1290
1364
|
} finally {
|
|
1291
1365
|
}
|
|
@@ -1303,60 +1377,60 @@ class it {
|
|
|
1303
1377
|
i && i.wind && (i.wind.kts = i.kts);
|
|
1304
1378
|
for (const c of r.forecasts) {
|
|
1305
1379
|
let a;
|
|
1306
|
-
const l = [], u = [],
|
|
1380
|
+
const l = [], u = [], g = x(c.date).utc(), d = `${r.name}-${c.model}`;
|
|
1307
1381
|
for (const f in c == null ? void 0 : c.hours) {
|
|
1308
|
-
const
|
|
1309
|
-
a = a ||
|
|
1310
|
-
const
|
|
1382
|
+
const m = c.hours[f];
|
|
1383
|
+
a = a || m;
|
|
1384
|
+
const S = g.clone().add(Number(f), "hour"), v = T.point([m.lng, m.lat], {
|
|
1311
1385
|
model: c.model,
|
|
1312
1386
|
name: r.name,
|
|
1313
1387
|
nameCn: r.nameCn,
|
|
1314
|
-
date:
|
|
1388
|
+
date: S.format(),
|
|
1315
1389
|
hour: Number(f),
|
|
1316
|
-
format:
|
|
1317
|
-
pressure:
|
|
1318
|
-
gusts:
|
|
1319
|
-
wind:
|
|
1320
|
-
movement:
|
|
1321
|
-
category:
|
|
1390
|
+
format: S.format("MMM-DD/HHmm[Z]"),
|
|
1391
|
+
pressure: m.pressure > 1e4 ? h.roundPrecision(m.pressure / 100, 0) : h.roundPrecision(m.pressure, 0),
|
|
1392
|
+
gusts: m.gusts,
|
|
1393
|
+
wind: m.wind || {},
|
|
1394
|
+
movement: m.movement,
|
|
1395
|
+
category: d,
|
|
1322
1396
|
type: "forecast"
|
|
1323
1397
|
});
|
|
1324
|
-
u.push(
|
|
1398
|
+
u.push(v), l.push(v.geometry.coordinates);
|
|
1325
1399
|
}
|
|
1326
1400
|
const p = {
|
|
1327
1401
|
kts: void 0,
|
|
1328
1402
|
deg: void 0
|
|
1329
1403
|
};
|
|
1330
1404
|
if (i) {
|
|
1331
|
-
const f =
|
|
1405
|
+
const f = x(i.updated).utc();
|
|
1332
1406
|
if (a) {
|
|
1333
|
-
const
|
|
1334
|
-
p.kts = Math.round(
|
|
1407
|
+
const S = b.calculateDistance(i, a), v = x(a.utc || a.updated).diff(f, "h", !0);
|
|
1408
|
+
p.kts = Math.round(S / v * 100) / 100, p.deg = b.calculateBearing(i, a, !0, 0);
|
|
1335
1409
|
}
|
|
1336
|
-
const
|
|
1410
|
+
const m = T.point([i.lng, i.lat], {
|
|
1337
1411
|
model: c.model,
|
|
1338
1412
|
name: r.name,
|
|
1339
1413
|
nameCn: r.nameCn,
|
|
1340
1414
|
date: f.format(),
|
|
1341
1415
|
hour: 0,
|
|
1342
1416
|
format: f.format("MMM-DD/HHmm[Z]"),
|
|
1343
|
-
pressure: i.pressure > 1e4 ?
|
|
1417
|
+
pressure: i.pressure > 1e4 ? h.roundPrecision((i == null ? void 0 : i.pressure) / 100, 0) : h.roundPrecision(i.pressure, 0),
|
|
1344
1418
|
wind: i.wind,
|
|
1345
1419
|
movement: p,
|
|
1346
|
-
category:
|
|
1420
|
+
category: d,
|
|
1347
1421
|
type: "forecast",
|
|
1348
1422
|
important: !0
|
|
1349
1423
|
// 第一个预报点为重要点
|
|
1350
1424
|
});
|
|
1351
|
-
u.unshift(
|
|
1425
|
+
u.unshift(m), l.unshift(m.geometry.coordinates);
|
|
1352
1426
|
}
|
|
1353
1427
|
if (e.features.push(...u), (l == null ? void 0 : l.length) > 1) {
|
|
1354
|
-
const f = T.lineString(
|
|
1355
|
-
date: (i == null ? void 0 : i.updated) || (
|
|
1428
|
+
const f = T.lineString(h.convertToMonotonicLng2(l), {
|
|
1429
|
+
date: (i == null ? void 0 : i.updated) || (g == null ? void 0 : g.format()),
|
|
1356
1430
|
id: r.id || r.name,
|
|
1357
1431
|
model: c.model,
|
|
1358
1432
|
name: r.name,
|
|
1359
|
-
category:
|
|
1433
|
+
category: d,
|
|
1360
1434
|
type: "forecast",
|
|
1361
1435
|
movement: p
|
|
1362
1436
|
});
|
|
@@ -1364,37 +1438,37 @@ class it {
|
|
|
1364
1438
|
}
|
|
1365
1439
|
}
|
|
1366
1440
|
}
|
|
1367
|
-
if (e.features.sort((c, a) => c.properties.type === "forecast" && a.properties.type === "forecast" && c.geometry.type === "Point" && a.geometry.type === "Point" ?
|
|
1368
|
-
const c = [], a =
|
|
1369
|
-
for (const
|
|
1370
|
-
const
|
|
1441
|
+
if (e.features.sort((c, a) => c.properties.type === "forecast" && a.properties.type === "forecast" && c.geometry.type === "Point" && a.geometry.type === "Point" ? x(c.properties.date).valueOf() - x(a.properties.date).valueOf() : 0), (s = r.history) != null && s.length) {
|
|
1442
|
+
const c = [], a = x(i == null ? void 0 : i.updated).utc(), l = x((o = r.history) == null ? void 0 : o.at(-1).updated).utc(), u = a.diff(l, "h") % 24 > 2 ? 24 : 12;
|
|
1443
|
+
for (const g of r.history) {
|
|
1444
|
+
const d = x(g.updated).utc(), p = d.isSameOrBefore(a) || d.isSame(l);
|
|
1371
1445
|
p && a.add(-u, "h");
|
|
1372
|
-
const f = T.point([
|
|
1446
|
+
const f = T.point([g.lng, g.lat], {
|
|
1373
1447
|
name: r.name,
|
|
1374
1448
|
nameCn: r.nameCn,
|
|
1375
|
-
date:
|
|
1376
|
-
format:
|
|
1377
|
-
pressure:
|
|
1378
|
-
kts:
|
|
1379
|
-
level:
|
|
1449
|
+
date: d.format(),
|
|
1450
|
+
format: d.format("MMM-DD/HHmm[Z]"),
|
|
1451
|
+
pressure: g.pressure > 1e4 ? h.roundPrecision(g.pressure / 100, 0) : h.roundPrecision(g.pressure, 0),
|
|
1452
|
+
kts: g.kts,
|
|
1453
|
+
level: g.type,
|
|
1380
1454
|
type: "history",
|
|
1381
1455
|
category: `${r.name}-history`,
|
|
1382
|
-
wind:
|
|
1383
|
-
movement:
|
|
1456
|
+
wind: g.wind,
|
|
1457
|
+
movement: g.movement,
|
|
1384
1458
|
important: p
|
|
1385
1459
|
});
|
|
1386
1460
|
e.features.push(f), c.push(f.geometry.coordinates);
|
|
1387
1461
|
}
|
|
1388
1462
|
if (c.length === 1 && c.push(c[0]), c.length > 1) {
|
|
1389
|
-
const
|
|
1463
|
+
const g = T.lineString(h.convertToMonotonicLng2(c), {
|
|
1390
1464
|
name: r.name,
|
|
1391
1465
|
type: "history",
|
|
1392
1466
|
updated: i == null ? void 0 : i.updated,
|
|
1393
|
-
pressure: (i == null ? void 0 : i.pressure) > 1e4 ?
|
|
1467
|
+
pressure: (i == null ? void 0 : i.pressure) > 1e4 ? h.roundPrecision((i == null ? void 0 : i.pressure) / 100, 0) : h.roundPrecision(i == null ? void 0 : i.pressure, 0),
|
|
1394
1468
|
kts: i == null ? void 0 : i.kts,
|
|
1395
1469
|
level: i == null ? void 0 : i.type
|
|
1396
1470
|
});
|
|
1397
|
-
e.features.push(
|
|
1471
|
+
e.features.push(g);
|
|
1398
1472
|
}
|
|
1399
1473
|
}
|
|
1400
1474
|
}
|
|
@@ -1409,32 +1483,32 @@ class it {
|
|
|
1409
1483
|
var o, r, i, c;
|
|
1410
1484
|
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 = [];
|
|
1411
1485
|
for (const a of n) {
|
|
1412
|
-
const l = a.properties.name, u = a.properties.model,
|
|
1486
|
+
const l = a.properties.name, u = a.properties.model, g = a.properties.showCircle, d = a.properties.disabled, p = x(a.properties.date).utc();
|
|
1413
1487
|
let f = e * 60;
|
|
1414
|
-
const
|
|
1488
|
+
const m = (r = t == null ? void 0 : t.data) == null ? void 0 : r.features.filter(
|
|
1415
1489
|
(P) => P.geometry.type === "Point" && P.properties.type === "forecast" && P.properties.category === `${l}-${u}`
|
|
1416
1490
|
);
|
|
1417
|
-
let
|
|
1418
|
-
for (;
|
|
1419
|
-
if (
|
|
1420
|
-
const P =
|
|
1491
|
+
let S, v = p.clone().add(f, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1492
|
+
for (; S = this.pickIndex(m, v), S <= m.length - 1; ) {
|
|
1493
|
+
if (S > 0) {
|
|
1494
|
+
const P = m[S], y = S === 0 ? void 0 : m[S - 1], N = (f / 60 - ((i = y == null ? void 0 : y.properties) == null ? void 0 : i.hour)) / (P.properties.hour - ((c = y == null ? void 0 : y.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[0], P.geometry.coordinates[0], N), E = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[1], P.geometry.coordinates[1], N), F = T.point([$, E], {
|
|
1421
1495
|
name: l,
|
|
1422
1496
|
model: u,
|
|
1423
1497
|
category: P == null ? void 0 : P.properties.category,
|
|
1424
|
-
date:
|
|
1425
|
-
format:
|
|
1426
|
-
gusts: this.computeNumber(
|
|
1427
|
-
hour: this.computeNumber(
|
|
1428
|
-
movement: this.computeNumber(
|
|
1429
|
-
pressure: this.computeNumber(
|
|
1430
|
-
wind: this.computeNumber(
|
|
1498
|
+
date: v.format(),
|
|
1499
|
+
format: v.format("MMM-DD/HHmm[Z]"),
|
|
1500
|
+
gusts: this.computeNumber(y == null ? void 0 : y.properties.gusts, P.properties.gusts, N),
|
|
1501
|
+
hour: this.computeNumber(y == null ? void 0 : y.properties.hour, P.properties.hour, N),
|
|
1502
|
+
movement: this.computeNumber(y == null ? void 0 : y.properties.movement, P.properties.movement, N),
|
|
1503
|
+
pressure: this.computeNumber(y == null ? void 0 : y.properties.pressure, P.properties.pressure, N),
|
|
1504
|
+
wind: this.computeNumber(y == null ? void 0 : y.properties.wind, P.properties.wind, N),
|
|
1431
1505
|
type: "forecast",
|
|
1432
|
-
disabled:
|
|
1433
|
-
showCircle:
|
|
1506
|
+
disabled: d,
|
|
1507
|
+
showCircle: g
|
|
1434
1508
|
});
|
|
1435
|
-
s.push(
|
|
1509
|
+
s.push(F);
|
|
1436
1510
|
}
|
|
1437
|
-
f += e * 60,
|
|
1511
|
+
f += e * 60, v = p.clone().add(f, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1438
1512
|
}
|
|
1439
1513
|
}
|
|
1440
1514
|
return s;
|
|
@@ -1464,28 +1538,28 @@ class it {
|
|
|
1464
1538
|
const { t1: o, t2: r, hr: i, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
1465
1539
|
if (o && r) {
|
|
1466
1540
|
if (!s.debug) {
|
|
1467
|
-
const p =
|
|
1541
|
+
const p = b.calculateDistance(t, o), f = b.calculateDistance(t, r);
|
|
1468
1542
|
if (p > 2 * n && f > 2 * n)
|
|
1469
|
-
return
|
|
1543
|
+
return k == null || k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, p, f, {
|
|
1470
1544
|
from: t,
|
|
1471
1545
|
t1: o,
|
|
1472
1546
|
t2: r,
|
|
1473
1547
|
hr: i
|
|
1474
1548
|
}), {};
|
|
1475
1549
|
}
|
|
1476
|
-
const a =
|
|
1477
|
-
let
|
|
1478
|
-
u < 180 ?
|
|
1479
|
-
const
|
|
1480
|
-
return
|
|
1550
|
+
const a = b.calculateBearing(t, o), l = b.calculateBearing(o, r), u = Math.abs(a - l);
|
|
1551
|
+
let g = 0;
|
|
1552
|
+
u < 180 ? g = u + 90 : u >= 180 && (g = u - 90);
|
|
1553
|
+
const d = b.calculateCoordinate(o, g, n);
|
|
1554
|
+
return k == null || k.info("[%s] the right tangent position: %j", s.requestId, {
|
|
1481
1555
|
from: t,
|
|
1482
1556
|
t1: o,
|
|
1483
1557
|
t2: r,
|
|
1484
1558
|
radius: n,
|
|
1485
1559
|
bearing1: a,
|
|
1486
1560
|
bearing2: l,
|
|
1487
|
-
right:
|
|
1488
|
-
}), { at:
|
|
1561
|
+
right: d
|
|
1562
|
+
}), { at: d, t1: o, t2: r, hr: Number(i), hours: c };
|
|
1489
1563
|
}
|
|
1490
1564
|
return {};
|
|
1491
1565
|
}
|
|
@@ -1503,19 +1577,19 @@ class it {
|
|
|
1503
1577
|
const { t1: o, t2: r, hr: i, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
1504
1578
|
if (o && r) {
|
|
1505
1579
|
if (!s.debug) {
|
|
1506
|
-
const
|
|
1507
|
-
if (
|
|
1508
|
-
return
|
|
1580
|
+
const d = b.calculateDistance(t, o), p = b.calculateDistance(t, r);
|
|
1581
|
+
if (d > 2 * n && p > 2 * n)
|
|
1582
|
+
return k == null || k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", s.requestId, d, p, {
|
|
1509
1583
|
from: t,
|
|
1510
1584
|
t1: o,
|
|
1511
1585
|
t2: r,
|
|
1512
1586
|
hr: i
|
|
1513
1587
|
}), {};
|
|
1514
1588
|
}
|
|
1515
|
-
const a =
|
|
1516
|
-
return { at:
|
|
1589
|
+
const a = b.calculateBearing(t, o), l = b.calculateBearing(o, r), u = b.calculateDistance(t, o);
|
|
1590
|
+
return { at: b.calculateCoordinate(o, a - l + 180, n < u ? n : u), t1: o, t2: r, hr: Number(i), hours: c };
|
|
1517
1591
|
} else
|
|
1518
|
-
return
|
|
1592
|
+
return k == null || k.info("[%s] no need drift: %j", s.requestId, { from: t, t1: o, t2: r, hr: i }), {};
|
|
1519
1593
|
}
|
|
1520
1594
|
/**
|
|
1521
1595
|
* 获取台风中心点对
|
|
@@ -1526,17 +1600,17 @@ class it {
|
|
|
1526
1600
|
* @private
|
|
1527
1601
|
*/
|
|
1528
1602
|
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
1529
|
-
var l, u,
|
|
1603
|
+
var l, u, g, d, p;
|
|
1530
1604
|
let s = {};
|
|
1531
1605
|
(l = t.forecasts) == null || l.forEach((f) => {
|
|
1532
1606
|
s = { ...f.hours, ...s };
|
|
1533
1607
|
});
|
|
1534
|
-
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (s == null ? void 0 : s[(
|
|
1535
|
-
|
|
1536
|
-
let r = (
|
|
1608
|
+
const o = ((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]]);
|
|
1609
|
+
k == null || k.info("[%s] the first tropical center: %j", n.requestId, o);
|
|
1610
|
+
let r = (d = Object.keys(s || {}).filter((f) => Number(f) <= (e < 0 ? 24 : e))) == null ? void 0 : d.at(-1);
|
|
1537
1611
|
r || (r = (p = Object.keys(s || {}).filter((f) => Number(f) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : p.at(-1));
|
|
1538
1612
|
const i = s == null ? void 0 : s[r || -1];
|
|
1539
|
-
|
|
1613
|
+
k == null || k.info("[%s] the second tropical center: %j in %d hrs", n.requestId, i, r);
|
|
1540
1614
|
const c = Object.keys(s || {}).filter((f) => Number(f) <= Number(r)), a = { 0: o };
|
|
1541
1615
|
for (const f of c)
|
|
1542
1616
|
a[f] = s[f];
|
|
@@ -1545,7 +1619,7 @@ class it {
|
|
|
1545
1619
|
static pickIndex(t, e) {
|
|
1546
1620
|
let n = 0;
|
|
1547
1621
|
for (const s of t) {
|
|
1548
|
-
if (
|
|
1622
|
+
if (x(s.properties.date).isAfter(e))
|
|
1549
1623
|
return n === 0 ? -1 : n;
|
|
1550
1624
|
n++;
|
|
1551
1625
|
}
|
|
@@ -1581,9 +1655,9 @@ typeof globalThis < "u" && typeof globalThis.Buffer > "u" && (globalThis.Buffer
|
|
|
1581
1655
|
throw new TypeError("Buffer.from: unsupported source type");
|
|
1582
1656
|
}
|
|
1583
1657
|
});
|
|
1584
|
-
let
|
|
1658
|
+
let O;
|
|
1585
1659
|
try {
|
|
1586
|
-
|
|
1660
|
+
O = z.getLogger("meteo");
|
|
1587
1661
|
} catch {
|
|
1588
1662
|
} finally {
|
|
1589
1663
|
}
|
|
@@ -1593,7 +1667,7 @@ function H() {
|
|
|
1593
1667
|
const { JSDOM: C } = require("jsdom"), { DOMParser: t } = new C("").window;
|
|
1594
1668
|
return new t();
|
|
1595
1669
|
}
|
|
1596
|
-
class
|
|
1670
|
+
class W {
|
|
1597
1671
|
/**
|
|
1598
1672
|
* Buffer to ArrayBuffer
|
|
1599
1673
|
* 将 Node.js Buffer 转换为独立的 ArrayBuffer(byteOffset=0)。
|
|
@@ -1612,10 +1686,10 @@ class F {
|
|
|
1612
1686
|
* @param options 步数、单位等选项
|
|
1613
1687
|
*/
|
|
1614
1688
|
static drawCircle(t, e, n, s = {}) {
|
|
1615
|
-
const o = (s == null ? void 0 : s.steps) ?? 64, r = (s == null ? void 0 : s.units) ?? "nauticalmiles", i = (s == null ? void 0 : s.properties) ?? {}, c = T.point([t, e]), a = T.destination(c, n, 90, { units: r }), l =
|
|
1689
|
+
const o = (s == null ? void 0 : s.steps) ?? 64, r = (s == null ? void 0 : s.units) ?? "nauticalmiles", i = (s == null ? void 0 : s.properties) ?? {}, c = T.point([t, e]), a = T.destination(c, n, 90, { units: r }), l = x.utc();
|
|
1616
1690
|
i.id = (s == null ? void 0 : s.id) || l.valueOf().toString();
|
|
1617
1691
|
const u = "circle";
|
|
1618
|
-
return i.name = (s == null ? void 0 : s.name) || `${u}_${l.format()}`, i.radius = n, i.center = [t, e], i.end = a.geometry.coordinates.map((
|
|
1692
|
+
return i.name = (s == null ? void 0 : s.name) || `${u}_${l.format()}`, i.radius = n, i.center = [t, e], i.end = a.geometry.coordinates.map((g) => h.roundPrecision(g, 9)), i.units = r, i.steps = o, i.shape = "circle", O.info("[%s] draw circle with %j", s == null ? void 0 : s.requestId, i), T.circle(c, n, { steps: o, units: r, properties: i });
|
|
1619
1693
|
}
|
|
1620
1694
|
/**
|
|
1621
1695
|
* 基于turf画矩形,返回GeoJSON Feature<Polygon>
|
|
@@ -1624,11 +1698,11 @@ class F {
|
|
|
1624
1698
|
* @param options 选项
|
|
1625
1699
|
*/
|
|
1626
1700
|
static drawRect(t, e, n = {}) {
|
|
1627
|
-
const s = (n == null ? void 0 : n.properties) ?? {}, o =
|
|
1701
|
+
const s = (n == null ? void 0 : n.properties) ?? {}, o = x.utc();
|
|
1628
1702
|
s.id = (n == null ? void 0 : n.id) || o.valueOf().toString();
|
|
1629
1703
|
const r = "rect";
|
|
1630
|
-
s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.start = t.map((l) =>
|
|
1631
|
-
const [i, c] =
|
|
1704
|
+
s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.start = t.map((l) => h.roundPrecision(l, 9)), s.end = e.map((l) => h.roundPrecision(l, 9)), s.shape = "rect", O.info("[%s] draw rect with %j", n == null ? void 0 : n.requestId, s);
|
|
1705
|
+
const [i, c] = h.convertToMonotonicLng2([t, e]), a = [Math.min(i[0], c[0]), Math.min(i[1], c[1]), Math.max(i[0], c[0]), Math.max(i[1], c[1])];
|
|
1632
1706
|
return T.bboxPolygon(a, { properties: s });
|
|
1633
1707
|
}
|
|
1634
1708
|
/**
|
|
@@ -1639,11 +1713,11 @@ class F {
|
|
|
1639
1713
|
* @returns
|
|
1640
1714
|
*/
|
|
1641
1715
|
static drawLine(t, e = {}) {
|
|
1642
|
-
const n = (e == null ? void 0 : e.properties) ?? {}, s =
|
|
1716
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = x.utc();
|
|
1643
1717
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1644
1718
|
const o = "line";
|
|
1645
|
-
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.shape = "line",
|
|
1646
|
-
const r =
|
|
1719
|
+
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.shape = "line", O.info("[%s] draw line with %j", e == null ? void 0 : e.requestId, n);
|
|
1720
|
+
const r = h.convertToMonotonicLng2(t);
|
|
1647
1721
|
return T.lineString(r, n);
|
|
1648
1722
|
}
|
|
1649
1723
|
/**
|
|
@@ -1653,11 +1727,11 @@ class F {
|
|
|
1653
1727
|
* @returns
|
|
1654
1728
|
*/
|
|
1655
1729
|
static drawPolygon(t, e = {}) {
|
|
1656
|
-
const n = (e == null ? void 0 : e.properties) ?? {}, s =
|
|
1730
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = x.utc();
|
|
1657
1731
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1658
1732
|
const o = "polygon";
|
|
1659
|
-
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.coordinates = t.map((i) => i.map((c) =>
|
|
1660
|
-
const r =
|
|
1733
|
+
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.coordinates = t.map((i) => i.map((c) => h.roundPrecision(c, 9))), n.shape = "polygon", O.info("[%s] draw polygon with %j", e == null ? void 0 : e.requestId, n);
|
|
1734
|
+
const r = h.convertToMonotonicLng2(t);
|
|
1661
1735
|
return T.polygon([r], n);
|
|
1662
1736
|
}
|
|
1663
1737
|
/**
|
|
@@ -1668,10 +1742,10 @@ class F {
|
|
|
1668
1742
|
* @returns
|
|
1669
1743
|
*/
|
|
1670
1744
|
static drawPoint(t, e, n = {}) {
|
|
1671
|
-
const s = (n == null ? void 0 : n.properties) ?? {}, o =
|
|
1745
|
+
const s = (n == null ? void 0 : n.properties) ?? {}, o = x.utc();
|
|
1672
1746
|
s.id = (n == null ? void 0 : n.id) || o.valueOf().toString();
|
|
1673
1747
|
const r = "point";
|
|
1674
|
-
return s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.shape = "point",
|
|
1748
|
+
return s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.shape = "point", O.info("[%s] draw point with %j", n == null ? void 0 : n.requestId, s), T.point([e, t], s);
|
|
1675
1749
|
}
|
|
1676
1750
|
/**
|
|
1677
1751
|
* 解析ORM GeoJSON Feature (圆), 返回FeatureCollection
|
|
@@ -1682,10 +1756,10 @@ class F {
|
|
|
1682
1756
|
*/
|
|
1683
1757
|
static parseCircle(t, e = {}) {
|
|
1684
1758
|
var s, o;
|
|
1685
|
-
|
|
1759
|
+
O.info("[%s] parse circle with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1686
1760
|
const n = t.properties || {};
|
|
1687
1761
|
if (n.shape == "circle") {
|
|
1688
|
-
const r =
|
|
1762
|
+
const r = x.utc();
|
|
1689
1763
|
n.id = (n == null ? void 0 : n.id) || r.valueOf().toString();
|
|
1690
1764
|
const i = n == null ? void 0 : n.id, c = ((s = n == null ? void 0 : n.center) == null ? void 0 : s.length) == 2 ? T.point(n.center) : T.centroid(t);
|
|
1691
1765
|
let a = "center";
|
|
@@ -1697,12 +1771,12 @@ class F {
|
|
|
1697
1771
|
u = T.pointToLineDistance(c, p, { units: l });
|
|
1698
1772
|
}
|
|
1699
1773
|
a = "end";
|
|
1700
|
-
const
|
|
1701
|
-
|
|
1702
|
-
const
|
|
1703
|
-
return a = "edge",
|
|
1774
|
+
const g = ((o = n == null ? void 0 : n.end) == null ? void 0 : o.length) == 2 ? T.point(n.end) : T.destination(c, u, 90, { units: l });
|
|
1775
|
+
g.properties = { id: `${a}_${i}`, parentId: i, name: a, radius: u, units: l };
|
|
1776
|
+
const d = T.lineString([c.geometry.coordinates, g.geometry.coordinates]);
|
|
1777
|
+
return a = "edge", d.properties = { id: `${a}_${i}`, parentId: i, name: a, radius: u, units: l }, T.featureCollection([c, g, d, t]);
|
|
1704
1778
|
} else
|
|
1705
|
-
return
|
|
1779
|
+
return O.warn("[%s] not a orm-std circle, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1706
1780
|
}
|
|
1707
1781
|
/**
|
|
1708
1782
|
* 解析ORM GeoJSON Feature (矩形), 返回FeatureCollection
|
|
@@ -1712,10 +1786,10 @@ class F {
|
|
|
1712
1786
|
* 如果feature是矩形,则返回矩形的四个顶点和矩形Feature
|
|
1713
1787
|
*/
|
|
1714
1788
|
static parseRect(t, e = {}) {
|
|
1715
|
-
|
|
1789
|
+
O.info("[%s] parse rect with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1716
1790
|
const n = t.properties || {};
|
|
1717
1791
|
if (n.shape == "rect") {
|
|
1718
|
-
const s =
|
|
1792
|
+
const s = x.utc();
|
|
1719
1793
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1720
1794
|
const o = n == null ? void 0 : n.id, r = t.geometry.coordinates[0], c = ["sw", "nw", "ne", "se"].map((a, l) => {
|
|
1721
1795
|
const u = T.point(r[l]);
|
|
@@ -1723,7 +1797,7 @@ class F {
|
|
|
1723
1797
|
});
|
|
1724
1798
|
return T.featureCollection([...c, t]);
|
|
1725
1799
|
} else
|
|
1726
|
-
return
|
|
1800
|
+
return O.warn("[%s] not a orm-std rect, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1727
1801
|
}
|
|
1728
1802
|
/**
|
|
1729
1803
|
* 解析ORM GeoJSON Feature (线), 返回FeatureCollection
|
|
@@ -1733,10 +1807,10 @@ class F {
|
|
|
1733
1807
|
* 如果feature是线,则返回所有坐标点(首为start、尾为end、中间为point_N)以及线Feature
|
|
1734
1808
|
*/
|
|
1735
1809
|
static parseLine(t, e = {}) {
|
|
1736
|
-
|
|
1810
|
+
O.info("[%s] parse line with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1737
1811
|
const n = t.properties || {};
|
|
1738
1812
|
if (n.shape == "line") {
|
|
1739
|
-
const s =
|
|
1813
|
+
const s = x.utc();
|
|
1740
1814
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1741
1815
|
const o = n == null ? void 0 : n.id, i = t.geometry.coordinates.map((c, a) => {
|
|
1742
1816
|
const l = `point_${a}`, u = T.point(c);
|
|
@@ -1744,7 +1818,7 @@ class F {
|
|
|
1744
1818
|
});
|
|
1745
1819
|
return T.featureCollection([...i, t]);
|
|
1746
1820
|
} else
|
|
1747
|
-
return
|
|
1821
|
+
return O.warn("[%s] not a orm-std line, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1748
1822
|
}
|
|
1749
1823
|
/**
|
|
1750
1824
|
* 解析ORM GeoJSON Feature (多边形), 返回FeatureCollection
|
|
@@ -1754,10 +1828,10 @@ class F {
|
|
|
1754
1828
|
* 如果feature是多边形,则返回多边形的顶点和多边形Feature
|
|
1755
1829
|
*/
|
|
1756
1830
|
static parsePolygon(t, e = {}) {
|
|
1757
|
-
|
|
1831
|
+
O.info("[%s] parse polygon with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1758
1832
|
const n = t.properties || {};
|
|
1759
1833
|
if (n.shape == "polygon") {
|
|
1760
|
-
const s =
|
|
1834
|
+
const s = x.utc();
|
|
1761
1835
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1762
1836
|
const o = n == null ? void 0 : n.id, i = t.geometry.coordinates[0].map((c, a) => {
|
|
1763
1837
|
const l = T.point(c), u = `corner_${a}`;
|
|
@@ -1765,7 +1839,7 @@ class F {
|
|
|
1765
1839
|
});
|
|
1766
1840
|
return T.featureCollection([...i, t]);
|
|
1767
1841
|
} else
|
|
1768
|
-
return
|
|
1842
|
+
return O.warn("[%s] not a orm-std polygon, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1769
1843
|
}
|
|
1770
1844
|
// ---------------------------------------------------------------------------
|
|
1771
1845
|
// ZIP / KMZ 内部工具
|
|
@@ -1787,12 +1861,12 @@ class F {
|
|
|
1787
1861
|
* 使用 Central Directory 解析,避免 Data Descriptor 导致的大小不准问题。
|
|
1788
1862
|
*/
|
|
1789
1863
|
static async _parseZipEntries(t) {
|
|
1790
|
-
var
|
|
1864
|
+
var g;
|
|
1791
1865
|
const e = new Uint8Array(t), n = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), s = new DataView(n), o = new Uint8Array(n), r = /* @__PURE__ */ new Map();
|
|
1792
1866
|
let i = -1;
|
|
1793
|
-
for (let
|
|
1794
|
-
if (s.getUint32(
|
|
1795
|
-
i =
|
|
1867
|
+
for (let d = n.byteLength - 22; d >= 0; d--)
|
|
1868
|
+
if (s.getUint32(d, !0) === 101010256) {
|
|
1869
|
+
i = d;
|
|
1796
1870
|
break;
|
|
1797
1871
|
}
|
|
1798
1872
|
if (i < 0)
|
|
@@ -1804,33 +1878,33 @@ class F {
|
|
|
1804
1878
|
for (; l < u; ) {
|
|
1805
1879
|
if (s.getUint32(l, !0) !== 33639248)
|
|
1806
1880
|
throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);
|
|
1807
|
-
const p = s.getUint16(l + 10, !0), f = s.getUint32(l + 20, !0),
|
|
1881
|
+
const p = s.getUint16(l + 10, !0), f = s.getUint32(l + 20, !0), m = s.getUint16(l + 28, !0), S = s.getUint16(l + 30, !0), v = s.getUint16(l + 32, !0), P = s.getUint32(l + 42, !0), y = o.slice(l + 46, l + 46 + m), N = new TextDecoder().decode(y), $ = s.getUint16(P + 26, !0), E = s.getUint16(P + 28, !0), F = P + 30 + $ + E, R = o.slice(F, F + f);
|
|
1808
1882
|
if (p === 0)
|
|
1809
|
-
r.set(
|
|
1883
|
+
r.set(N, R);
|
|
1810
1884
|
else if (p === 8) {
|
|
1811
1885
|
if (typeof DecompressionStream < "u") {
|
|
1812
|
-
const
|
|
1813
|
-
|
|
1814
|
-
const
|
|
1815
|
-
let
|
|
1886
|
+
const D = new DecompressionStream("deflate-raw"), M = D.writable.getWriter(), A = D.readable.getReader();
|
|
1887
|
+
M.write(R), M.close();
|
|
1888
|
+
const j = [];
|
|
1889
|
+
let U = 0;
|
|
1816
1890
|
for (; ; ) {
|
|
1817
|
-
const { done:
|
|
1818
|
-
if (
|
|
1891
|
+
const { done: w, value: I } = await A.read();
|
|
1892
|
+
if (w)
|
|
1819
1893
|
break;
|
|
1820
|
-
|
|
1894
|
+
j.push(I), U += I.length;
|
|
1821
1895
|
}
|
|
1822
|
-
const
|
|
1823
|
-
let
|
|
1824
|
-
for (const
|
|
1825
|
-
|
|
1826
|
-
r.set(
|
|
1827
|
-
} else if (typeof process < "u" && ((
|
|
1896
|
+
const X = new Uint8Array(U);
|
|
1897
|
+
let B = 0;
|
|
1898
|
+
for (const w of j)
|
|
1899
|
+
X.set(w, B), B += w.length;
|
|
1900
|
+
r.set(N, X);
|
|
1901
|
+
} else if (typeof process < "u" && ((g = process.versions) != null && g.node))
|
|
1828
1902
|
try {
|
|
1829
|
-
r.set(
|
|
1903
|
+
r.set(N, W._inflateRawSync(R));
|
|
1830
1904
|
} catch {
|
|
1831
1905
|
}
|
|
1832
1906
|
}
|
|
1833
|
-
l += 46 +
|
|
1907
|
+
l += 46 + m + S + v;
|
|
1834
1908
|
}
|
|
1835
1909
|
return r;
|
|
1836
1910
|
}
|
|
@@ -1845,41 +1919,41 @@ class F {
|
|
|
1845
1919
|
*/
|
|
1846
1920
|
static async convertKML2GeoJSON(t, e = {}) {
|
|
1847
1921
|
var i, c;
|
|
1848
|
-
|
|
1922
|
+
O.info("[%s] convert kml to geojson", e == null ? void 0 : e.requestId);
|
|
1849
1923
|
const s = H().parseFromString(t, "application/xml"), o = Array.from(s.querySelectorAll("Placemark")), r = [];
|
|
1850
1924
|
for (const a of o) {
|
|
1851
1925
|
const l = {}, u = Array.from(a.querySelectorAll("ExtendedData > Data"));
|
|
1852
|
-
for (const
|
|
1853
|
-
const
|
|
1854
|
-
|
|
1926
|
+
for (const y of u) {
|
|
1927
|
+
const N = y.getAttribute("name"), $ = (c = (i = y.querySelector("value")) == null ? void 0 : i.textContent) == null ? void 0 : c.trim();
|
|
1928
|
+
N && $ !== void 0 && $ !== null && (l[N] = $);
|
|
1855
1929
|
}
|
|
1856
|
-
const
|
|
1857
|
-
const
|
|
1858
|
-
return [
|
|
1859
|
-
}),
|
|
1860
|
-
if (
|
|
1861
|
-
const
|
|
1862
|
-
if (
|
|
1863
|
-
const
|
|
1864
|
-
r.push(
|
|
1930
|
+
const g = x.utc(), d = Object.keys(l).find((y) => y.toLowerCase().indexOf("name") !== -1), p = d ? l[d] : void 0, f = `${g.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, m = (y) => y.trim().split(/[\s\n]+/).filter((N) => N.length > 0).map((N) => {
|
|
1931
|
+
const $ = N.split(",").map(Number);
|
|
1932
|
+
return [$[0], $[1]];
|
|
1933
|
+
}), S = a.querySelector("LineString > coordinates");
|
|
1934
|
+
if (S) {
|
|
1935
|
+
const y = m(S.textContent || "");
|
|
1936
|
+
if (y.length >= 2) {
|
|
1937
|
+
const N = T.lineString(y, { ...l, shape: "line", id: f, name: p });
|
|
1938
|
+
r.push(N);
|
|
1865
1939
|
}
|
|
1866
1940
|
continue;
|
|
1867
1941
|
}
|
|
1868
|
-
const
|
|
1869
|
-
if (
|
|
1870
|
-
const
|
|
1871
|
-
if (
|
|
1872
|
-
const
|
|
1873
|
-
r.push(
|
|
1942
|
+
const v = a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");
|
|
1943
|
+
if (v) {
|
|
1944
|
+
const y = m(v.textContent || "");
|
|
1945
|
+
if (y.length >= 4) {
|
|
1946
|
+
const N = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]], $ = T.polygon([N], { ...l, shape: "polygon", id: f, name: p });
|
|
1947
|
+
r.push($);
|
|
1874
1948
|
}
|
|
1875
1949
|
continue;
|
|
1876
1950
|
}
|
|
1877
1951
|
const P = a.querySelector("Point > coordinates");
|
|
1878
1952
|
if (P) {
|
|
1879
|
-
const
|
|
1880
|
-
if (
|
|
1881
|
-
const
|
|
1882
|
-
r.push(
|
|
1953
|
+
const y = m(P.textContent || "");
|
|
1954
|
+
if (y.length >= 1) {
|
|
1955
|
+
const N = T.point(y[0], { ...l, shape: "point", id: f, name: p });
|
|
1956
|
+
r.push(N);
|
|
1883
1957
|
}
|
|
1884
1958
|
continue;
|
|
1885
1959
|
}
|
|
@@ -1897,12 +1971,12 @@ class F {
|
|
|
1897
1971
|
*/
|
|
1898
1972
|
static async convertKMZ2GeoJSON(t, e = {}) {
|
|
1899
1973
|
var r;
|
|
1900
|
-
|
|
1901
|
-
const n = await
|
|
1974
|
+
O.info("[%s] convert kmz to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
1975
|
+
const n = await W._parseZipEntries(t), s = n.get("doc.kml") ?? ((r = [...n.entries()].find(([i]) => i.toLowerCase().endsWith(".kml"))) == null ? void 0 : r[1]);
|
|
1902
1976
|
if (!s)
|
|
1903
|
-
return
|
|
1977
|
+
return O.warn("[%s] no .kml file found in kmz", e == null ? void 0 : e.requestId), T.featureCollection([]);
|
|
1904
1978
|
const o = new TextDecoder().decode(s);
|
|
1905
|
-
return
|
|
1979
|
+
return W.convertKML2GeoJSON(o, e);
|
|
1906
1980
|
}
|
|
1907
1981
|
/**
|
|
1908
1982
|
* 将 ZIP 文件中所有 .kml 文件合并转换为一个 GeoJSON FeatureCollection(异步)。
|
|
@@ -1914,15 +1988,15 @@ class F {
|
|
|
1914
1988
|
* @param options
|
|
1915
1989
|
*/
|
|
1916
1990
|
static async convertZIP2GeoJSON(t, e = {}) {
|
|
1917
|
-
|
|
1918
|
-
const n = await
|
|
1991
|
+
O.info("[%s] convert zip to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
1992
|
+
const n = await W._parseZipEntries(t), s = [];
|
|
1919
1993
|
for (const [o, r] of n) {
|
|
1920
1994
|
if (!o.toLowerCase().endsWith(".kml"))
|
|
1921
1995
|
continue;
|
|
1922
|
-
const i = new TextDecoder().decode(r), c = await
|
|
1996
|
+
const i = new TextDecoder().decode(r), c = await W.convertKML2GeoJSON(i, e);
|
|
1923
1997
|
s.push(...c.features);
|
|
1924
1998
|
}
|
|
1925
|
-
return s.length === 0 ? (
|
|
1999
|
+
return s.length === 0 ? (O.warn("[%s] no .kml files found in zip", e == null ? void 0 : e.requestId), this.convertSHP2GeoJSON(t, e)) : T.featureCollection(s);
|
|
1926
2000
|
}
|
|
1927
2001
|
/**
|
|
1928
2002
|
* 将 Shapefile ZIP(含 .shp/.shx/.dbf/.prj)转换为 GeoJSON FeatureCollection。
|
|
@@ -1933,12 +2007,12 @@ class F {
|
|
|
1933
2007
|
* @param options
|
|
1934
2008
|
*/
|
|
1935
2009
|
static async convertSHP2GeoJSON(t, e = {}) {
|
|
1936
|
-
|
|
2010
|
+
O.info("[%s] convert shp zip to geojson", e == null ? void 0 : e.requestId);
|
|
1937
2011
|
try {
|
|
1938
|
-
typeof Buffer < "u" && Buffer.isBuffer(t) && (t =
|
|
2012
|
+
typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
1939
2013
|
const n = await J(t);
|
|
1940
2014
|
if (Array.isArray(n)) {
|
|
1941
|
-
const s = n.flatMap((c) => c.features || []), o =
|
|
2015
|
+
const s = n.flatMap((c) => c.features || []), o = x.utc(), r = (e == null ? void 0 : e.id) || o.valueOf().toString(), i = {
|
|
1942
2016
|
Point: "point",
|
|
1943
2017
|
MultiPoint: "point",
|
|
1944
2018
|
LineString: "line",
|
|
@@ -1950,20 +2024,20 @@ class F {
|
|
|
1950
2024
|
var p;
|
|
1951
2025
|
const l = ((p = c.geometry) == null ? void 0 : p.type) || "", u = i[l] || l.toLowerCase();
|
|
1952
2026
|
c.properties = c.properties || {}, c.properties.shape = u, c.properties.parentId = r, c.properties.id = `${r}_${a}`;
|
|
1953
|
-
const
|
|
1954
|
-
c.properties.name =
|
|
2027
|
+
const g = Object.keys(c.properties).find((f) => f.toLowerCase().indexOf("name") !== -1), d = g ? c.properties[g] : void 0;
|
|
2028
|
+
c.properties.name = d || `${u}_${o.format()}_${a}`;
|
|
1955
2029
|
}), T.featureCollection(s);
|
|
1956
2030
|
}
|
|
1957
2031
|
return n;
|
|
1958
2032
|
} catch (n) {
|
|
1959
|
-
return
|
|
2033
|
+
return O.warn("[%s] failed to convert shp zip: %s", e == null ? void 0 : e.requestId, n), T.featureCollection([]);
|
|
1960
2034
|
}
|
|
1961
2035
|
}
|
|
1962
2036
|
}
|
|
1963
2037
|
export {
|
|
1964
2038
|
K as AisHelper,
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
2039
|
+
W as GeoJsonHelper,
|
|
2040
|
+
b as LaneHelper,
|
|
2041
|
+
h as LngLatHelper,
|
|
1968
2042
|
it as TropicalHelper
|
|
1969
2043
|
};
|