@idm-plugin/geo 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ais/src/index.d.ts +8 -0
- package/dist/index.js +582 -572
- package/dist/index.umd.cjs +6 -6
- package/dist/lane/src/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
var Y = Object.defineProperty;
|
|
2
|
+
var Q = (C, t, e) => t in C ? Y(C, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : C[t] = e;
|
|
3
|
+
var K = (C, t, e) => (Q(C, typeof t != "symbol" ? t + "" : t, e), e);
|
|
1
4
|
import * as T from "@turf/turf";
|
|
2
5
|
import N from "moment";
|
|
3
|
-
import
|
|
6
|
+
import J from "@log4js-node/log4js-api";
|
|
4
7
|
import "moment-timezone";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
8
|
+
import _ from "tz-lookup";
|
|
9
|
+
import H from "shpjs";
|
|
7
10
|
class h {
|
|
8
11
|
/**
|
|
9
12
|
* 基于输入的经度,计算出时区
|
|
@@ -12,7 +15,7 @@ class h {
|
|
|
12
15
|
*/
|
|
13
16
|
static guessTimeZoneOffset(t, e) {
|
|
14
17
|
t = h.convertToStdLng(t);
|
|
15
|
-
const n =
|
|
18
|
+
const n = _(e, t), s = N().tz(n).utcOffset();
|
|
16
19
|
return h.roundPrecision(s / 60, 1);
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
@@ -33,22 +36,22 @@ class h {
|
|
|
33
36
|
t = h.convertToStdLng(t, e);
|
|
34
37
|
let s = "E";
|
|
35
38
|
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
36
|
-
let c = t * 3600,
|
|
39
|
+
let c = t * 3600, i = "", r = "", o = "";
|
|
37
40
|
const a = c % 3600 % 60;
|
|
38
|
-
n.indexOf("S") !== -1 && (c = c - a,
|
|
39
|
-
const
|
|
40
|
-
n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ?
|
|
41
|
-
const
|
|
42
|
-
n.indexOf("M") !== -1 ? o = h.roundPrecision(
|
|
43
|
-
const m = `${n.replace(/S+/gi,
|
|
41
|
+
n.indexOf("S") !== -1 && (c = c - a, i = h.padNumber(a, 2, 1));
|
|
42
|
+
const u = c / 60 % 60;
|
|
43
|
+
n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? r = h.roundPrecision(u, 2).toString().padStart(2, "0") : r = h.padNumber(u, 2, 2), c = c - u * 60);
|
|
44
|
+
const l = c / 3600;
|
|
45
|
+
n.indexOf("M") !== -1 ? o = h.roundPrecision(l, e).toString().padStart(3, "0") : o = h.padNumber(l, 3, 6), Number(i) >= 60 && (r = Number(r) + 1, i = 0), Number(r) >= 60 && (o = Number(o) + 1, r = 0), o = o.toString(), r = h.padNumber(Number(r), 2, Number.isInteger(Number(r)) ? 0 : 2), i = h.padNumber(Number(i), 2, Number.isInteger(Number(i)) ? 0 : 1);
|
|
46
|
+
const m = `${n.replace(/S+/gi, i).replace(/M+/gi, r).replace(/H+/gi, o)}${s}`;
|
|
44
47
|
return {
|
|
45
48
|
direction: s,
|
|
46
|
-
degree: h.roundPrecision(
|
|
47
|
-
minute: h.roundPrecision(
|
|
49
|
+
degree: h.roundPrecision(l, e),
|
|
50
|
+
minute: h.roundPrecision(u, e),
|
|
48
51
|
second: h.roundPrecision(a, e),
|
|
49
52
|
pretty: m,
|
|
50
|
-
S:
|
|
51
|
-
M:
|
|
53
|
+
S: i,
|
|
54
|
+
M: r,
|
|
52
55
|
H: o
|
|
53
56
|
};
|
|
54
57
|
}
|
|
@@ -62,22 +65,22 @@ class h {
|
|
|
62
65
|
t = t % 180;
|
|
63
66
|
let s = "N";
|
|
64
67
|
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
65
|
-
let c = t * 3600,
|
|
68
|
+
let c = t * 3600, i = "", r = "", o = "";
|
|
66
69
|
const a = c % 3600 % 60;
|
|
67
|
-
n.indexOf("S") !== -1 && (c = c - a,
|
|
68
|
-
const
|
|
69
|
-
n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ?
|
|
70
|
-
const
|
|
71
|
-
n.indexOf("M") !== -1 ? o = h.roundPrecision(
|
|
72
|
-
const m = `${n.replace(/S+/gi,
|
|
70
|
+
n.indexOf("S") !== -1 && (c = c - a, i = h.padNumber(a, 2, 1));
|
|
71
|
+
const u = c / 60 % 60;
|
|
72
|
+
n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? r = h.roundPrecision(u, 2).toString().padStart(2, "0") : r = h.padNumber(u, 2, 2), c = c - u * 60);
|
|
73
|
+
const l = c / 3600;
|
|
74
|
+
n.indexOf("M") !== -1 ? o = h.roundPrecision(l, e).toString().padStart(2, "0") : o = h.padNumber(l, 2, 6), Number(i) >= 60 && (r = Number(r) + 1, i = 0), Number(r) >= 60 && (o = Number(o) + 1, r = 0), o = o.toString(), r = h.padNumber(Number(r), 2, Number.isInteger(Number(r)) ? 0 : 2), i = h.padNumber(Number(i), 2, Number.isInteger(Number(i)) ? 0 : 1);
|
|
75
|
+
const m = `${n.replace(/S+/gi, i).replace(/M+/gi, r).replace(/H+/gi, o)}${s}`;
|
|
73
76
|
return {
|
|
74
77
|
direction: s,
|
|
75
|
-
degree: h.roundPrecision(
|
|
76
|
-
minute: h.roundPrecision(
|
|
78
|
+
degree: h.roundPrecision(l, e),
|
|
79
|
+
minute: h.roundPrecision(u, e),
|
|
77
80
|
second: h.roundPrecision(a, e),
|
|
78
81
|
pretty: m,
|
|
79
|
-
S:
|
|
80
|
-
M:
|
|
82
|
+
S: i,
|
|
83
|
+
M: r,
|
|
81
84
|
H: o
|
|
82
85
|
};
|
|
83
86
|
}
|
|
@@ -88,12 +91,12 @@ class h {
|
|
|
88
91
|
const s = t[t.length - 1].toUpperCase();
|
|
89
92
|
t = t.substring(0, t.length - 1).trim();
|
|
90
93
|
const c = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
91
|
-
let [
|
|
92
|
-
if (
|
|
93
|
-
const a = this.roundPrecision(
|
|
94
|
-
|
|
94
|
+
let [i, r, o] = c;
|
|
95
|
+
if (r = r || 0, r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, o = o || 0, o = o > 60 ? o / Math.pow(10, String(o).length - 2) : o, i > 360 && !r) {
|
|
96
|
+
const a = this.roundPrecision(i / 100, 0);
|
|
97
|
+
r = i - a * 100, i = a;
|
|
95
98
|
}
|
|
96
|
-
n =
|
|
99
|
+
n = i + r / 60 + o / 3600, s === "W" && (n = n * -1);
|
|
97
100
|
} else
|
|
98
101
|
n = Number(t);
|
|
99
102
|
return h.convertToStdLng(n, e);
|
|
@@ -105,12 +108,12 @@ class h {
|
|
|
105
108
|
const s = t[t.length - 1].toUpperCase();
|
|
106
109
|
t = t.substring(0, t.length - 1).trim();
|
|
107
110
|
const c = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
108
|
-
let [
|
|
109
|
-
if (o = o || 0,
|
|
110
|
-
const a = this.roundPrecision(
|
|
111
|
-
|
|
111
|
+
let [i, r, o] = c;
|
|
112
|
+
if (o = o || 0, r = r || 0, r = r > 60 ? r / Math.pow(10, String(r).length - 2) : r, o = o > 60 ? o / Math.pow(10, String(o).length - 2) : o, i > 90 && !r) {
|
|
113
|
+
const a = this.roundPrecision(i / 100, 0);
|
|
114
|
+
r = i - a * 100, i = a;
|
|
112
115
|
}
|
|
113
|
-
if (n =
|
|
116
|
+
if (n = i + r / 60 + o / 3600, n > 90)
|
|
114
117
|
throw new Error(`latitude out of range: ${t}${s}`);
|
|
115
118
|
s === "S" && (n = n * -1);
|
|
116
119
|
} else
|
|
@@ -175,26 +178,32 @@ class h {
|
|
|
175
178
|
return s >= 1 ? c : n > 0 ? `${c}.${Math.trunc(s * Math.pow(10, n)).toString().padStart(n, "0")}` : c;
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
|
-
class
|
|
181
|
+
const z = class z {
|
|
182
|
+
/**
|
|
183
|
+
* 是否船报点,type 大小写不敏感
|
|
184
|
+
*/
|
|
185
|
+
static isShipReport(t) {
|
|
186
|
+
return z.shipReportTypes.includes(String((t == null ? void 0 : t.type) ?? "").toUpperCase());
|
|
187
|
+
}
|
|
179
188
|
static json2Str(t) {
|
|
180
189
|
const e = t.type ? t.type[0].toUpperCase() : "A";
|
|
181
190
|
return `${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo || {})}|${t.vendor}|${t.deleted}`;
|
|
182
191
|
}
|
|
183
192
|
static str2Json(t) {
|
|
184
|
-
const [e, n, s, c,
|
|
193
|
+
const [e, n, s, c, i, r, o, a, u, l, m] = t.split("|");
|
|
185
194
|
return {
|
|
186
195
|
lat: Number(e),
|
|
187
196
|
lng: Number(n),
|
|
188
197
|
positionTime: Number(s),
|
|
189
198
|
sog: Number(c),
|
|
190
|
-
cog: Number(
|
|
191
|
-
hdg: Number(
|
|
199
|
+
cog: Number(i),
|
|
200
|
+
hdg: Number(r),
|
|
192
201
|
//@ts-ignore
|
|
193
202
|
draught: isNaN(o) ? null : Number(o),
|
|
194
203
|
type: a,
|
|
195
204
|
important: a !== "A",
|
|
196
|
-
meteo:
|
|
197
|
-
vendor:
|
|
205
|
+
meteo: u ? JSON.parse(u) : void 0,
|
|
206
|
+
vendor: l,
|
|
198
207
|
deleted: m === "true"
|
|
199
208
|
};
|
|
200
209
|
}
|
|
@@ -202,48 +211,45 @@ class K {
|
|
|
202
211
|
if (t.length < 2)
|
|
203
212
|
return t;
|
|
204
213
|
const s = t.at(0).positionTime < t.at(-1).positionTime;
|
|
205
|
-
s || t.sort((
|
|
206
|
-
const c = [];
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
r && (i = t[l - 1], o = l);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if ((i == null ? void 0 : i.positionTime) > (r == null ? void 0 : r.positionTime) && r) {
|
|
224
|
-
const l = {
|
|
225
|
-
start: {
|
|
226
|
-
lat: r.lat,
|
|
227
|
-
lng: r.lng,
|
|
228
|
-
sog: r.sog,
|
|
229
|
-
positionTime: r.positionTime,
|
|
230
|
-
utc: N.unix(r.positionTime).utc().format()
|
|
231
|
-
},
|
|
232
|
-
end: {
|
|
233
|
-
lat: i.lat,
|
|
234
|
-
lng: i.lng,
|
|
235
|
-
sog: i.sog,
|
|
236
|
-
positionTime: i.positionTime,
|
|
237
|
-
utc: N.unix(i.positionTime).utc().format()
|
|
238
|
-
},
|
|
239
|
-
duration: i.positionTime - r.positionTime
|
|
240
|
-
}, u = t.filter((d) => d.positionTime >= l.start.positionTime && d.positionTime <= l.end.positionTime), m = S.divideAccordingToLng(u);
|
|
241
|
-
l.distance = S.calculateRouteDistance(m), l.hours = Math.round(l.duration / 3600 * 10) / 10, l.hours && (l.avgSog = Math.round(l.distance / l.hours * 10) / 10, c.push(l));
|
|
214
|
+
s || t.sort((a, u) => a.positionTime - u.positionTime);
|
|
215
|
+
const c = [], i = n ? t.filter((a) => !z.isShipReport(a)) : t;
|
|
216
|
+
if (i.length < 2)
|
|
217
|
+
return c;
|
|
218
|
+
let r, o;
|
|
219
|
+
for (let a = 0; a < i.length - 1; a++) {
|
|
220
|
+
const u = i[a];
|
|
221
|
+
for (let l = a + 1; l < i.length; l++) {
|
|
222
|
+
const m = i[l - 1], d = i[l], p = d.positionTime - m.positionTime;
|
|
223
|
+
if (b.calculateDistance(d, m, !0, 4) / (p / 3600) < e)
|
|
224
|
+
r || (r = u), l === i.length - 1 && (o = d, a = l);
|
|
225
|
+
else {
|
|
226
|
+
r && (o = i[l - 1], a = l);
|
|
227
|
+
break;
|
|
242
228
|
}
|
|
243
|
-
r = void 0, i = void 0;
|
|
244
229
|
}
|
|
230
|
+
if ((o == null ? void 0 : o.positionTime) > (r == null ? void 0 : r.positionTime) && r) {
|
|
231
|
+
const l = {
|
|
232
|
+
start: {
|
|
233
|
+
lat: r.lat,
|
|
234
|
+
lng: r.lng,
|
|
235
|
+
sog: r.sog,
|
|
236
|
+
positionTime: r.positionTime,
|
|
237
|
+
utc: N.unix(r.positionTime).utc().format()
|
|
238
|
+
},
|
|
239
|
+
end: {
|
|
240
|
+
lat: o.lat,
|
|
241
|
+
lng: o.lng,
|
|
242
|
+
sog: o.sog,
|
|
243
|
+
positionTime: o.positionTime,
|
|
244
|
+
utc: N.unix(o.positionTime).utc().format()
|
|
245
|
+
},
|
|
246
|
+
duration: o.positionTime - r.positionTime
|
|
247
|
+
}, m = i.filter((p) => p.positionTime >= l.start.positionTime && p.positionTime <= l.end.positionTime), d = b.divideAccordingToLng(m);
|
|
248
|
+
l.distance = b.calculateRouteDistance(d), l.hours = Math.round(l.duration / 3600 * 10) / 10, l.hours && (l.avgSog = Math.round(l.distance / l.hours * 10) / 10, c.push(l));
|
|
249
|
+
}
|
|
250
|
+
r = void 0, o = void 0;
|
|
245
251
|
}
|
|
246
|
-
return s || t.sort((
|
|
252
|
+
return s || t.sort((a, u) => u.positionTime - a.positionTime), c;
|
|
247
253
|
}
|
|
248
254
|
/**
|
|
249
255
|
* 计算轨迹摘要
|
|
@@ -252,25 +258,29 @@ class K {
|
|
|
252
258
|
* @param etm
|
|
253
259
|
*/
|
|
254
260
|
static inspectSummary(t, e, n) {
|
|
255
|
-
const s = N(e), c = N(n),
|
|
256
|
-
let
|
|
257
|
-
if (
|
|
258
|
-
for (let
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
+
const s = N(e), c = N(n), i = t.filter((u) => u.positionTime >= s.unix() && u.positionTime <= c.unix());
|
|
262
|
+
let r = 0, o = 0;
|
|
263
|
+
if (i.length > 1)
|
|
264
|
+
for (let u = 0; u < i.length - 1; u++) {
|
|
265
|
+
const l = i[u], m = i[u + 1];
|
|
266
|
+
r += b.calculateDistance(l, m, !0, 4), o += Math.abs(m.positionTime - l.positionTime);
|
|
261
267
|
}
|
|
262
|
-
|
|
263
|
-
const a = o ? Math.round(
|
|
264
|
-
return { distance:
|
|
268
|
+
r = Math.round(r * 100) / 100, o = Math.round(o / 3600 * 100) / 100;
|
|
269
|
+
const a = o ? Math.round(r / o * 100) / 100 : 0;
|
|
270
|
+
return { distance: r, interval: o, avgSpd: a };
|
|
265
271
|
}
|
|
266
|
-
}
|
|
267
|
-
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* 船报点类型,其定位精度与 AIS 不一致,参与航速推算会干扰停泊判定
|
|
275
|
+
*/
|
|
276
|
+
K(z, "shipReportTypes", ["N", "C", "B", "E", "NOON", "COSP", "BOSP", "EOSP"]);
|
|
277
|
+
let V = z, X;
|
|
268
278
|
try {
|
|
269
|
-
X =
|
|
279
|
+
X = J.getLogger("meteo");
|
|
270
280
|
} catch {
|
|
271
281
|
} finally {
|
|
272
282
|
}
|
|
273
|
-
const
|
|
283
|
+
const tt = (() => {
|
|
274
284
|
const C = new Uint32Array(256);
|
|
275
285
|
for (let t = 0; t < 256; t++) {
|
|
276
286
|
let e = t;
|
|
@@ -280,42 +290,42 @@ const Y = (() => {
|
|
|
280
290
|
}
|
|
281
291
|
return C;
|
|
282
292
|
})();
|
|
283
|
-
function
|
|
293
|
+
function et(C) {
|
|
284
294
|
let t = 4294967295;
|
|
285
295
|
for (let e = 0; e < C.length; e++)
|
|
286
|
-
t =
|
|
296
|
+
t = tt[(t ^ C[e]) & 255] ^ t >>> 8;
|
|
287
297
|
return (t ^ 4294967295) >>> 0;
|
|
288
298
|
}
|
|
289
|
-
function
|
|
299
|
+
function nt(C) {
|
|
290
300
|
const t = new TextEncoder(), e = [], n = [];
|
|
291
301
|
let s = 0;
|
|
292
302
|
for (const d of C) {
|
|
293
|
-
const p = t.encode(d.name), f =
|
|
294
|
-
|
|
303
|
+
const p = t.encode(d.name), f = et(d.data), g = new Uint8Array(30 + p.length), S = new DataView(g.buffer);
|
|
304
|
+
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), g.set(p, 30), e.push({ nameBytes: p, data: d.data, crc: f, offset: s }), s += g.length + d.data.length, n.push(g, d.data);
|
|
295
305
|
}
|
|
296
|
-
const c = s,
|
|
297
|
-
let
|
|
306
|
+
const c = s, i = [];
|
|
307
|
+
let r = 0;
|
|
298
308
|
for (const d of e) {
|
|
299
309
|
const p = new Uint8Array(46 + d.nameBytes.length), f = new DataView(p.buffer);
|
|
300
|
-
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),
|
|
310
|
+
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), r += p.length, i.push(p);
|
|
301
311
|
}
|
|
302
312
|
const o = new Uint8Array(22), a = new DataView(o.buffer);
|
|
303
|
-
a.setUint32(0, 101010256, !0), a.setUint16(8, e.length, !0), a.setUint16(10, e.length, !0), a.setUint32(12,
|
|
304
|
-
const
|
|
313
|
+
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);
|
|
314
|
+
const u = n.reduce((d, p) => d + p.length, 0) + r + 22, l = new Uint8Array(u);
|
|
305
315
|
let m = 0;
|
|
306
316
|
for (const d of n)
|
|
307
|
-
|
|
308
|
-
for (const d of
|
|
309
|
-
|
|
310
|
-
return
|
|
317
|
+
l.set(d, m), m += d.length;
|
|
318
|
+
for (const d of i)
|
|
319
|
+
l.set(d, m), m += d.length;
|
|
320
|
+
return l.set(o, m), l;
|
|
311
321
|
}
|
|
312
|
-
function
|
|
322
|
+
function G(C) {
|
|
313
323
|
let t = "", e = C;
|
|
314
324
|
for (; e >= 0; )
|
|
315
325
|
t = String.fromCharCode(65 + e % 26) + t, e = Math.floor(e / 26) - 1;
|
|
316
326
|
return t;
|
|
317
327
|
}
|
|
318
|
-
class
|
|
328
|
+
class b {
|
|
319
329
|
/**
|
|
320
330
|
* 计算方位角
|
|
321
331
|
* @param from 坐标 {lng, lat}
|
|
@@ -329,8 +339,8 @@ class S {
|
|
|
329
339
|
[t.lng, t.lat],
|
|
330
340
|
[e.lng, e.lat]
|
|
331
341
|
]);
|
|
332
|
-
let
|
|
333
|
-
return n ?
|
|
342
|
+
let i;
|
|
343
|
+
return n ? i = T.rhumbBearing(c.features[0], c.features[1]) : i = T.bearing(c.features[0], c.features[1]), i < 0 && (i += 360), h.roundPrecision(i, s);
|
|
334
344
|
}
|
|
335
345
|
/**
|
|
336
346
|
* 计算两点间距离
|
|
@@ -343,12 +353,12 @@ class S {
|
|
|
343
353
|
*/
|
|
344
354
|
static calculateDistance(t, e, n = !0, s = 4, c = "nauticalmiles") {
|
|
345
355
|
t = { ...t }, e = { ...e }, t.lng = h.convertToStdLng(t.lng, s), e.lng = h.convertToStdLng(e.lng, s);
|
|
346
|
-
const
|
|
356
|
+
const i = T.points([
|
|
347
357
|
[t.lng, t.lat],
|
|
348
358
|
[e.lng, e.lat]
|
|
349
359
|
]);
|
|
350
|
-
let
|
|
351
|
-
return n ?
|
|
360
|
+
let r;
|
|
361
|
+
return n ? r = T.rhumbDistance(i.features[0], i.features[1], { units: c }) : r = T.distance(i.features[0], i.features[1], { units: c }), h.roundPrecision(r, s);
|
|
352
362
|
}
|
|
353
363
|
/**
|
|
354
364
|
* 计算航线距离
|
|
@@ -358,11 +368,11 @@ class S {
|
|
|
358
368
|
*/
|
|
359
369
|
static calculateRouteDistance(t, e = 4, n = "nauticalmiles") {
|
|
360
370
|
let s = 0, c;
|
|
361
|
-
for (const
|
|
362
|
-
for (let
|
|
363
|
-
const o = { lng: r
|
|
364
|
-
|
|
365
|
-
const a = { lng: r
|
|
371
|
+
for (const i of t)
|
|
372
|
+
for (let r = 0; r < i.length - 1; r++) {
|
|
373
|
+
const o = { lng: i[r][0], lat: i[r][1] };
|
|
374
|
+
r === 0 && c && (s += this.calculateDistance(c, o, !0, e, n));
|
|
375
|
+
const a = { lng: i[r + 1][0], lat: i[r + 1][1] };
|
|
366
376
|
s += this.calculateDistance(o, a, !0, e, n), c = a;
|
|
367
377
|
}
|
|
368
378
|
return h.roundPrecision(s, e);
|
|
@@ -376,10 +386,10 @@ class S {
|
|
|
376
386
|
* @param rhumb
|
|
377
387
|
*/
|
|
378
388
|
static calculateCoordinate(t, e, n, s = "nauticalmiles", c = !0) {
|
|
379
|
-
const
|
|
380
|
-
let
|
|
381
|
-
c ?
|
|
382
|
-
const o =
|
|
389
|
+
const i = T.point([t.lng, t.lat]);
|
|
390
|
+
let r;
|
|
391
|
+
c ? r = T.rhumbDestination(i, n, e, { units: s }) : r = T.destination(i, n, e, { units: s });
|
|
392
|
+
const o = r.geometry.coordinates;
|
|
383
393
|
return { lng: h.convertToStdLng(o[0], 8), lat: h.roundPrecision(o[1], 8) };
|
|
384
394
|
}
|
|
385
395
|
/**
|
|
@@ -391,13 +401,13 @@ class S {
|
|
|
391
401
|
* @param includeTail true 包含终点 to
|
|
392
402
|
* @param units 单位,默认 nm(海里)
|
|
393
403
|
*/
|
|
394
|
-
static interpolateCoordinates(t, e, n, s = !0, c = !0,
|
|
395
|
-
const
|
|
396
|
-
s &&
|
|
397
|
-
let
|
|
398
|
-
for (;
|
|
399
|
-
|
|
400
|
-
return c &&
|
|
404
|
+
static interpolateCoordinates(t, e, n, s = !0, c = !0, i = "nauticalmiles") {
|
|
405
|
+
const r = [], o = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, i);
|
|
406
|
+
s && r.push({ lng: t.lng, lat: t.lat });
|
|
407
|
+
let u = 0;
|
|
408
|
+
for (; u < a; )
|
|
409
|
+
u += n, u < a && r.push(this.calculateCoordinate(t, o, u, i, !1));
|
|
410
|
+
return c && r.push({ lng: e.lng, lat: e.lat }), r;
|
|
401
411
|
}
|
|
402
412
|
/**
|
|
403
413
|
* 分组坐标(如相邻两个坐标经度差超180度,需以180为界将坐标分为两组)
|
|
@@ -417,21 +427,21 @@ class S {
|
|
|
417
427
|
t = n ? this.deduplicateCoordinates(t) : t;
|
|
418
428
|
let s = [];
|
|
419
429
|
const c = [];
|
|
420
|
-
let
|
|
430
|
+
let i, r;
|
|
421
431
|
for (let o = 0; o < t.length - 1; o++) {
|
|
422
|
-
|
|
423
|
-
const a =
|
|
432
|
+
i = h.convertToStdLng(t[o].lng, 8), r = h.convertToStdLng(t[o + 1].lng, 8), t[o].lat = h.roundPrecision(t[o].lat, 8), t[o + 1].lat = h.roundPrecision(t[o + 1].lat, 8), s.push([i, t[o].lat]);
|
|
433
|
+
const a = i - r;
|
|
424
434
|
if (Math.abs(a) > 180) {
|
|
425
|
-
const
|
|
426
|
-
[
|
|
427
|
-
[
|
|
435
|
+
const u = h.convertToMonotonicLng2([
|
|
436
|
+
[i, t[o].lat],
|
|
437
|
+
[r, t[o + 1].lat]
|
|
428
438
|
]);
|
|
429
|
-
let
|
|
430
|
-
e ? (
|
|
439
|
+
let l, m;
|
|
440
|
+
e ? (l = T.lineString(u), m = T.lineString([
|
|
431
441
|
[a > 0 ? 180 : -180, 89],
|
|
432
442
|
[a > 0 ? 180 : -180, -89]
|
|
433
|
-
])) : (
|
|
434
|
-
const d = T.lineIntersect(
|
|
443
|
+
])) : (l = T.greatCircle(u[0], u[1]), m = T.greatCircle([a > 0 ? 180 : -180, 89], [a > 0 ? 180 : -180, -89]));
|
|
444
|
+
const d = T.lineIntersect(l, m);
|
|
435
445
|
let p;
|
|
436
446
|
if (d.features.length) {
|
|
437
447
|
const f = T.getCoord(d.features[0]);
|
|
@@ -440,7 +450,7 @@ class S {
|
|
|
440
450
|
p = t[o].lat;
|
|
441
451
|
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]));
|
|
442
452
|
}
|
|
443
|
-
o === t.length - 2 && s.push([
|
|
453
|
+
o === t.length - 2 && s.push([r, t[o + 1].lat]);
|
|
444
454
|
}
|
|
445
455
|
return c.push(s), c;
|
|
446
456
|
}
|
|
@@ -451,7 +461,7 @@ class S {
|
|
|
451
461
|
static deduplicateRoute(t) {
|
|
452
462
|
const e = [];
|
|
453
463
|
for (const n of t) {
|
|
454
|
-
const s = n.reduce((c,
|
|
464
|
+
const s = n.reduce((c, i) => (c.findIndex((r) => r[0] === i[0] && r[1] === i[1]) === -1 && c.push(i), c), []);
|
|
455
465
|
e.push(s);
|
|
456
466
|
}
|
|
457
467
|
return e;
|
|
@@ -499,13 +509,13 @@ class S {
|
|
|
499
509
|
*/
|
|
500
510
|
static mergeCoordinateToRoute(t, e) {
|
|
501
511
|
t.lng = h.convertToStdLng(t.lng, 8);
|
|
502
|
-
let n = Number.MAX_VALUE, s = 0, c = 0,
|
|
512
|
+
let n = Number.MAX_VALUE, s = 0, c = 0, i, r;
|
|
503
513
|
return e.forEach((o, a) => {
|
|
504
|
-
for (let
|
|
505
|
-
const
|
|
506
|
-
n > d && (n = d, c =
|
|
514
|
+
for (let u = 0; u < o.length - 1; u++) {
|
|
515
|
+
const l = { lng: o[u][0], lat: o[u][1] }, m = { lng: o[u + 1][0], lat: o[u + 1][1] }, d = this.calculatePointToLineDistance(t, l, m);
|
|
516
|
+
n > d && (n = d, c = u, s = a, i = this.calculateDistance(l, t), r = this.calculateDistance(m, t));
|
|
507
517
|
}
|
|
508
|
-
}),
|
|
518
|
+
}), i !== 0 && r !== 0 ? e[s].splice(c + 1, 0, [t.lng, t.lat]) : i === 0 ? e[s].splice(c, 1, [t.lng, t.lat]) : r === 0 && e[s].splice(c + 1, 1, [t.lng, t.lat]), e;
|
|
509
519
|
}
|
|
510
520
|
/**
|
|
511
521
|
* 向Route尾加1个坐标
|
|
@@ -514,8 +524,8 @@ class S {
|
|
|
514
524
|
*/
|
|
515
525
|
static appendCoordinateToRoute(t, e) {
|
|
516
526
|
t.lng = h.convertToStdLng(t.lng, 8);
|
|
517
|
-
const n =
|
|
518
|
-
return n.push(t),
|
|
527
|
+
const n = b.convertRouteToCoordinates(e);
|
|
528
|
+
return n.push(t), b.divideAccordingToLng(n);
|
|
519
529
|
}
|
|
520
530
|
/**
|
|
521
531
|
* 向route头加1个坐标
|
|
@@ -523,8 +533,8 @@ class S {
|
|
|
523
533
|
* @param route
|
|
524
534
|
*/
|
|
525
535
|
static unshiftCoordinateToRoute(t, e) {
|
|
526
|
-
const n =
|
|
527
|
-
return n.unshift(t),
|
|
536
|
+
const n = b.convertRouteToCoordinates(e);
|
|
537
|
+
return n.unshift(t), b.divideAccordingToLng(n);
|
|
528
538
|
}
|
|
529
539
|
/**
|
|
530
540
|
* 合并多个waypoints进航线
|
|
@@ -547,18 +557,18 @@ class S {
|
|
|
547
557
|
n = this.mergeWaypointsToRoute([t, e], n);
|
|
548
558
|
const s = [];
|
|
549
559
|
let c = 0;
|
|
550
|
-
return n.forEach((
|
|
560
|
+
return n.forEach((i) => {
|
|
551
561
|
if (c === 2)
|
|
552
562
|
return;
|
|
553
|
-
const
|
|
554
|
-
for (const o of
|
|
563
|
+
const r = [];
|
|
564
|
+
for (const o of i) {
|
|
555
565
|
if (h.roundPrecision(e.lng, 8) === h.roundPrecision(o[0], 8) && h.roundPrecision(e.lat, 8) === h.roundPrecision(o[1], 8)) {
|
|
556
|
-
|
|
566
|
+
r.push(o), c === 0 && r.push([t.lng, t.lat]), c = 2;
|
|
557
567
|
break;
|
|
558
568
|
}
|
|
559
|
-
c === 1 ?
|
|
569
|
+
c === 1 ? r.push(o) : h.roundPrecision(t.lng, 8) === h.roundPrecision(o[0], 8) && h.roundPrecision(t.lat, 8) === h.roundPrecision(o[1], 8) && (c = 1, r.push(o));
|
|
560
570
|
}
|
|
561
|
-
|
|
571
|
+
r.length && s.push(r);
|
|
562
572
|
}), s;
|
|
563
573
|
}
|
|
564
574
|
/**
|
|
@@ -570,12 +580,12 @@ class S {
|
|
|
570
580
|
* @return [{lng, lat}]
|
|
571
581
|
*/
|
|
572
582
|
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
573
|
-
const c = this.convertRouteToCoordinates(n, 0),
|
|
574
|
-
(
|
|
575
|
-
), o =
|
|
576
|
-
(
|
|
583
|
+
const c = this.convertRouteToCoordinates(n, 0), i = this.mergeCoordinatesToWaypoints([t, e], c.length ? c : s), r = i.findIndex(
|
|
584
|
+
(u) => h.roundPrecision(t.lng, 8) === h.roundPrecision(u.lng, 8) && h.roundPrecision(t.lat, 8) === h.roundPrecision(u.lat, 8)
|
|
585
|
+
), o = i.findIndex(
|
|
586
|
+
(u) => h.roundPrecision(e.lng, 8) === h.roundPrecision(u.lng, 8) && h.roundPrecision(e.lat, 8) === h.roundPrecision(u.lat, 8)
|
|
577
587
|
);
|
|
578
|
-
return
|
|
588
|
+
return i.filter((u, l) => l >= r && l <= o);
|
|
579
589
|
}
|
|
580
590
|
/**
|
|
581
591
|
* 计算坐标到航路上的最短距离
|
|
@@ -584,10 +594,10 @@ class S {
|
|
|
584
594
|
*/
|
|
585
595
|
static calculateMinDistanceToRoute(t, e) {
|
|
586
596
|
let n = Number.MAX_VALUE, s = 0, c = 0;
|
|
587
|
-
return e.forEach((
|
|
588
|
-
for (let o = 0; o <
|
|
589
|
-
const a = { lng:
|
|
590
|
-
n >
|
|
597
|
+
return e.forEach((i, r) => {
|
|
598
|
+
for (let o = 0; o < i.length - 1; o++) {
|
|
599
|
+
const a = { lng: i[o][0], lat: i[o][1] }, u = { lng: i[o + 1][0], lat: i[o + 1][1] }, l = this.calculatePointToLineDistance(t, a, u);
|
|
600
|
+
n > l && (n = l, s = o, c = r);
|
|
591
601
|
}
|
|
592
602
|
}), { minDist: n, segIndex: c, minIndex: s };
|
|
593
603
|
}
|
|
@@ -598,22 +608,22 @@ class S {
|
|
|
598
608
|
* @return [[[lng, lat]]]
|
|
599
609
|
*/
|
|
600
610
|
static calculateSubRoute(t, e) {
|
|
601
|
-
const n =
|
|
602
|
-
|
|
611
|
+
const n = b.convertRouteToCoordinates(e);
|
|
612
|
+
b.mergeCoordinateToWaypoints(t, n, !0), e = b.divideAccordingToLng(n);
|
|
603
613
|
const { segIndex: s, minIndex: c } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
604
614
|
t.lng = h.convertToStdLng(t.lng);
|
|
605
|
-
const
|
|
606
|
-
let
|
|
615
|
+
const i = [];
|
|
616
|
+
let r = !0;
|
|
607
617
|
for (let o = s; o < e.length; o++)
|
|
608
|
-
if (
|
|
618
|
+
if (r) {
|
|
609
619
|
const a = [];
|
|
610
620
|
a.push([t.lng, t.lat]);
|
|
611
|
-
for (let
|
|
612
|
-
t.lng === e[o][
|
|
613
|
-
|
|
621
|
+
for (let u = c + 1; u < e[o].length; u++)
|
|
622
|
+
t.lng === e[o][u][0] && t.lat === e[o][u][1] || a.push(e[o][u]);
|
|
623
|
+
i.push(a), r = !1;
|
|
614
624
|
} else
|
|
615
|
-
|
|
616
|
-
return
|
|
625
|
+
i.push([...e[o]]);
|
|
626
|
+
return i;
|
|
617
627
|
}
|
|
618
628
|
/**
|
|
619
629
|
* 计算子途经点
|
|
@@ -623,19 +633,19 @@ class S {
|
|
|
623
633
|
*/
|
|
624
634
|
static calculateSubWaypoints(t, e) {
|
|
625
635
|
let n = Number.MAX_VALUE, s = 0;
|
|
626
|
-
for (let
|
|
627
|
-
const
|
|
628
|
-
if (this.calculateDistance(t,
|
|
636
|
+
for (let i = 0; i < e.length - 1; i++) {
|
|
637
|
+
const r = e[i], o = e[i + 1];
|
|
638
|
+
if (this.calculateDistance(t, r) === 0)
|
|
629
639
|
return e;
|
|
630
640
|
if (this.calculateDistance(t, o) === 0)
|
|
631
|
-
return e.filter((
|
|
632
|
-
const a = this.calculatePointToLineDistance(t,
|
|
633
|
-
n > a && (n = a, s =
|
|
641
|
+
return e.filter((u, l) => l > 0);
|
|
642
|
+
const a = this.calculatePointToLineDistance(t, r, o);
|
|
643
|
+
n > a && (n = a, s = i);
|
|
634
644
|
}
|
|
635
645
|
t.lng = h.convertToStdLng(t.lng);
|
|
636
646
|
const c = [t];
|
|
637
|
-
for (let
|
|
638
|
-
c.push(e[
|
|
647
|
+
for (let i = s + 1; i < e.length; i++)
|
|
648
|
+
c.push(e[i]);
|
|
639
649
|
return c;
|
|
640
650
|
}
|
|
641
651
|
/**
|
|
@@ -649,11 +659,11 @@ class S {
|
|
|
649
659
|
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);
|
|
650
660
|
const c = h.convertToMonotonicLng([e, n]);
|
|
651
661
|
e = c[0], n = c[1];
|
|
652
|
-
const
|
|
662
|
+
const i = T.lineString([
|
|
653
663
|
[e.lng, e.lat],
|
|
654
664
|
[n.lng, n.lat]
|
|
655
|
-
]),
|
|
656
|
-
return h.roundPrecision(Math.min(
|
|
665
|
+
]), 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);
|
|
666
|
+
return h.roundPrecision(Math.min(r, o), 6);
|
|
657
667
|
}
|
|
658
668
|
/**
|
|
659
669
|
* 计算途经点的COG, Distance等属性
|
|
@@ -663,8 +673,8 @@ class S {
|
|
|
663
673
|
static calculateWaypointsPropInRoute(t, e) {
|
|
664
674
|
e = this.mergeWaypointsToRoute(t, e);
|
|
665
675
|
for (let n = 0; n < t.length - 1; n++) {
|
|
666
|
-
const s = t[n], c = t[n + 1],
|
|
667
|
-
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), c.distanceFromPrevious = this.calculateRouteDistance(
|
|
676
|
+
const s = t[n], c = t[n + 1], i = this.calculateRangeRoute(s, c, e);
|
|
677
|
+
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), c.distanceFromPrevious = this.calculateRouteDistance(i), c.distanceFromStart = h.roundPrecision((s.distanceFromStart || 0) + c.distanceFromPrevious);
|
|
668
678
|
}
|
|
669
679
|
return t;
|
|
670
680
|
}
|
|
@@ -692,22 +702,22 @@ class S {
|
|
|
692
702
|
*/
|
|
693
703
|
static mergeCoordinateToWaypoints(t, e, n = !0) {
|
|
694
704
|
t.lng = h.convertToStdLng(t.lng, 8);
|
|
695
|
-
let s = Number.MAX_VALUE, c = 0,
|
|
705
|
+
let s = Number.MAX_VALUE, c = 0, i = 0, r = 0;
|
|
696
706
|
if (e.length < 2)
|
|
697
707
|
e.push(t);
|
|
698
708
|
else {
|
|
699
709
|
for (let o = 0; o < e.length - 1; o++) {
|
|
700
|
-
const a = { lng: e[o].lng, lat: e[o].lat },
|
|
701
|
-
s >=
|
|
710
|
+
const a = { lng: e[o].lng, lat: e[o].lat }, u = { lng: e[o + 1].lng, lat: e[o + 1].lat }, l = this.calculatePointToLineDistance(t, a, u);
|
|
711
|
+
s >= l && (s = l, c = o, i = this.calculateDistance(a, t, !1, 6), r = this.calculateDistance(u, t, !1, 6));
|
|
702
712
|
}
|
|
703
|
-
|
|
713
|
+
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));
|
|
704
714
|
}
|
|
705
715
|
return e.map((o, a) => {
|
|
706
716
|
o.lng = h.convertToStdLng(o.lng);
|
|
707
|
-
const
|
|
708
|
-
if (
|
|
709
|
-
const
|
|
710
|
-
o.sog = h.roundPrecision(
|
|
717
|
+
const u = e[a + 1];
|
|
718
|
+
if (u && ((o.bearing === null || o.bearing === void 0) && ((o.positionTime || 0) > (u.positionTime || 0) ? o.bearing = this.calculateBearing(u, o, !0) : o.bearing = this.calculateBearing(o, u, !0)), o.cog = o.cog || o.bearing, !o.sog && o.positionTime && u.positionTime)) {
|
|
719
|
+
const l = this.calculateDistance(o, u, !0), m = Math.abs(u.positionTime - o.positionTime) / 3600;
|
|
720
|
+
o.sog = h.roundPrecision(l / m, 2);
|
|
711
721
|
}
|
|
712
722
|
return o;
|
|
713
723
|
});
|
|
@@ -722,12 +732,12 @@ class S {
|
|
|
722
732
|
static generateRouteAccordingToWaypoints(t, e = !0, n = !0) {
|
|
723
733
|
const s = [];
|
|
724
734
|
for (let c = 1; c < t.length; c++) {
|
|
725
|
-
const
|
|
726
|
-
if (c === 1 && s.push(
|
|
727
|
-
const o = this.interpolateCoordinates(
|
|
735
|
+
const i = t[c - 1], r = t[c];
|
|
736
|
+
if (c === 1 && s.push(i), r.gcToPrevious) {
|
|
737
|
+
const o = this.interpolateCoordinates(i, r, 200, !1, !0, "nauticalmiles");
|
|
728
738
|
s.push(...o);
|
|
729
739
|
} else
|
|
730
|
-
s.push(
|
|
740
|
+
s.push(r);
|
|
731
741
|
}
|
|
732
742
|
return this.divideAccordingToLng(s, e, n);
|
|
733
743
|
}
|
|
@@ -737,7 +747,7 @@ class S {
|
|
|
737
747
|
* @param route [[[lng, lat]]]
|
|
738
748
|
*/
|
|
739
749
|
static nearestCoordinateInRoute(t, e) {
|
|
740
|
-
const n = T.point([t.lng, t.lat]), c = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]),
|
|
750
|
+
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);
|
|
741
751
|
return { lng: h.roundPrecision(o[0], 8), lat: h.roundPrecision(o[1], 8) };
|
|
742
752
|
}
|
|
743
753
|
/**
|
|
@@ -749,12 +759,12 @@ class S {
|
|
|
749
759
|
let n = 0;
|
|
750
760
|
this.mergeCoordinateToWaypoints(t, e);
|
|
751
761
|
for (let s = 0; s < e.length - 1; s++) {
|
|
752
|
-
const c = e[s],
|
|
762
|
+
const c = e[s], i = e[s + 1];
|
|
753
763
|
if (this.calculateDistance(t, c) === 0) {
|
|
754
764
|
n = s;
|
|
755
765
|
break;
|
|
756
766
|
}
|
|
757
|
-
if (this.calculateDistance(t,
|
|
767
|
+
if (this.calculateDistance(t, i) === 0) {
|
|
758
768
|
n = s + 1;
|
|
759
769
|
break;
|
|
760
770
|
}
|
|
@@ -771,41 +781,41 @@ class S {
|
|
|
771
781
|
*/
|
|
772
782
|
static calculateNextCoordinateAlongRoute(t, e, n, s = "nauticalmiles") {
|
|
773
783
|
var m;
|
|
774
|
-
const c = t.speed || 12,
|
|
775
|
-
let
|
|
776
|
-
if (e && n.length ? (
|
|
784
|
+
const c = t.speed || 12, i = [];
|
|
785
|
+
let r = [], o = !1, a = 0, u = 0, l;
|
|
786
|
+
if (e && n.length ? (i.push(t), n.forEach((d, p) => {
|
|
777
787
|
if (o)
|
|
778
|
-
|
|
788
|
+
r.push(d);
|
|
779
789
|
else {
|
|
780
790
|
const f = [];
|
|
781
791
|
let g;
|
|
782
|
-
for (let
|
|
783
|
-
if (
|
|
784
|
-
f.push(d[
|
|
792
|
+
for (let S = 0; S < d.length; S++)
|
|
793
|
+
if (l)
|
|
794
|
+
f.push(d[S]);
|
|
785
795
|
else {
|
|
786
|
-
g = { lng: d[
|
|
796
|
+
g = { lng: d[S][0], lat: d[S][1] };
|
|
787
797
|
const v = this.calculateDistance(t, g, !0, 8, s);
|
|
788
798
|
if (a += v, a < e)
|
|
789
|
-
|
|
799
|
+
u += v, v && i.push(g), t = g;
|
|
790
800
|
else {
|
|
791
|
-
if (
|
|
792
|
-
|
|
801
|
+
if (u = e, a === e)
|
|
802
|
+
l = g, f.push([l.lng, l.lat]);
|
|
793
803
|
else {
|
|
794
804
|
const x = a - e, y = this.calculateBearing(g, t);
|
|
795
|
-
|
|
805
|
+
l = this.calculateCoordinate(g, y, x, s), f.push([l.lng, l.lat]), f.push([g.lng, g.lat]);
|
|
796
806
|
}
|
|
797
807
|
o = !0;
|
|
798
808
|
}
|
|
799
809
|
}
|
|
800
|
-
f.length &&
|
|
810
|
+
f.length && r.push(f), p === n.length - 1 && !l && (l = g);
|
|
801
811
|
}
|
|
802
|
-
})) : (
|
|
803
|
-
if (
|
|
804
|
-
const d = { lng:
|
|
805
|
-
|
|
812
|
+
})) : (r = n, l = { ...t }), l)
|
|
813
|
+
if (i.push(l), l.distanceFromPrevious = Math.round(u * 1e4) / 1e4, l.hourFromPrevious = Math.round(u / c * 1e4) / 1e4, ((m = r[0]) == null ? void 0 : m.length) > 1) {
|
|
814
|
+
const d = { lng: r[0][1][0], lat: r[0][1][1] };
|
|
815
|
+
l.bearing = this.calculateBearing(l, d);
|
|
806
816
|
} else
|
|
807
|
-
|
|
808
|
-
return { coordinate:
|
|
817
|
+
l.bearing = 0;
|
|
818
|
+
return { coordinate: l, nextRoute: r, prevRoute: i };
|
|
809
819
|
}
|
|
810
820
|
/**
|
|
811
821
|
* 返回最近点及其是否为垂足(最近点不是起点或终点)
|
|
@@ -814,11 +824,11 @@ class S {
|
|
|
814
824
|
* @param to {lng, lat}
|
|
815
825
|
*/
|
|
816
826
|
static nearestCoordinateInLine(t, e, n) {
|
|
817
|
-
const s = h.convertToStdLng(t.lng, 6), c = T.point([s, t.lat]),
|
|
818
|
-
[
|
|
819
|
-
[
|
|
820
|
-
]), a = T.nearestPointOnLine(o, c),
|
|
821
|
-
return { lng:
|
|
827
|
+
const s = h.convertToStdLng(t.lng, 6), c = T.point([s, t.lat]), i = h.convertToStdLng(e.lng, 6), r = h.convertToStdLng(n.lng, 6), o = T.lineString([
|
|
828
|
+
[i, e.lat],
|
|
829
|
+
[r, n.lat]
|
|
830
|
+
]), a = T.nearestPointOnLine(o, c), u = T.getCoord(a), l = h.roundPrecision(u[0], 6), m = h.roundPrecision(u[1], 6);
|
|
831
|
+
return { lng: l, lat: m, inline: !(l === i && m === e.lat) && !(l === r && m === n.lat) };
|
|
822
832
|
}
|
|
823
833
|
/**
|
|
824
834
|
* 将route转coordinate
|
|
@@ -828,9 +838,9 @@ class S {
|
|
|
828
838
|
static convertRouteToCoordinates(t, e = 0) {
|
|
829
839
|
const n = [];
|
|
830
840
|
let s, c;
|
|
831
|
-
return t.forEach((
|
|
832
|
-
|
|
833
|
-
const o = { lng: h.roundPrecision(
|
|
841
|
+
return t.forEach((i) => {
|
|
842
|
+
i.forEach((r) => {
|
|
843
|
+
const o = { lng: h.roundPrecision(r[0], 8), lat: h.roundPrecision(r[1], 8) };
|
|
834
844
|
if (!c)
|
|
835
845
|
n.push(o), c = o;
|
|
836
846
|
else if (c.bearing === void 0 || c.bearing === null)
|
|
@@ -863,17 +873,17 @@ class S {
|
|
|
863
873
|
this.mergeCoordinateToWaypoints(s, t, !0);
|
|
864
874
|
});
|
|
865
875
|
for (let s = 1; s < e.length; s++) {
|
|
866
|
-
const c = e[s - 1],
|
|
867
|
-
if (
|
|
868
|
-
const
|
|
869
|
-
for (let a = o - 1; a >
|
|
876
|
+
const c = e[s - 1], i = e[s];
|
|
877
|
+
if (i.gcToPrevious) {
|
|
878
|
+
const r = t.findIndex((a) => a.lng === c.lng && a.lat === c.lat), o = t.findIndex((a) => a.lng === i.lng && a.lat === i.lat);
|
|
879
|
+
for (let a = o - 1; a > r; a--)
|
|
870
880
|
t.splice(a, 1);
|
|
871
881
|
}
|
|
872
882
|
}
|
|
873
883
|
let n = 0;
|
|
874
884
|
for (let s = 1; s < t.length; s++) {
|
|
875
|
-
const c = t[s - 1],
|
|
876
|
-
|
|
885
|
+
const c = t[s - 1], i = t[s];
|
|
886
|
+
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 = h.roundPrecision(n + i.distanceFromPrevious), i.distanceFromStart = n;
|
|
877
887
|
}
|
|
878
888
|
return t.map((s) => (s.lng = h.convertToStdLng(s.lng), s));
|
|
879
889
|
}
|
|
@@ -883,14 +893,14 @@ class S {
|
|
|
883
893
|
*/
|
|
884
894
|
static calculateCenter(t) {
|
|
885
895
|
const e = [];
|
|
886
|
-
for (const
|
|
887
|
-
for (const o of
|
|
896
|
+
for (const r of t)
|
|
897
|
+
for (const o of r)
|
|
888
898
|
e.push(o);
|
|
889
899
|
const n = T.featureCollection([]), s = h.convertToMonotonicLng2(e);
|
|
890
|
-
for (const
|
|
891
|
-
n.features.push(T.point(
|
|
892
|
-
const
|
|
893
|
-
return { lng: h.convertToStdLng(
|
|
900
|
+
for (const r of s)
|
|
901
|
+
n.features.push(T.point(r));
|
|
902
|
+
const i = T.center(n).geometry.coordinates;
|
|
903
|
+
return { lng: h.convertToStdLng(i[0], 8), lat: h.roundPrecision(i[1], 8) };
|
|
894
904
|
}
|
|
895
905
|
/**
|
|
896
906
|
* 计算中心点
|
|
@@ -907,8 +917,8 @@ class S {
|
|
|
907
917
|
static calculateBBox(t) {
|
|
908
918
|
const e = [];
|
|
909
919
|
for (const c of t)
|
|
910
|
-
for (const
|
|
911
|
-
e.push(
|
|
920
|
+
for (const i of c)
|
|
921
|
+
e.push(i);
|
|
912
922
|
const n = h.convertToMonotonicLng2(e), s = T.lineString(n);
|
|
913
923
|
return T.bbox(s);
|
|
914
924
|
}
|
|
@@ -932,8 +942,8 @@ class S {
|
|
|
932
942
|
static simplifyCoordinates(t, e = 1, n = 0) {
|
|
933
943
|
if (t.length <= 2)
|
|
934
944
|
return [...t];
|
|
935
|
-
const s =
|
|
936
|
-
return X.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)", t.length,
|
|
945
|
+
const s = b.rdpSimplify(t, e), i = (n > 0 ? b.splitLongLegs(t, s, n) : s).map((r) => t[r]);
|
|
946
|
+
return X.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)", t.length, i.length, e, n), i;
|
|
937
947
|
}
|
|
938
948
|
/**
|
|
939
949
|
* RDP 主循环:首尾点与强制标记点作为锚点分段,段内迭代栈求最大横向偏差
|
|
@@ -950,26 +960,26 @@ class S {
|
|
|
950
960
|
(a.important || a.pilot || a.suspend || a.velocity || a.gcToPrevious) && (n[o] = !0, s.push(o));
|
|
951
961
|
}
|
|
952
962
|
s.push(t.length - 1);
|
|
953
|
-
const c = t.map((o) =>
|
|
963
|
+
const c = t.map((o) => b.toUnitVector(o)), i = T.convertLength(1, "radians", "nauticalmiles");
|
|
954
964
|
for (let o = 0; o < s.length - 1; o++) {
|
|
955
965
|
const a = [[s[o], s[o + 1]]];
|
|
956
966
|
for (; a.length; ) {
|
|
957
|
-
const [
|
|
967
|
+
const [u, l] = a.pop(), m = c[u], d = c[l];
|
|
958
968
|
let p = m[1] * d[2] - m[2] * d[1], f = m[2] * d[0] - m[0] * d[2], g = m[0] * d[1] - m[1] * d[0];
|
|
959
|
-
const
|
|
960
|
-
v || (p /=
|
|
969
|
+
const S = Math.sqrt(p * p + f * f + g * g), v = S < 1e-12;
|
|
970
|
+
v || (p /= S, f /= S, g /= S);
|
|
961
971
|
let x = 0, y = -1;
|
|
962
|
-
for (let P =
|
|
963
|
-
const D = v ?
|
|
972
|
+
for (let P = u + 1; P < l; P++) {
|
|
973
|
+
const D = v ? b.calculateDistance(t[P], t[u]) : Math.asin(Math.min(1, Math.abs(c[P][0] * p + c[P][1] * f + c[P][2] * g))) * i;
|
|
964
974
|
D > x && (x = D, y = P);
|
|
965
975
|
}
|
|
966
|
-
x > e && (n[y] = !0, a.push([
|
|
976
|
+
x > e && (n[y] = !0, a.push([u, y], [y, l]));
|
|
967
977
|
}
|
|
968
978
|
}
|
|
969
|
-
const
|
|
979
|
+
const r = [];
|
|
970
980
|
for (let o = 0; o < n.length; o++)
|
|
971
|
-
n[o] &&
|
|
972
|
-
return
|
|
981
|
+
n[o] && r.push(o);
|
|
982
|
+
return r;
|
|
973
983
|
}
|
|
974
984
|
/**
|
|
975
985
|
* 最大腿长后处理:超过 maxLeg 的腿按腿内原始点累计里程均分为 ceil(leg/maxLeg) 段取点
|
|
@@ -981,20 +991,20 @@ class S {
|
|
|
981
991
|
static splitLongLegs(t, e, n) {
|
|
982
992
|
const s = [e[0]];
|
|
983
993
|
for (let c = 1; c < e.length; c++) {
|
|
984
|
-
const
|
|
985
|
-
if (o > n &&
|
|
986
|
-
const a = Math.ceil(o / n),
|
|
987
|
-
for (let
|
|
988
|
-
|
|
989
|
-
for (let
|
|
990
|
-
const m = o / a *
|
|
991
|
-
let d =
|
|
992
|
-
for (; d <
|
|
994
|
+
const i = s[s.length - 1], r = e[c], o = b.calculateDistance(t[i], t[r]);
|
|
995
|
+
if (o > n && r - i >= 2) {
|
|
996
|
+
const a = Math.ceil(o / n), u = [0];
|
|
997
|
+
for (let l = i + 1; l <= r; l++)
|
|
998
|
+
u.push(u[u.length - 1] + b.calculateDistance(t[l - 1], t[l]));
|
|
999
|
+
for (let l = 1; l < a; l++) {
|
|
1000
|
+
const m = o / a * l;
|
|
1001
|
+
let d = i + 1;
|
|
1002
|
+
for (; d < r - 1 && u[d - i] < m; )
|
|
993
1003
|
d++;
|
|
994
|
-
d >
|
|
1004
|
+
d > i && d < r && s[s.length - 1] !== d && s.push(d);
|
|
995
1005
|
}
|
|
996
1006
|
}
|
|
997
|
-
s.push(
|
|
1007
|
+
s.push(r);
|
|
998
1008
|
}
|
|
999
1009
|
return s;
|
|
1000
1010
|
}
|
|
@@ -1015,14 +1025,14 @@ class S {
|
|
|
1015
1025
|
* @returns {number} 单位 nm
|
|
1016
1026
|
*/
|
|
1017
1027
|
static perpendicularDeviation(t, e, n) {
|
|
1018
|
-
const s =
|
|
1019
|
-
let
|
|
1020
|
-
const
|
|
1021
|
-
if (
|
|
1022
|
-
return
|
|
1023
|
-
|
|
1024
|
-
const
|
|
1025
|
-
return Math.asin(Math.min(1, Math.abs(
|
|
1028
|
+
const s = b.toUnitVector(e), c = b.toUnitVector(n), i = b.toUnitVector(t);
|
|
1029
|
+
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];
|
|
1030
|
+
const u = Math.sqrt(r * r + o * o + a * a);
|
|
1031
|
+
if (u < 1e-12)
|
|
1032
|
+
return b.calculateDistance(t, e);
|
|
1033
|
+
r /= u, o /= u, a /= u;
|
|
1034
|
+
const l = T.convertLength(1, "radians", "nauticalmiles");
|
|
1035
|
+
return Math.asin(Math.min(1, Math.abs(i[0] * r + i[1] * o + i[2] * a))) * l;
|
|
1026
1036
|
}
|
|
1027
1037
|
/**
|
|
1028
1038
|
* 在时间轨迹上寻找ts最近的点
|
|
@@ -1032,9 +1042,9 @@ class S {
|
|
|
1032
1042
|
*/
|
|
1033
1043
|
static nearestTSPointInWaypoints(t, e, n) {
|
|
1034
1044
|
const s = N.unix(t), c = n.filter(
|
|
1035
|
-
(
|
|
1045
|
+
(i) => s.clone().subtract(e, "hour").unix() <= (i.positionTime || 0) && s.clone().add(e, "h").unix() >= (i.positionTime || 0)
|
|
1036
1046
|
);
|
|
1037
|
-
return c.sort((
|
|
1047
|
+
return c.sort((i, r) => (i.positionTime || 0) - (r.positionTime || 0)), c.at(-1);
|
|
1038
1048
|
}
|
|
1039
1049
|
/**
|
|
1040
1050
|
* 推测船位
|
|
@@ -1042,17 +1052,17 @@ class S {
|
|
|
1042
1052
|
* @param positions 带时间(positionTime)的轨迹
|
|
1043
1053
|
*/
|
|
1044
1054
|
static deadReckoning(t, e) {
|
|
1045
|
-
var c,
|
|
1055
|
+
var c, i, r, o;
|
|
1046
1056
|
t > 1e12 && (t = Math.round(t / 1e3));
|
|
1047
1057
|
const n = N.unix(t);
|
|
1048
1058
|
let s = e.find((a) => a.positionTime === n.unix());
|
|
1049
1059
|
if (!s) {
|
|
1050
|
-
const a = (
|
|
1051
|
-
if (a &&
|
|
1052
|
-
const
|
|
1053
|
-
s =
|
|
1060
|
+
const a = (i = (c = e.filter((l) => (l == null ? void 0 : l.positionTime) < n.unix())) == null ? void 0 : c.sort((l, m) => (l.positionTime || 0) - (m.positionTime || 0))) == null ? void 0 : i.at(-1), u = (o = (r = e.filter((l) => (l == null ? void 0 : l.positionTime) > n.unix())) == null ? void 0 : r.sort((l, m) => (l.positionTime || 0) - (m.positionTime || 0))) == null ? void 0 : o.at(0);
|
|
1061
|
+
if (a && u) {
|
|
1062
|
+
const l = b.calculateBearing(a, u, !0), m = b.calculateDistance(a, u), d = (n.unix() - a.positionTime) / (u.positionTime - a.positionTime);
|
|
1063
|
+
s = b.calculateCoordinate(a, l, m * d), s.positionTime = n.unix(), s.utc = n.utc().format(), s.cog = l, s.sog = Math.round(m / ((u.positionTime - a.positionTime) / 3600) * 100) / 100;
|
|
1054
1064
|
} else
|
|
1055
|
-
s = a ||
|
|
1065
|
+
s = a || u, s && (s.utc = N.unix(s == null ? void 0 : s.positionTime).utc().format());
|
|
1056
1066
|
}
|
|
1057
1067
|
return s;
|
|
1058
1068
|
}
|
|
@@ -1062,20 +1072,20 @@ class S {
|
|
|
1062
1072
|
* @param positions
|
|
1063
1073
|
*/
|
|
1064
1074
|
static deadReckoningTime(t, e) {
|
|
1065
|
-
e = JSON.parse(JSON.stringify(e)), e.sort((a,
|
|
1075
|
+
e = JSON.parse(JSON.stringify(e)), e.sort((a, u) => (a.positionTime || 0) - (u.positionTime || 0));
|
|
1066
1076
|
let n = Number.MAX_SAFE_INTEGER, s = Number.MAX_SAFE_INTEGER;
|
|
1067
1077
|
for (let a = 0; a < e.length - 1; a++) {
|
|
1068
|
-
const
|
|
1078
|
+
const u = e[a], l = e[a + 1], m = b.calculatePointToLineDistance(t, u, l);
|
|
1069
1079
|
m < n && (n = m, s = a);
|
|
1070
1080
|
}
|
|
1071
|
-
const c = e[s],
|
|
1072
|
-
if (
|
|
1081
|
+
const c = e[s], i = e[s + 1], r = b.calculateDistance(c, t), o = b.calculateDistance(i, t);
|
|
1082
|
+
if (r === 0)
|
|
1073
1083
|
t = c;
|
|
1074
1084
|
else if (o === 0)
|
|
1075
|
-
t =
|
|
1085
|
+
t = i;
|
|
1076
1086
|
else {
|
|
1077
|
-
const a = c.positionTime || 0,
|
|
1078
|
-
t.positionTime = Math.round(a + (
|
|
1087
|
+
const a = c.positionTime || 0, u = i.positionTime || 0, l = b.calculateDistance(c, i);
|
|
1088
|
+
t.positionTime = Math.round(a + (u - a) * (r / l));
|
|
1079
1089
|
}
|
|
1080
1090
|
return t.utc = t.positionTime ? N.unix(t.positionTime).utc().format() : void 0, t.positionTime ? t : void 0;
|
|
1081
1091
|
}
|
|
@@ -1113,7 +1123,7 @@ class S {
|
|
|
1113
1123
|
*/
|
|
1114
1124
|
static waypoints2RTZ(t, e) {
|
|
1115
1125
|
const s = [];
|
|
1116
|
-
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="${
|
|
1126
|
+
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(`
|
|
1117
1127
|
`) + `
|
|
1118
1128
|
`;
|
|
1119
1129
|
}
|
|
@@ -1125,7 +1135,7 @@ class S {
|
|
|
1125
1135
|
*/
|
|
1126
1136
|
static waypoints2RTZ10(t, e, n = !0) {
|
|
1127
1137
|
const c = [];
|
|
1128
|
-
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="${
|
|
1138
|
+
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="${b.xmlEscape(t)}"></routeInfo>`), c.push(...b.toRTZWaypoints(e, 6, n)), c.push("</route>"), c.join(`
|
|
1129
1139
|
`) + `
|
|
1130
1140
|
`;
|
|
1131
1141
|
}
|
|
@@ -1133,21 +1143,21 @@ class S {
|
|
|
1133
1143
|
const s = [];
|
|
1134
1144
|
s.push(" <waypoints>");
|
|
1135
1145
|
for (let c = 0; c < t.length; c++) {
|
|
1136
|
-
const
|
|
1137
|
-
if (
|
|
1138
|
-
const
|
|
1139
|
-
s.push(` <leg geometryType="${
|
|
1146
|
+
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, u = [`id="${r}"`, 'revision="0"'];
|
|
1147
|
+
if (i.name && u.push(`name="${b.xmlEscape(i.name)}"`), s.push(` <waypoint ${u.join(" ")}>`), s.push(` <position lat="${b.xmlEscape(o)}" lon="${b.xmlEscape(a)}" />`), c > 0) {
|
|
1148
|
+
const l = i.gcToPrevious ? "Orthodrome" : "Loxodrome";
|
|
1149
|
+
s.push(` <leg geometryType="${l}" />`);
|
|
1140
1150
|
}
|
|
1141
1151
|
if (n) {
|
|
1142
|
-
const
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
1145
|
-
else if (
|
|
1152
|
+
const l = [];
|
|
1153
|
+
if (i.description && l.push(` <description>${b.xmlEscape(i.description)}</description>`), i.utc)
|
|
1154
|
+
l.push(` <time>${b.xmlEscape(i.utc)}</time>`);
|
|
1155
|
+
else if (i.positionTime)
|
|
1146
1156
|
try {
|
|
1147
|
-
|
|
1157
|
+
l.push(` <time>${b.xmlEscape(N.unix(i.positionTime).utc().format())}</time>`);
|
|
1148
1158
|
} catch {
|
|
1149
1159
|
}
|
|
1150
|
-
|
|
1160
|
+
i.cog !== void 0 && l.push(` <cog>${b.xmlEscape(i.cog)}</cog>`), i.sog !== void 0 && l.push(` <sog>${b.xmlEscape(i.sog)}</sog>`), l.length && (s.push(" <extensions>"), s.push(...l), s.push(" </extensions>"));
|
|
1151
1161
|
}
|
|
1152
1162
|
s.push(" </waypoint>");
|
|
1153
1163
|
}
|
|
@@ -1162,13 +1172,13 @@ class S {
|
|
|
1162
1172
|
*/
|
|
1163
1173
|
static waypoints2CSV(t, e, n) {
|
|
1164
1174
|
X.debug("keep name for waypoints2CSV for legacy compatibility only", t);
|
|
1165
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, c = e.some((g) => g.name),
|
|
1166
|
-
c && p.push("Name"),
|
|
1175
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, c = e.some((g) => g.name), i = e.some((g) => g.description), r = e.some((g) => g.port != null), o = e.some((g) => g.stbd != null), a = e.some((g) => g.arrRad != null), u = e.some((g) => g.speed != null), l = e.some((g, S) => S > 0 && g.gcToPrevious != null), m = e.some((g) => g.bearing != null), d = e.some((g) => g.distanceFromPrevious != null), p = ["WPT No.", "Latitude", "Longitude"];
|
|
1176
|
+
c && p.push("Name"), i && p.push("Description"), l && p.push("Leg"), m && p.push("Bearing[deg]"), d && p.push("Distance[NM]"), u && p.push("Speed[kn]"), r && p.push("PORT XTD[NM]"), o && p.push("STBD XTD[NM]"), a && p.push("Arr.Rad[NM]");
|
|
1167
1177
|
const f = [];
|
|
1168
|
-
f.push(p.map((g) =>
|
|
1178
|
+
f.push(p.map((g) => b.csvEscapeField(g)).join(","));
|
|
1169
1179
|
for (let g = 0; g < e.length; g++) {
|
|
1170
|
-
const
|
|
1171
|
-
v.push((g + 1).toString()), v.push(
|
|
1180
|
+
const S = e[g], v = [];
|
|
1181
|
+
v.push((g + 1).toString()), v.push(S.lat.toFixed(s)), v.push(S.lng.toFixed(s)), c && v.push(S.name ?? ""), i && v.push(S.description ?? ""), l && v.push(g === 0 ? "" : S.gcToPrevious ? "GC" : "RL"), m && v.push(S.bearing != null ? String(S.bearing) : ""), d && v.push(S.distanceFromPrevious != null ? String(S.distanceFromPrevious) : ""), u && v.push(S.speed != null ? String(S.speed) : ""), r && v.push(S.port != null ? String(S.port) : ""), o && v.push(S.stbd != null ? String(S.stbd) : ""), a && v.push(S.arrRad != null ? String(S.arrRad) : ""), f.push(v.map((x) => b.csvEscapeField(x)).join(","));
|
|
1172
1182
|
}
|
|
1173
1183
|
return f.join(`
|
|
1174
1184
|
`);
|
|
@@ -1181,13 +1191,13 @@ class S {
|
|
|
1181
1191
|
* @param options.precision 经纬度分钟小数位数,默认3
|
|
1182
1192
|
*/
|
|
1183
1193
|
static waypoints2JRCCSV(t, e, n) {
|
|
1184
|
-
const s = (n == null ? void 0 : n.precision) ?? 3, c = e.some((f) => f.name),
|
|
1185
|
-
|
|
1194
|
+
const s = (n == null ? void 0 : n.precision) ?? 3, c = e.some((f) => f.name), i = e.some((f) => f.port != null), r = e.some((f) => f.stbd != null), o = e.some((f) => f.arrRad != null), a = e.some((f) => f.speed != null), u = e.some((f, g) => g > 0 && f.gcToPrevious != null), l = e.some((f) => f.rot != null), m = e.some((f) => f.turnRad != null), d = ["// WPT No.", "LAT", "", "", "LON", "", ""];
|
|
1195
|
+
i && d.push("PORT[NM]"), r && d.push("STBD[NM]"), o && d.push("Arr. Rad[NM]"), a && d.push("Speed[kn]"), u && d.push("Sail(RL/GC)"), l && d.push("ROT[deg/min]"), m && d.push("Turn Rad[NM]"), c && d.push("Name");
|
|
1186
1196
|
const p = [];
|
|
1187
|
-
p.push("// ROUTE SHEET exported by JRC ECDIS."), p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."), p.push(`// ${
|
|
1197
|
+
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(","));
|
|
1188
1198
|
for (let f = 0; f < e.length; f++) {
|
|
1189
|
-
const g = e[f],
|
|
1190
|
-
|
|
1199
|
+
const g = e[f], S = String(f).padStart(3, "0"), v = h.lat2pretty(g.lat, 6), x = h.lng2pretty(g.lng, 6), y = v.degree, P = Number(v.minute).toFixed(s), D = v.direction, U = x.degree, F = Number(x.minute).toFixed(s), $ = x.direction, R = [S, String(y), P, D, String(U), F, $];
|
|
1200
|
+
i && R.push(f === 0 ? "***" : g.port != null ? String(g.port) : "***"), r && R.push(f === 0 ? "***" : g.stbd != null ? String(g.stbd) : "***"), o && R.push(f === 0 ? "***" : g.arrRad != null ? String(g.arrRad) : "***"), a && R.push(f === 0 ? "***" : g.speed != null ? Number(g.speed).toFixed(1).padStart(5, "0") : "***"), u && R.push(f === 0 ? "***" : g.gcToPrevious ? "GC" : "RL"), l && R.push(f === 0 ? "***" : g.rot != null ? String(g.rot) : "***"), m && R.push(f === 0 ? "***" : g.turnRad != null ? String(g.turnRad) : "***"), c && R.push(g.name ?? ""), p.push(R.join(","));
|
|
1191
1201
|
}
|
|
1192
1202
|
return p.join(`
|
|
1193
1203
|
`);
|
|
@@ -1204,23 +1214,23 @@ class S {
|
|
|
1204
1214
|
* @returns Uint8Array 二进制数据,可直接用于 new Blob([result], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
|
|
1205
1215
|
*/
|
|
1206
1216
|
static waypoints2XLSX(t, e, n) {
|
|
1207
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, c = t || "Route",
|
|
1208
|
-
|
|
1217
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, c = t || "Route", i = e.some((M) => M.name), r = e.some((M) => M.description), o = e.some((M) => M.port != null), a = e.some((M) => M.stbd != null), u = e.some((M) => M.arrRad != null), l = e.some((M) => M.speed != null), m = e.some((M, w) => w > 0 && M.gcToPrevious != null), d = e.some((M) => M.bearing != null), p = e.some((M) => M.distanceFromPrevious != null), f = ["WPT No.", "Latitude", "Longitude"];
|
|
1218
|
+
i && f.push("Name"), r && f.push("Description"), m && f.push("Leg"), d && f.push("Bearing[deg]"), p && f.push("Distance[NM]"), l && f.push("Speed[kn]"), o && f.push("PORT XTD[NM]"), a && f.push("STBD XTD[NM]"), u && f.push("Arr.Rad[NM]");
|
|
1209
1219
|
const g = (M) => M == null ? "" : String(M).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1210
|
-
let v = `<row r="1">${f.map((M,
|
|
1220
|
+
let v = `<row r="1">${f.map((M, w) => `<c r="${G(w)}1" s="1" t="inlineStr"><is><t>${g(M)}</t></is></c>`).join("")}</row>`;
|
|
1211
1221
|
for (let M = 0; M < e.length; M++) {
|
|
1212
|
-
const
|
|
1222
|
+
const w = e[M], j = M + 2, E = [], Z = (q, L) => E.push(`<c r="${G(q)}${j}"><v>${L}</v></c>`), B = (q, L) => E.push(`<c r="${G(q)}${j}" t="inlineStr"><is><t>${g(L)}</t></is></c>`), A = (q, L) => {
|
|
1213
1223
|
L != null ? Z(q, L) : B(q, "");
|
|
1214
1224
|
};
|
|
1215
|
-
Z(0, M + 1), B(1, h.lat2pretty(
|
|
1225
|
+
Z(0, M + 1), B(1, h.lat2pretty(w.lat, s).pretty), B(2, h.lng2pretty(w.lng, s).pretty);
|
|
1216
1226
|
let I = 3;
|
|
1217
|
-
|
|
1227
|
+
i && (B(I, w.name ?? ""), I++), r && (B(I, w.description ?? ""), I++), m && (B(I, M === 0 ? "" : w.gcToPrevious ? "GC" : "RL"), I++), d && (A(I, w.bearing), I++), p && (A(I, w.distanceFromPrevious), I++), l && (A(I, w.speed), I++), o && (A(I, w.port), I++), a && (A(I, w.stbd), I++), u && (A(I, w.arrRad), I++), v += `<row r="${j}">${E.join("")}</row>`;
|
|
1218
1228
|
}
|
|
1219
|
-
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>' + v + "</sheetData></worksheet>", P = '<?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>',
|
|
1220
|
-
return
|
|
1229
|
+
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>' + v + "</sheetData></worksheet>", P = '<?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>', U = '<?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="' + g(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();
|
|
1230
|
+
return nt([
|
|
1221
1231
|
{ name: "[Content_Types].xml", data: R.encode(P) },
|
|
1222
1232
|
{ name: "_rels/.rels", data: R.encode(D) },
|
|
1223
|
-
{ name: "xl/workbook.xml", data: R.encode(
|
|
1233
|
+
{ name: "xl/workbook.xml", data: R.encode(U) },
|
|
1224
1234
|
{ name: "xl/_rels/workbook.xml.rels", data: R.encode(F) },
|
|
1225
1235
|
{ name: "xl/worksheets/sheet1.xml", data: R.encode(y) },
|
|
1226
1236
|
{ name: "xl/styles.xml", data: R.encode($) }
|
|
@@ -1242,8 +1252,8 @@ class S {
|
|
|
1242
1252
|
* @param isLat true为纬度,false为经度
|
|
1243
1253
|
*/
|
|
1244
1254
|
static decimalToNmeaDm(t, e) {
|
|
1245
|
-
const n = Math.abs(t), s = Math.floor(n), c = (n - s) * 60,
|
|
1246
|
-
return { dm:
|
|
1255
|
+
const n = Math.abs(t), s = Math.floor(n), c = (n - s) * 60, i = e ? `${s.toString().padStart(2, "0")}${c.toFixed(2).padStart(5, "0")}` : `${s.toString().padStart(3, "0")}${c.toFixed(2).padStart(5, "0")}`, r = e ? t >= 0 ? "N" : "S" : t >= 0 ? "E" : "W";
|
|
1256
|
+
return { dm: i, dir: r };
|
|
1247
1257
|
}
|
|
1248
1258
|
/**
|
|
1249
1259
|
* 计算NMEA 0183校验和 ($与*之间所有字符的异或,两字符十六进制大写)
|
|
@@ -1263,7 +1273,7 @@ class S {
|
|
|
1263
1273
|
static waypoints2NMEA(t) {
|
|
1264
1274
|
const e = [];
|
|
1265
1275
|
for (let n = 0; n < t.length; n++) {
|
|
1266
|
-
const s = t[n], c =
|
|
1276
|
+
const s = t[n], c = b.decimalToNmeaDm(s.lat, !0), i = b.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 = b.nmeaChecksum(o);
|
|
1267
1277
|
e.push(`$${o}*${a}`);
|
|
1268
1278
|
}
|
|
1269
1279
|
return e.join(`\r
|
|
@@ -1283,19 +1293,19 @@ class S {
|
|
|
1283
1293
|
*/
|
|
1284
1294
|
static coordinatesSummary(t, e = 3) {
|
|
1285
1295
|
if (t.length > 1) {
|
|
1286
|
-
const n = t[0], s = t[t.length - 1], c = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ? N.unix(n == null ? void 0 : n.positionTime) : N.unix(s == null ? void 0 : s.positionTime),
|
|
1296
|
+
const n = t[0], s = t[t.length - 1], c = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ? N.unix(n == null ? void 0 : n.positionTime) : N.unix(s == null ? void 0 : s.positionTime), i = (n == null ? void 0 : n.positionTime) > (s == null ? void 0 : s.positionTime) ? N.unix(n == null ? void 0 : n.positionTime) : N.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), l = V.inspectStoppages(t, e).reduce(
|
|
1287
1297
|
(d, p) => (d.duration += p.duration, d.distance += p.distance, d),
|
|
1288
1298
|
{ hours: 0, distance: 0, spd: 0, duration: 0 }
|
|
1289
1299
|
);
|
|
1290
|
-
|
|
1291
|
-
const m =
|
|
1300
|
+
l.hours = Math.round(l.duration / 3600 * 100) / 100, l.distance = Math.round(l.distance * 100) / 100, l.spd = l.hours ? Math.round(l.distance / l.hours * 100) / 100 : 0;
|
|
1301
|
+
const m = r ? Math.round((a - l.distance) / (r - l.hours) * 100) / 100 : 0;
|
|
1292
1302
|
return {
|
|
1293
1303
|
begin: c.utc().format(),
|
|
1294
|
-
end:
|
|
1295
|
-
distance: Math.round((a -
|
|
1296
|
-
hours: Math.round((
|
|
1304
|
+
end: i.utc().format(),
|
|
1305
|
+
distance: Math.round((a - l.distance) * 100) / 100,
|
|
1306
|
+
hours: Math.round((r - l.hours) * 100) / 100,
|
|
1297
1307
|
avgSpeed: m,
|
|
1298
|
-
stoppage:
|
|
1308
|
+
stoppage: l
|
|
1299
1309
|
};
|
|
1300
1310
|
}
|
|
1301
1311
|
return {
|
|
@@ -1316,37 +1326,37 @@ class S {
|
|
|
1316
1326
|
* }
|
|
1317
1327
|
*/
|
|
1318
1328
|
static pickUTCSampleFromSpeed(t, e) {
|
|
1319
|
-
var
|
|
1320
|
-
if (!((
|
|
1329
|
+
var u, l, m;
|
|
1330
|
+
if (!((l = (u = e == null ? void 0 : e.sample) == null ? void 0 : u.hours) != null && l.length))
|
|
1321
1331
|
return { routes: [], hour: void 0 };
|
|
1322
|
-
const n = e.sample.hours.at(0), s = N.utc(t), c = N.utc(e.eta),
|
|
1323
|
-
let
|
|
1324
|
-
if (!
|
|
1325
|
-
let d = e.sample.all.filter((y) => N.utc(y.eta).isBefore(
|
|
1332
|
+
const n = e.sample.hours.at(0), s = N.utc(t), c = N.utc(e.eta), i = s.isAfter(c) ? c : s;
|
|
1333
|
+
let r = e.sample.all.find((d) => d.eta === i.format());
|
|
1334
|
+
if (!r) {
|
|
1335
|
+
let d = e.sample.all.filter((y) => N.utc(y.eta).isBefore(i)).at(-1);
|
|
1326
1336
|
if (d) {
|
|
1327
1337
|
const y = this.calculateSubRoute(d, e.route);
|
|
1328
|
-
|
|
1338
|
+
r = (m = this.calculateNextCoordinateAlongRoute(d, d.speed * i.diff(N(d.etd), "hours", !0), y)) == null ? void 0 : m.coordinate;
|
|
1329
1339
|
} else
|
|
1330
|
-
d = e.sample.all.at(0),
|
|
1331
|
-
const { cFactor: p, cog: f, wxFactor: g, meteo:
|
|
1332
|
-
|
|
1333
|
-
...
|
|
1340
|
+
d = e.sample.all.at(0), r = d;
|
|
1341
|
+
const { cFactor: p, cog: f, wxFactor: g, meteo: S } = d, v = Math.round(r.distanceFromPrevious * 1e4) / 1e4, x = Math.round((v + d.distanceFromStart) * 1e4) / 1e4;
|
|
1342
|
+
r = {
|
|
1343
|
+
...r,
|
|
1334
1344
|
cFactor: p,
|
|
1335
1345
|
cog: f,
|
|
1336
1346
|
speed: d.speed,
|
|
1337
1347
|
wxFactor: g,
|
|
1338
1348
|
distanceFromStart: x,
|
|
1339
1349
|
distanceFromPrevious: v,
|
|
1340
|
-
meteo:
|
|
1341
|
-
eta:
|
|
1342
|
-
etd:
|
|
1350
|
+
meteo: S,
|
|
1351
|
+
eta: i.format(),
|
|
1352
|
+
etd: i.format()
|
|
1343
1353
|
};
|
|
1344
1354
|
}
|
|
1345
|
-
|
|
1346
|
-
const o = this.calculateRangeWaypoints(n,
|
|
1355
|
+
r.distanceToGo = Math.round((e.distance - r.distanceFromStart) * 100) / 100, r.timeToGo = Math.round(c.diff(r.etd, "hours", !0) * 100) / 100;
|
|
1356
|
+
const o = this.calculateRangeWaypoints(n, r, e.route);
|
|
1347
1357
|
return {
|
|
1348
1358
|
routes: this.generateRouteAccordingToWaypoints(o),
|
|
1349
|
-
hour:
|
|
1359
|
+
hour: r
|
|
1350
1360
|
};
|
|
1351
1361
|
}
|
|
1352
1362
|
/**
|
|
@@ -1361,13 +1371,13 @@ class S {
|
|
|
1361
1371
|
*/
|
|
1362
1372
|
static pickUTCSampleFromRoute(t, e, n) {
|
|
1363
1373
|
var d;
|
|
1364
|
-
const s = this.calculateSubRoute(e, n), c = this.calculateRouteDistance(s),
|
|
1374
|
+
const s = this.calculateSubRoute(e, n), c = this.calculateRouteDistance(s), i = c / e.speed, r = N.utc(t), o = N(e.etd), a = (d = this.calculateNextCoordinateAlongRoute(e, e.speed * r.diff(N(e.etd), "hours", !0), s)) == null ? void 0 : d.coordinate;
|
|
1365
1375
|
a.speed = e.speed;
|
|
1366
|
-
const
|
|
1367
|
-
a.eta = Math.abs(
|
|
1368
|
-
const
|
|
1376
|
+
const u = o.clone().add(a.hourFromPrevious, "hour");
|
|
1377
|
+
a.eta = Math.abs(u.diff(r, "second")) < 2 ? r.format() : u.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(N(a.etd), "hour") * 100) / 100;
|
|
1378
|
+
const l = this.calculateRangeWaypoints(e, a, n);
|
|
1369
1379
|
return {
|
|
1370
|
-
routes: this.generateRouteAccordingToWaypoints(
|
|
1380
|
+
routes: this.generateRouteAccordingToWaypoints(l),
|
|
1371
1381
|
hour: a
|
|
1372
1382
|
};
|
|
1373
1383
|
}
|
|
@@ -1385,7 +1395,7 @@ class S {
|
|
|
1385
1395
|
* 判断路径是否与ECA区域相交
|
|
1386
1396
|
* @param path
|
|
1387
1397
|
* @param ecaZones
|
|
1388
|
-
* @see https://
|
|
1398
|
+
* @see https://ossjson.ormwx.com/layers/other/eca-zones.json
|
|
1389
1399
|
* @return 返回相交的区域
|
|
1390
1400
|
* [
|
|
1391
1401
|
* {
|
|
@@ -1397,36 +1407,36 @@ class S {
|
|
|
1397
1407
|
* 如果没有相交区域,返回空数组。
|
|
1398
1408
|
*/
|
|
1399
1409
|
static async intersectInECA(t, e) {
|
|
1400
|
-
var c,
|
|
1401
|
-
const s = (e instanceof Array ? e : e.features).filter((
|
|
1410
|
+
var c, i;
|
|
1411
|
+
const s = (e instanceof Array ? e : e.features).filter((r) => {
|
|
1402
1412
|
var o, a;
|
|
1403
|
-
return ((o =
|
|
1413
|
+
return ((o = r.geometry) == null ? void 0 : o.type) === "Polygon" && !((a = r.properties) != null && a.disabled);
|
|
1404
1414
|
});
|
|
1405
1415
|
if (t != null && t.length) {
|
|
1406
|
-
let
|
|
1407
|
-
t.some((
|
|
1408
|
-
const o =
|
|
1409
|
-
polygon:
|
|
1410
|
-
bbox: T.bbox(
|
|
1416
|
+
let r = t;
|
|
1417
|
+
t.some((l) => l instanceof Array) ? t = this.convertRouteToCoordinates(t) : r = this.divideAccordingToLng(t);
|
|
1418
|
+
const o = r.map((l) => T.lineString(l)), a = [], u = s.map((l) => ({
|
|
1419
|
+
polygon: l,
|
|
1420
|
+
bbox: T.bbox(l)
|
|
1411
1421
|
// [minX, minY, maxX, maxY]
|
|
1412
1422
|
}));
|
|
1413
|
-
for (const
|
|
1414
|
-
const m =
|
|
1415
|
-
for (const { polygon: f, bbox: g } of
|
|
1423
|
+
for (const l of o) {
|
|
1424
|
+
const m = l.geometry.coordinates, d = this.convertRouteToCoordinates([m]), p = T.bbox(l);
|
|
1425
|
+
for (const { polygon: f, bbox: g } of u) {
|
|
1416
1426
|
if (p[0] > g[2] || p[2] < g[0] || p[1] > g[3] || p[3] < g[1])
|
|
1417
1427
|
continue;
|
|
1418
|
-
let
|
|
1419
|
-
const v = T.lineIntersect(
|
|
1420
|
-
(c = v == null ? void 0 : v.features) != null && c.length && (
|
|
1428
|
+
let S = [];
|
|
1429
|
+
const v = T.lineIntersect(l, f);
|
|
1430
|
+
(c = v == null ? void 0 : v.features) != null && c.length && (S = T.getCoords(v.features).map((P) => {
|
|
1421
1431
|
const D = T.getCoord(P);
|
|
1422
1432
|
return { lng: D[0], lat: D[1] };
|
|
1423
1433
|
}));
|
|
1424
1434
|
const x = [...d];
|
|
1425
|
-
if (
|
|
1426
|
-
for (const y of
|
|
1435
|
+
if (S.length > 0)
|
|
1436
|
+
for (const y of S)
|
|
1427
1437
|
this.mergeCoordinateToWaypoints(y, x, !0);
|
|
1428
1438
|
for (let y = 0; y < x.length - 1; y++) {
|
|
1429
|
-
const P = x[y], D = x[y + 1],
|
|
1439
|
+
const P = x[y], D = x[y + 1], U = this.calculateRangeWaypoints(P, D, [], x), F = this.divideAccordingToLng(U);
|
|
1430
1440
|
for (const $ of F) {
|
|
1431
1441
|
const R = [
|
|
1432
1442
|
Math.min($[0][0], $[$.length - 1][0]),
|
|
@@ -1438,11 +1448,11 @@ class S {
|
|
|
1438
1448
|
continue;
|
|
1439
1449
|
const M = T.lineString($);
|
|
1440
1450
|
if (T.booleanContains(f, M)) {
|
|
1441
|
-
const
|
|
1451
|
+
const w = $.map((E) => ({ lng: E[0], lat: E[1] })), j = this.calculateRouteDistance([$]);
|
|
1442
1452
|
a.push({
|
|
1443
1453
|
distance: j,
|
|
1444
|
-
waypoints:
|
|
1445
|
-
eca: (
|
|
1454
|
+
waypoints: w,
|
|
1455
|
+
eca: (i = f == null ? void 0 : f.properties) == null ? void 0 : i.name
|
|
1446
1456
|
});
|
|
1447
1457
|
}
|
|
1448
1458
|
}
|
|
@@ -1454,13 +1464,13 @@ class S {
|
|
|
1454
1464
|
return [];
|
|
1455
1465
|
}
|
|
1456
1466
|
}
|
|
1457
|
-
let
|
|
1467
|
+
let O;
|
|
1458
1468
|
try {
|
|
1459
|
-
|
|
1469
|
+
O = J.getLogger("vessel");
|
|
1460
1470
|
} catch {
|
|
1461
1471
|
} finally {
|
|
1462
1472
|
}
|
|
1463
|
-
class
|
|
1473
|
+
class ut {
|
|
1464
1474
|
/**
|
|
1465
1475
|
* 将原始数据转换为geojson
|
|
1466
1476
|
* @param raw
|
|
@@ -1468,23 +1478,23 @@ class it {
|
|
|
1468
1478
|
static convert2Geojson(t) {
|
|
1469
1479
|
var n, s, c;
|
|
1470
1480
|
const e = T.featureCollection([]);
|
|
1471
|
-
for (const
|
|
1472
|
-
const
|
|
1473
|
-
if (
|
|
1474
|
-
|
|
1475
|
-
for (const o of
|
|
1481
|
+
for (const i of t) {
|
|
1482
|
+
const r = (n = i.history) == null ? void 0 : n[0];
|
|
1483
|
+
if (i.forecasts) {
|
|
1484
|
+
r && r.wind && (r.wind.kts = r.kts);
|
|
1485
|
+
for (const o of i.forecasts) {
|
|
1476
1486
|
let a;
|
|
1477
|
-
const
|
|
1487
|
+
const u = [], l = [], m = N(o.date).utc(), d = `${i.name}-${o.model}`;
|
|
1478
1488
|
for (const f in o == null ? void 0 : o.hours) {
|
|
1479
1489
|
const g = o.hours[f];
|
|
1480
1490
|
a = a || g;
|
|
1481
|
-
const
|
|
1491
|
+
const S = m.clone().add(Number(f), "hour"), v = T.point([g.lng, g.lat], {
|
|
1482
1492
|
model: o.model,
|
|
1483
|
-
name:
|
|
1484
|
-
nameCn:
|
|
1485
|
-
date:
|
|
1493
|
+
name: i.name,
|
|
1494
|
+
nameCn: i.nameCn,
|
|
1495
|
+
date: S.format(),
|
|
1486
1496
|
hour: Number(f),
|
|
1487
|
-
format:
|
|
1497
|
+
format: S.format("MMM-DD/HHmm[Z]"),
|
|
1488
1498
|
pressure: g.pressure > 1e4 ? h.roundPrecision(g.pressure / 100, 0) : h.roundPrecision(g.pressure, 0),
|
|
1489
1499
|
gusts: g.gusts,
|
|
1490
1500
|
wind: g.wind || {},
|
|
@@ -1492,41 +1502,41 @@ class it {
|
|
|
1492
1502
|
category: d,
|
|
1493
1503
|
type: "forecast"
|
|
1494
1504
|
});
|
|
1495
|
-
|
|
1505
|
+
l.push(v), u.push(v.geometry.coordinates);
|
|
1496
1506
|
}
|
|
1497
1507
|
const p = {
|
|
1498
1508
|
kts: void 0,
|
|
1499
1509
|
deg: void 0
|
|
1500
1510
|
};
|
|
1501
|
-
if (
|
|
1502
|
-
const f = N(
|
|
1511
|
+
if (r) {
|
|
1512
|
+
const f = N(r.updated).utc();
|
|
1503
1513
|
if (a) {
|
|
1504
|
-
const
|
|
1505
|
-
p.kts = Math.round(
|
|
1514
|
+
const S = b.calculateDistance(r, a), v = N(a.utc || a.updated).diff(f, "h", !0);
|
|
1515
|
+
p.kts = Math.round(S / v * 100) / 100, p.deg = b.calculateBearing(r, a, !0, 0);
|
|
1506
1516
|
}
|
|
1507
|
-
const g = T.point([
|
|
1517
|
+
const g = T.point([r.lng, r.lat], {
|
|
1508
1518
|
model: o.model,
|
|
1509
|
-
name:
|
|
1510
|
-
nameCn:
|
|
1519
|
+
name: i.name,
|
|
1520
|
+
nameCn: i.nameCn,
|
|
1511
1521
|
date: f.format(),
|
|
1512
1522
|
hour: 0,
|
|
1513
1523
|
format: f.format("MMM-DD/HHmm[Z]"),
|
|
1514
|
-
pressure:
|
|
1515
|
-
wind:
|
|
1524
|
+
pressure: r.pressure > 1e4 ? h.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : h.roundPrecision(r.pressure, 0),
|
|
1525
|
+
wind: r.wind,
|
|
1516
1526
|
movement: p,
|
|
1517
1527
|
category: d,
|
|
1518
1528
|
type: "forecast",
|
|
1519
1529
|
important: !0
|
|
1520
1530
|
// 第一个预报点为重要点
|
|
1521
1531
|
});
|
|
1522
|
-
|
|
1532
|
+
l.unshift(g), u.unshift(g.geometry.coordinates);
|
|
1523
1533
|
}
|
|
1524
|
-
if (e.features.push(...
|
|
1525
|
-
const f = T.lineString(h.convertToMonotonicLng2(
|
|
1526
|
-
date: (
|
|
1527
|
-
id:
|
|
1534
|
+
if (e.features.push(...l), (u == null ? void 0 : u.length) > 1) {
|
|
1535
|
+
const f = T.lineString(h.convertToMonotonicLng2(u), {
|
|
1536
|
+
date: (r == null ? void 0 : r.updated) || (m == null ? void 0 : m.format()),
|
|
1537
|
+
id: i.id || i.name,
|
|
1528
1538
|
model: o.model,
|
|
1529
|
-
name:
|
|
1539
|
+
name: i.name,
|
|
1530
1540
|
category: d,
|
|
1531
1541
|
type: "forecast",
|
|
1532
1542
|
movement: p
|
|
@@ -1535,21 +1545,21 @@ class it {
|
|
|
1535
1545
|
}
|
|
1536
1546
|
}
|
|
1537
1547
|
}
|
|
1538
|
-
if (e.features.sort((o, a) => o.properties.type === "forecast" && a.properties.type === "forecast" && o.geometry.type === "Point" && a.geometry.type === "Point" ? N(o.properties.date).valueOf() - N(a.properties.date).valueOf() : 0), (s =
|
|
1539
|
-
const o = [], a = N(
|
|
1540
|
-
for (const m of
|
|
1541
|
-
const d = N(m.updated).utc(), p = d.isSameOrBefore(a) || d.isSame(
|
|
1542
|
-
p && a.add(-
|
|
1548
|
+
if (e.features.sort((o, a) => o.properties.type === "forecast" && a.properties.type === "forecast" && o.geometry.type === "Point" && a.geometry.type === "Point" ? N(o.properties.date).valueOf() - N(a.properties.date).valueOf() : 0), (s = i.history) != null && s.length) {
|
|
1549
|
+
const o = [], a = N(r == null ? void 0 : r.updated).utc(), u = N((c = i.history) == null ? void 0 : c.at(-1).updated).utc(), l = a.diff(u, "h") % 24 > 2 ? 24 : 12;
|
|
1550
|
+
for (const m of i.history) {
|
|
1551
|
+
const d = N(m.updated).utc(), p = d.isSameOrBefore(a) || d.isSame(u);
|
|
1552
|
+
p && a.add(-l, "h");
|
|
1543
1553
|
const f = T.point([m.lng, m.lat], {
|
|
1544
|
-
name:
|
|
1545
|
-
nameCn:
|
|
1554
|
+
name: i.name,
|
|
1555
|
+
nameCn: i.nameCn,
|
|
1546
1556
|
date: d.format(),
|
|
1547
1557
|
format: d.format("MMM-DD/HHmm[Z]"),
|
|
1548
1558
|
pressure: m.pressure > 1e4 ? h.roundPrecision(m.pressure / 100, 0) : h.roundPrecision(m.pressure, 0),
|
|
1549
1559
|
kts: m.kts,
|
|
1550
1560
|
level: m.type,
|
|
1551
1561
|
type: "history",
|
|
1552
|
-
category: `${
|
|
1562
|
+
category: `${i.name}-history`,
|
|
1553
1563
|
wind: m.wind,
|
|
1554
1564
|
movement: m.movement,
|
|
1555
1565
|
important: p
|
|
@@ -1558,12 +1568,12 @@ class it {
|
|
|
1558
1568
|
}
|
|
1559
1569
|
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
1560
1570
|
const m = T.lineString(h.convertToMonotonicLng2(o), {
|
|
1561
|
-
name:
|
|
1571
|
+
name: i.name,
|
|
1562
1572
|
type: "history",
|
|
1563
|
-
updated:
|
|
1564
|
-
pressure: (
|
|
1565
|
-
kts:
|
|
1566
|
-
level:
|
|
1573
|
+
updated: r == null ? void 0 : r.updated,
|
|
1574
|
+
pressure: (r == null ? void 0 : r.pressure) > 1e4 ? h.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : h.roundPrecision(r == null ? void 0 : r.pressure, 0),
|
|
1575
|
+
kts: r == null ? void 0 : r.kts,
|
|
1576
|
+
level: r == null ? void 0 : r.type
|
|
1567
1577
|
});
|
|
1568
1578
|
e.features.push(m);
|
|
1569
1579
|
}
|
|
@@ -1577,20 +1587,20 @@ class it {
|
|
|
1577
1587
|
* @param step
|
|
1578
1588
|
*/
|
|
1579
1589
|
static interpolate(t, e = 3) {
|
|
1580
|
-
var c,
|
|
1590
|
+
var c, i, r, o;
|
|
1581
1591
|
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 = [];
|
|
1582
1592
|
for (const a of n) {
|
|
1583
|
-
const
|
|
1593
|
+
const u = a.properties.name, l = a.properties.model, m = a.properties.showCircle, d = a.properties.disabled, p = N(a.properties.date).utc();
|
|
1584
1594
|
let f = e * 60;
|
|
1585
|
-
const g = (
|
|
1586
|
-
(x) => x.geometry.type === "Point" && x.properties.type === "forecast" && x.properties.category === `${
|
|
1595
|
+
const g = (i = t == null ? void 0 : t.data) == null ? void 0 : i.features.filter(
|
|
1596
|
+
(x) => x.geometry.type === "Point" && x.properties.type === "forecast" && x.properties.category === `${u}-${l}`
|
|
1587
1597
|
);
|
|
1588
|
-
let
|
|
1589
|
-
for (;
|
|
1590
|
-
if (
|
|
1591
|
-
const x = g[
|
|
1592
|
-
name:
|
|
1593
|
-
model:
|
|
1598
|
+
let S, v = p.clone().add(f, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1599
|
+
for (; S = this.pickIndex(g, v), S <= g.length - 1; ) {
|
|
1600
|
+
if (S > 0) {
|
|
1601
|
+
const x = g[S], y = S === 0 ? void 0 : g[S - 1], P = (f / 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], P), U = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[1], x.geometry.coordinates[1], P), F = T.point([D, U], {
|
|
1602
|
+
name: u,
|
|
1603
|
+
model: l,
|
|
1594
1604
|
category: x == null ? void 0 : x.properties.category,
|
|
1595
1605
|
date: v.format(),
|
|
1596
1606
|
format: v.format("MMM-DD/HHmm[Z]"),
|
|
@@ -1617,8 +1627,8 @@ class it {
|
|
|
1617
1627
|
* @param options
|
|
1618
1628
|
*/
|
|
1619
1629
|
static accelPassageAt(t, e) {
|
|
1620
|
-
const { t1: n, t2: s, hr: c, hours:
|
|
1621
|
-
return { t1: n, t2: s, hr: c, hours:
|
|
1630
|
+
const { t1: n, t2: s, hr: c, hours: i } = this.tropicalCenterTwin(t, 24, e);
|
|
1631
|
+
return { t1: n, t2: s, hr: c, hours: i };
|
|
1622
1632
|
}
|
|
1623
1633
|
/**
|
|
1624
1634
|
* 计算最佳绕航点
|
|
@@ -1632,31 +1642,31 @@ class it {
|
|
|
1632
1642
|
* @param options
|
|
1633
1643
|
*/
|
|
1634
1644
|
static diversionPassageAt(t, e, n, s = {}) {
|
|
1635
|
-
const { t1: c, t2:
|
|
1636
|
-
if (c &&
|
|
1645
|
+
const { t1: c, t2: i, hr: r, hours: o } = this.tropicalCenterTwin(e, 24, s);
|
|
1646
|
+
if (c && i) {
|
|
1637
1647
|
if (!s.debug) {
|
|
1638
|
-
const p =
|
|
1648
|
+
const p = b.calculateDistance(t, c), f = b.calculateDistance(t, i);
|
|
1639
1649
|
if (p > 2 * n && f > 2 * n)
|
|
1640
|
-
return
|
|
1650
|
+
return O == null || O.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, p, f, {
|
|
1641
1651
|
from: t,
|
|
1642
1652
|
t1: c,
|
|
1643
|
-
t2:
|
|
1644
|
-
hr:
|
|
1653
|
+
t2: i,
|
|
1654
|
+
hr: r
|
|
1645
1655
|
}), {};
|
|
1646
1656
|
}
|
|
1647
|
-
const a =
|
|
1657
|
+
const a = b.calculateBearing(t, c), u = b.calculateBearing(c, i), l = Math.abs(a - u);
|
|
1648
1658
|
let m = 0;
|
|
1649
|
-
|
|
1650
|
-
const d =
|
|
1651
|
-
return
|
|
1659
|
+
l < 180 ? m = l + 90 : l >= 180 && (m = l - 90);
|
|
1660
|
+
const d = b.calculateCoordinate(c, m, n);
|
|
1661
|
+
return O == null || O.info("[%s] the right tangent position: %j", s.requestId, {
|
|
1652
1662
|
from: t,
|
|
1653
1663
|
t1: c,
|
|
1654
|
-
t2:
|
|
1664
|
+
t2: i,
|
|
1655
1665
|
radius: n,
|
|
1656
1666
|
bearing1: a,
|
|
1657
|
-
bearing2:
|
|
1667
|
+
bearing2: u,
|
|
1658
1668
|
right: d
|
|
1659
|
-
}), { at: d, t1: c, t2:
|
|
1669
|
+
}), { at: d, t1: c, t2: i, hr: Number(r), hours: o };
|
|
1660
1670
|
}
|
|
1661
1671
|
return {};
|
|
1662
1672
|
}
|
|
@@ -1671,22 +1681,22 @@ class it {
|
|
|
1671
1681
|
* @param options
|
|
1672
1682
|
*/
|
|
1673
1683
|
static driftPassageAt(t, e, n, s = {}) {
|
|
1674
|
-
const { t1: c, t2:
|
|
1675
|
-
if (c &&
|
|
1684
|
+
const { t1: c, t2: i, hr: r, hours: o } = this.tropicalCenterTwin(e, 24, s);
|
|
1685
|
+
if (c && i) {
|
|
1676
1686
|
if (!s.debug) {
|
|
1677
|
-
const d =
|
|
1687
|
+
const d = b.calculateDistance(t, c), p = b.calculateDistance(t, i);
|
|
1678
1688
|
if (d > 2 * n && p > 2 * n)
|
|
1679
|
-
return
|
|
1689
|
+
return O == null || O.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", s.requestId, d, p, {
|
|
1680
1690
|
from: t,
|
|
1681
1691
|
t1: c,
|
|
1682
|
-
t2:
|
|
1683
|
-
hr:
|
|
1692
|
+
t2: i,
|
|
1693
|
+
hr: r
|
|
1684
1694
|
}), {};
|
|
1685
1695
|
}
|
|
1686
|
-
const a =
|
|
1687
|
-
return { at:
|
|
1696
|
+
const a = b.calculateBearing(t, c), u = b.calculateBearing(c, i), l = b.calculateDistance(t, c);
|
|
1697
|
+
return { at: b.calculateCoordinate(c, a - u + 180, n < l ? n : l), t1: c, t2: i, hr: Number(r), hours: o };
|
|
1688
1698
|
} else
|
|
1689
|
-
return
|
|
1699
|
+
return O == null || O.info("[%s] no need drift: %j", s.requestId, { from: t, t1: c, t2: i, hr: r }), {};
|
|
1690
1700
|
}
|
|
1691
1701
|
/**
|
|
1692
1702
|
* 获取台风中心点对
|
|
@@ -1697,21 +1707,21 @@ class it {
|
|
|
1697
1707
|
* @private
|
|
1698
1708
|
*/
|
|
1699
1709
|
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
1700
|
-
var
|
|
1710
|
+
var u, l, m, d, p;
|
|
1701
1711
|
let s = {};
|
|
1702
|
-
(
|
|
1712
|
+
(u = t.forecasts) == null || u.forEach((f) => {
|
|
1703
1713
|
s = { ...f.hours, ...s };
|
|
1704
1714
|
});
|
|
1705
|
-
const c = ((
|
|
1706
|
-
|
|
1707
|
-
let
|
|
1708
|
-
|
|
1709
|
-
const
|
|
1710
|
-
|
|
1711
|
-
const o = Object.keys(s || {}).filter((f) => Number(f) <= Number(
|
|
1715
|
+
const c = ((l = t == null ? void 0 : t.history) == null ? void 0 : l[0]) || (s == null ? void 0 : s[(m = Object.keys(s)) == null ? void 0 : m[0]]);
|
|
1716
|
+
O == null || O.info("[%s] the first tropical center: %j", n.requestId, c);
|
|
1717
|
+
let i = (d = Object.keys(s || {}).filter((f) => Number(f) <= (e < 0 ? 24 : e))) == null ? void 0 : d.at(-1);
|
|
1718
|
+
i || (i = (p = Object.keys(s || {}).filter((f) => Number(f) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : p.at(-1));
|
|
1719
|
+
const r = s == null ? void 0 : s[i || -1];
|
|
1720
|
+
O == null || O.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, i);
|
|
1721
|
+
const o = Object.keys(s || {}).filter((f) => Number(f) <= Number(i)), a = { 0: c };
|
|
1712
1722
|
for (const f of o)
|
|
1713
1723
|
a[f] = s[f];
|
|
1714
|
-
return { t1: c, t2:
|
|
1724
|
+
return { t1: c, t2: r, hr: Number(i), hours: a };
|
|
1715
1725
|
}
|
|
1716
1726
|
static pickIndex(t, e) {
|
|
1717
1727
|
let n = 0;
|
|
@@ -1752,13 +1762,13 @@ typeof globalThis < "u" && typeof globalThis.Buffer > "u" && (globalThis.Buffer
|
|
|
1752
1762
|
throw new TypeError("Buffer.from: unsupported source type");
|
|
1753
1763
|
}
|
|
1754
1764
|
});
|
|
1755
|
-
let
|
|
1765
|
+
let k;
|
|
1756
1766
|
try {
|
|
1757
|
-
|
|
1767
|
+
k = J.getLogger("meteo");
|
|
1758
1768
|
} catch {
|
|
1759
1769
|
} finally {
|
|
1760
1770
|
}
|
|
1761
|
-
function
|
|
1771
|
+
function st() {
|
|
1762
1772
|
if (typeof DOMParser < "u")
|
|
1763
1773
|
return new DOMParser();
|
|
1764
1774
|
const { JSDOM: C } = require("jsdom"), { DOMParser: t } = new C("").window;
|
|
@@ -1783,10 +1793,10 @@ class W {
|
|
|
1783
1793
|
* @param options 步数、单位等选项
|
|
1784
1794
|
*/
|
|
1785
1795
|
static drawCircle(t, e, n, s = {}) {
|
|
1786
|
-
const c = (s == null ? void 0 : s.steps) ?? 64,
|
|
1787
|
-
|
|
1788
|
-
const
|
|
1789
|
-
return
|
|
1796
|
+
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 }), u = N.utc();
|
|
1797
|
+
r.id = (s == null ? void 0 : s.id) || u.valueOf().toString();
|
|
1798
|
+
const l = "circle";
|
|
1799
|
+
return r.name = (s == null ? void 0 : s.name) || `${l}_${u.format()}`, r.radius = n, r.center = [t, e], r.end = a.geometry.coordinates.map((m) => h.roundPrecision(m, 9)), r.units = i, r.steps = c, r.shape = "circle", k.info("[%s] draw circle with %j", s == null ? void 0 : s.requestId, r), T.circle(o, n, { steps: c, units: i, properties: r });
|
|
1790
1800
|
}
|
|
1791
1801
|
/**
|
|
1792
1802
|
* 基于turf画矩形,返回GeoJSON Feature<Polygon>
|
|
@@ -1797,9 +1807,9 @@ class W {
|
|
|
1797
1807
|
static drawRect(t, e, n = {}) {
|
|
1798
1808
|
const s = (n == null ? void 0 : n.properties) ?? {}, c = N.utc();
|
|
1799
1809
|
s.id = (n == null ? void 0 : n.id) || c.valueOf().toString();
|
|
1800
|
-
const
|
|
1801
|
-
s.name = (n == null ? void 0 : n.name) || `${
|
|
1802
|
-
const [
|
|
1810
|
+
const i = "rect";
|
|
1811
|
+
s.name = (n == null ? void 0 : n.name) || `${i}_${c.format()}`, s.start = t.map((u) => h.roundPrecision(u, 9)), s.end = e.map((u) => h.roundPrecision(u, 9)), s.shape = "rect", k.info("[%s] draw rect with %j", n == null ? void 0 : n.requestId, s);
|
|
1812
|
+
const [r, o] = h.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])];
|
|
1803
1813
|
return T.bboxPolygon(a, { properties: s });
|
|
1804
1814
|
}
|
|
1805
1815
|
/**
|
|
@@ -1813,9 +1823,9 @@ class W {
|
|
|
1813
1823
|
const n = (e == null ? void 0 : e.properties) ?? {}, s = N.utc();
|
|
1814
1824
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1815
1825
|
const c = "line";
|
|
1816
|
-
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.shape = "line",
|
|
1817
|
-
const
|
|
1818
|
-
return T.lineString(
|
|
1826
|
+
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.shape = "line", k.info("[%s] draw line with %j", e == null ? void 0 : e.requestId, n);
|
|
1827
|
+
const i = h.convertToMonotonicLng2(t);
|
|
1828
|
+
return T.lineString(i, n);
|
|
1819
1829
|
}
|
|
1820
1830
|
/**
|
|
1821
1831
|
* 基于turf画多边形,返回GeoJSON Feature<Polygon>
|
|
@@ -1827,9 +1837,9 @@ class W {
|
|
|
1827
1837
|
const n = (e == null ? void 0 : e.properties) ?? {}, s = N.utc();
|
|
1828
1838
|
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1829
1839
|
const c = "polygon";
|
|
1830
|
-
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.coordinates = t.map((
|
|
1831
|
-
const
|
|
1832
|
-
return T.polygon([
|
|
1840
|
+
n.name = (e == null ? void 0 : e.name) || `${c}_${s.format()}`, n.coordinates = t.map((r) => r.map((o) => h.roundPrecision(o, 9))), n.shape = "polygon", k.info("[%s] draw polygon with %j", e == null ? void 0 : e.requestId, n);
|
|
1841
|
+
const i = h.convertToMonotonicLng2(t);
|
|
1842
|
+
return T.polygon([i], n);
|
|
1833
1843
|
}
|
|
1834
1844
|
/**
|
|
1835
1845
|
* 基于turf画点,返回GeoJSON Feature<Point>
|
|
@@ -1841,8 +1851,8 @@ class W {
|
|
|
1841
1851
|
static drawPoint(t, e, n = {}) {
|
|
1842
1852
|
const s = (n == null ? void 0 : n.properties) ?? {}, c = N.utc();
|
|
1843
1853
|
s.id = (n == null ? void 0 : n.id) || c.valueOf().toString();
|
|
1844
|
-
const
|
|
1845
|
-
return s.name = (n == null ? void 0 : n.name) || `${
|
|
1854
|
+
const i = "point";
|
|
1855
|
+
return s.name = (n == null ? void 0 : n.name) || `${i}_${c.format()}`, s.shape = "point", k.info("[%s] draw point with %j", n == null ? void 0 : n.requestId, s), T.point([e, t], s);
|
|
1846
1856
|
}
|
|
1847
1857
|
/**
|
|
1848
1858
|
* 解析ORM GeoJSON Feature (圆), 返回FeatureCollection
|
|
@@ -1853,27 +1863,27 @@ class W {
|
|
|
1853
1863
|
*/
|
|
1854
1864
|
static parseCircle(t, e = {}) {
|
|
1855
1865
|
var s, c;
|
|
1856
|
-
|
|
1866
|
+
k.info("[%s] parse circle with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1857
1867
|
const n = t.properties || {};
|
|
1858
1868
|
if (n.shape == "circle") {
|
|
1859
|
-
const
|
|
1860
|
-
n.id = (n == null ? void 0 : n.id) ||
|
|
1861
|
-
const
|
|
1869
|
+
const i = N.utc();
|
|
1870
|
+
n.id = (n == null ? void 0 : n.id) || i.valueOf().toString();
|
|
1871
|
+
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);
|
|
1862
1872
|
let a = "center";
|
|
1863
|
-
o.properties = { id: `${a}_${
|
|
1864
|
-
const
|
|
1865
|
-
let
|
|
1866
|
-
if (!
|
|
1873
|
+
o.properties = { id: `${a}_${r}`, parentId: r, name: a };
|
|
1874
|
+
const u = (n == null ? void 0 : n.units) || "nauticalmiles";
|
|
1875
|
+
let l = n == null ? void 0 : n.radius;
|
|
1876
|
+
if (!l) {
|
|
1867
1877
|
const p = T.polygonToLine(t);
|
|
1868
|
-
|
|
1878
|
+
l = T.pointToLineDistance(o, p, { units: u });
|
|
1869
1879
|
}
|
|
1870
1880
|
a = "end";
|
|
1871
|
-
const m = ((c = n == null ? void 0 : n.end) == null ? void 0 : c.length) == 2 ? T.point(n.end) : T.destination(o,
|
|
1872
|
-
m.properties = { id: `${a}_${
|
|
1881
|
+
const m = ((c = n == null ? void 0 : n.end) == null ? void 0 : c.length) == 2 ? T.point(n.end) : T.destination(o, l, 90, { units: u });
|
|
1882
|
+
m.properties = { id: `${a}_${r}`, parentId: r, name: a, radius: l, units: u };
|
|
1873
1883
|
const d = T.lineString([o.geometry.coordinates, m.geometry.coordinates]);
|
|
1874
|
-
return a = "edge", d.properties = { id: `${a}_${
|
|
1884
|
+
return a = "edge", d.properties = { id: `${a}_${r}`, parentId: r, name: a, radius: l, units: u }, T.featureCollection([o, m, d, t]);
|
|
1875
1885
|
} else
|
|
1876
|
-
return
|
|
1886
|
+
return k.warn("[%s] not a orm-std circle, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1877
1887
|
}
|
|
1878
1888
|
/**
|
|
1879
1889
|
* 解析ORM GeoJSON Feature (矩形), 返回FeatureCollection
|
|
@@ -1883,18 +1893,18 @@ class W {
|
|
|
1883
1893
|
* 如果feature是矩形,则返回矩形的四个顶点和矩形Feature
|
|
1884
1894
|
*/
|
|
1885
1895
|
static parseRect(t, e = {}) {
|
|
1886
|
-
|
|
1896
|
+
k.info("[%s] parse rect with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1887
1897
|
const n = t.properties || {};
|
|
1888
1898
|
if (n.shape == "rect") {
|
|
1889
1899
|
const s = N.utc();
|
|
1890
1900
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1891
|
-
const c = n == null ? void 0 : n.id,
|
|
1892
|
-
const
|
|
1893
|
-
return
|
|
1901
|
+
const c = n == null ? void 0 : n.id, i = t.geometry.coordinates[0], o = ["sw", "nw", "ne", "se"].map((a, u) => {
|
|
1902
|
+
const l = T.point(i[u]);
|
|
1903
|
+
return l.properties = { id: `${a}_${c}`, parentId: c, name: a }, l;
|
|
1894
1904
|
});
|
|
1895
1905
|
return T.featureCollection([...o, t]);
|
|
1896
1906
|
} else
|
|
1897
|
-
return
|
|
1907
|
+
return k.warn("[%s] not a orm-std rect, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1898
1908
|
}
|
|
1899
1909
|
/**
|
|
1900
1910
|
* 解析ORM GeoJSON Feature (线), 返回FeatureCollection
|
|
@@ -1904,18 +1914,18 @@ class W {
|
|
|
1904
1914
|
* 如果feature是线,则返回所有坐标点(首为start、尾为end、中间为point_N)以及线Feature
|
|
1905
1915
|
*/
|
|
1906
1916
|
static parseLine(t, e = {}) {
|
|
1907
|
-
|
|
1917
|
+
k.info("[%s] parse line with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1908
1918
|
const n = t.properties || {};
|
|
1909
1919
|
if (n.shape == "line") {
|
|
1910
1920
|
const s = N.utc();
|
|
1911
1921
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1912
|
-
const c = n == null ? void 0 : n.id,
|
|
1913
|
-
const
|
|
1914
|
-
return
|
|
1922
|
+
const c = n == null ? void 0 : n.id, r = t.geometry.coordinates.map((o, a) => {
|
|
1923
|
+
const u = `point_${a}`, l = T.point(o);
|
|
1924
|
+
return l.properties = { id: `${u}_${c}`, parentId: c, name: u, index: a }, l;
|
|
1915
1925
|
});
|
|
1916
|
-
return T.featureCollection([...
|
|
1926
|
+
return T.featureCollection([...r, t]);
|
|
1917
1927
|
} else
|
|
1918
|
-
return
|
|
1928
|
+
return k.warn("[%s] not a orm-std line, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1919
1929
|
}
|
|
1920
1930
|
/**
|
|
1921
1931
|
* 解析ORM GeoJSON Feature (多边形), 返回FeatureCollection
|
|
@@ -1925,18 +1935,18 @@ class W {
|
|
|
1925
1935
|
* 如果feature是多边形,则返回多边形的顶点和多边形Feature
|
|
1926
1936
|
*/
|
|
1927
1937
|
static parsePolygon(t, e = {}) {
|
|
1928
|
-
|
|
1938
|
+
k.info("[%s] parse polygon with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1929
1939
|
const n = t.properties || {};
|
|
1930
1940
|
if (n.shape == "polygon") {
|
|
1931
1941
|
const s = N.utc();
|
|
1932
1942
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1933
|
-
const c = n == null ? void 0 : n.id,
|
|
1934
|
-
const
|
|
1935
|
-
return
|
|
1943
|
+
const c = n == null ? void 0 : n.id, r = t.geometry.coordinates[0].map((o, a) => {
|
|
1944
|
+
const u = T.point(o), l = `corner_${a}`;
|
|
1945
|
+
return u.properties = { id: `${l}_${c}`, parentId: c, name: l, index: a }, u;
|
|
1936
1946
|
});
|
|
1937
|
-
return T.featureCollection([...
|
|
1947
|
+
return T.featureCollection([...r, t]);
|
|
1938
1948
|
} else
|
|
1939
|
-
return
|
|
1949
|
+
return k.warn("[%s] not a orm-std polygon, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1940
1950
|
}
|
|
1941
1951
|
// ---------------------------------------------------------------------------
|
|
1942
1952
|
// ZIP / KMZ 内部工具
|
|
@@ -1959,51 +1969,51 @@ class W {
|
|
|
1959
1969
|
*/
|
|
1960
1970
|
static async _parseZipEntries(t) {
|
|
1961
1971
|
var m;
|
|
1962
|
-
const e = new Uint8Array(t), n = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), s = new DataView(n), c = new Uint8Array(n),
|
|
1963
|
-
let
|
|
1972
|
+
const e = new Uint8Array(t), n = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), s = new DataView(n), c = new Uint8Array(n), i = /* @__PURE__ */ new Map();
|
|
1973
|
+
let r = -1;
|
|
1964
1974
|
for (let d = n.byteLength - 22; d >= 0; d--)
|
|
1965
1975
|
if (s.getUint32(d, !0) === 101010256) {
|
|
1966
|
-
|
|
1976
|
+
r = d;
|
|
1967
1977
|
break;
|
|
1968
1978
|
}
|
|
1969
|
-
if (
|
|
1979
|
+
if (r < 0)
|
|
1970
1980
|
throw new Error("Invalid ZIP file: EOCD not found");
|
|
1971
|
-
s.getUint16(
|
|
1972
|
-
const o = s.getUint32(
|
|
1973
|
-
let
|
|
1974
|
-
const
|
|
1975
|
-
for (;
|
|
1976
|
-
if (s.getUint32(
|
|
1977
|
-
throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${
|
|
1978
|
-
const p = s.getUint16(
|
|
1981
|
+
s.getUint16(r + 8, !0);
|
|
1982
|
+
const o = s.getUint32(r + 12, !0), a = s.getUint32(r + 16, !0);
|
|
1983
|
+
let u = a;
|
|
1984
|
+
const l = a + o;
|
|
1985
|
+
for (; u < l; ) {
|
|
1986
|
+
if (s.getUint32(u, !0) !== 33639248)
|
|
1987
|
+
throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${u}`);
|
|
1988
|
+
const p = s.getUint16(u + 10, !0), f = s.getUint32(u + 20, !0), g = s.getUint16(u + 28, !0), S = s.getUint16(u + 30, !0), v = s.getUint16(u + 32, !0), x = s.getUint32(u + 42, !0), y = c.slice(u + 46, u + 46 + g), P = new TextDecoder().decode(y), D = s.getUint16(x + 26, !0), U = s.getUint16(x + 28, !0), F = x + 30 + D + U, $ = c.slice(F, F + f);
|
|
1979
1989
|
if (p === 0)
|
|
1980
|
-
|
|
1990
|
+
i.set(P, $);
|
|
1981
1991
|
else if (p === 8) {
|
|
1982
1992
|
if (typeof DecompressionStream < "u") {
|
|
1983
|
-
const R = new DecompressionStream("deflate-raw"), M = R.writable.getWriter(),
|
|
1993
|
+
const R = new DecompressionStream("deflate-raw"), M = R.writable.getWriter(), w = R.readable.getReader();
|
|
1984
1994
|
M.write($), M.close();
|
|
1985
1995
|
const j = [];
|
|
1986
|
-
let
|
|
1996
|
+
let E = 0;
|
|
1987
1997
|
for (; ; ) {
|
|
1988
|
-
const { done:
|
|
1989
|
-
if (
|
|
1998
|
+
const { done: A, value: I } = await w.read();
|
|
1999
|
+
if (A)
|
|
1990
2000
|
break;
|
|
1991
|
-
j.push(I),
|
|
2001
|
+
j.push(I), E += I.length;
|
|
1992
2002
|
}
|
|
1993
|
-
const Z = new Uint8Array(
|
|
2003
|
+
const Z = new Uint8Array(E);
|
|
1994
2004
|
let B = 0;
|
|
1995
|
-
for (const
|
|
1996
|
-
Z.set(
|
|
1997
|
-
|
|
2005
|
+
for (const A of j)
|
|
2006
|
+
Z.set(A, B), B += A.length;
|
|
2007
|
+
i.set(P, Z);
|
|
1998
2008
|
} else if (typeof process < "u" && ((m = process.versions) != null && m.node))
|
|
1999
2009
|
try {
|
|
2000
|
-
|
|
2010
|
+
i.set(P, W._inflateRawSync($));
|
|
2001
2011
|
} catch {
|
|
2002
2012
|
}
|
|
2003
2013
|
}
|
|
2004
|
-
|
|
2014
|
+
u += 46 + g + S + v;
|
|
2005
2015
|
}
|
|
2006
|
-
return
|
|
2016
|
+
return i;
|
|
2007
2017
|
}
|
|
2008
2018
|
// ---------------------------------------------------------------------------
|
|
2009
2019
|
// KMZ / ZIP → GeoJSON
|
|
@@ -2015,24 +2025,24 @@ class W {
|
|
|
2015
2025
|
* @returns
|
|
2016
2026
|
*/
|
|
2017
2027
|
static async convertKML2GeoJSON(t, e = {}) {
|
|
2018
|
-
var
|
|
2019
|
-
|
|
2020
|
-
const s =
|
|
2028
|
+
var r, o;
|
|
2029
|
+
k.info("[%s] convert kml to geojson", e == null ? void 0 : e.requestId);
|
|
2030
|
+
const s = st().parseFromString(t, "application/xml"), c = Array.from(s.querySelectorAll("Placemark")), i = [];
|
|
2021
2031
|
for (const a of c) {
|
|
2022
|
-
const
|
|
2023
|
-
for (const y of
|
|
2024
|
-
const P = y.getAttribute("name"), D = (o = (
|
|
2025
|
-
P && D !== void 0 && D !== null && (
|
|
2032
|
+
const u = {}, l = Array.from(a.querySelectorAll("ExtendedData > Data"));
|
|
2033
|
+
for (const y of l) {
|
|
2034
|
+
const P = y.getAttribute("name"), D = (o = (r = y.querySelector("value")) == null ? void 0 : r.textContent) == null ? void 0 : o.trim();
|
|
2035
|
+
P && D !== void 0 && D !== null && (u[P] = D);
|
|
2026
2036
|
}
|
|
2027
|
-
const m = N.utc(), d = Object.keys(
|
|
2037
|
+
const m = N.utc(), d = Object.keys(u).find((y) => y.toLowerCase().indexOf("name") !== -1), p = d ? u[d] : void 0, f = `${m.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, g = (y) => y.trim().split(/[\s\n]+/).filter((P) => P.length > 0).map((P) => {
|
|
2028
2038
|
const D = P.split(",").map(Number);
|
|
2029
2039
|
return [D[0], D[1]];
|
|
2030
|
-
}),
|
|
2031
|
-
if (
|
|
2032
|
-
const y = g(
|
|
2040
|
+
}), S = a.querySelector("LineString > coordinates");
|
|
2041
|
+
if (S) {
|
|
2042
|
+
const y = g(S.textContent || "");
|
|
2033
2043
|
if (y.length >= 2) {
|
|
2034
|
-
const P = T.lineString(y, { ...
|
|
2035
|
-
|
|
2044
|
+
const P = T.lineString(y, { ...u, shape: "line", id: f, name: p });
|
|
2045
|
+
i.push(P);
|
|
2036
2046
|
}
|
|
2037
2047
|
continue;
|
|
2038
2048
|
}
|
|
@@ -2040,8 +2050,8 @@ class W {
|
|
|
2040
2050
|
if (v) {
|
|
2041
2051
|
const y = g(v.textContent || "");
|
|
2042
2052
|
if (y.length >= 4) {
|
|
2043
|
-
const P = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]], D = T.polygon([P], { ...
|
|
2044
|
-
|
|
2053
|
+
const P = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]], D = T.polygon([P], { ...u, shape: "polygon", id: f, name: p });
|
|
2054
|
+
i.push(D);
|
|
2045
2055
|
}
|
|
2046
2056
|
continue;
|
|
2047
2057
|
}
|
|
@@ -2049,13 +2059,13 @@ class W {
|
|
|
2049
2059
|
if (x) {
|
|
2050
2060
|
const y = g(x.textContent || "");
|
|
2051
2061
|
if (y.length >= 1) {
|
|
2052
|
-
const P = T.point(y[0], { ...
|
|
2053
|
-
|
|
2062
|
+
const P = T.point(y[0], { ...u, shape: "point", id: f, name: p });
|
|
2063
|
+
i.push(P);
|
|
2054
2064
|
}
|
|
2055
2065
|
continue;
|
|
2056
2066
|
}
|
|
2057
2067
|
}
|
|
2058
|
-
return T.featureCollection(
|
|
2068
|
+
return T.featureCollection(i);
|
|
2059
2069
|
}
|
|
2060
2070
|
/**
|
|
2061
2071
|
* 将 KMZ(ZIP 内含 doc.kml 或首个 .kml 文件)异步转换为 GeoJSON。
|
|
@@ -2067,11 +2077,11 @@ class W {
|
|
|
2067
2077
|
* @param options
|
|
2068
2078
|
*/
|
|
2069
2079
|
static async convertKMZ2GeoJSON(t, e = {}) {
|
|
2070
|
-
var
|
|
2071
|
-
|
|
2072
|
-
const n = await W._parseZipEntries(t), s = n.get("doc.kml") ?? ((
|
|
2080
|
+
var i;
|
|
2081
|
+
k.info("[%s] convert kmz to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
2082
|
+
const n = await W._parseZipEntries(t), s = n.get("doc.kml") ?? ((i = [...n.entries()].find(([r]) => r.toLowerCase().endsWith(".kml"))) == null ? void 0 : i[1]);
|
|
2073
2083
|
if (!s)
|
|
2074
|
-
return
|
|
2084
|
+
return k.warn("[%s] no .kml file found in kmz", e == null ? void 0 : e.requestId), T.featureCollection([]);
|
|
2075
2085
|
const c = new TextDecoder().decode(s);
|
|
2076
2086
|
return W.convertKML2GeoJSON(c, e);
|
|
2077
2087
|
}
|
|
@@ -2085,15 +2095,15 @@ class W {
|
|
|
2085
2095
|
* @param options
|
|
2086
2096
|
*/
|
|
2087
2097
|
static async convertZIP2GeoJSON(t, e = {}) {
|
|
2088
|
-
|
|
2098
|
+
k.info("[%s] convert zip to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
2089
2099
|
const n = await W._parseZipEntries(t), s = [];
|
|
2090
|
-
for (const [c,
|
|
2100
|
+
for (const [c, i] of n) {
|
|
2091
2101
|
if (!c.toLowerCase().endsWith(".kml"))
|
|
2092
2102
|
continue;
|
|
2093
|
-
const
|
|
2103
|
+
const r = new TextDecoder().decode(i), o = await W.convertKML2GeoJSON(r, e);
|
|
2094
2104
|
s.push(...o.features);
|
|
2095
2105
|
}
|
|
2096
|
-
return s.length === 0 ? (
|
|
2106
|
+
return s.length === 0 ? (k.warn("[%s] no .kml files found in zip", e == null ? void 0 : e.requestId), this.convertSHP2GeoJSON(t, e)) : T.featureCollection(s);
|
|
2097
2107
|
}
|
|
2098
2108
|
/**
|
|
2099
2109
|
* 将 Shapefile ZIP(含 .shp/.shx/.dbf/.prj)转换为 GeoJSON FeatureCollection。
|
|
@@ -2104,12 +2114,12 @@ class W {
|
|
|
2104
2114
|
* @param options
|
|
2105
2115
|
*/
|
|
2106
2116
|
static async convertSHP2GeoJSON(t, e = {}) {
|
|
2107
|
-
|
|
2117
|
+
k.info("[%s] convert shp zip to geojson", e == null ? void 0 : e.requestId);
|
|
2108
2118
|
try {
|
|
2109
2119
|
typeof Buffer < "u" && Buffer.isBuffer(t) && (t = W.toArrayBuffer(t));
|
|
2110
|
-
const n = await
|
|
2120
|
+
const n = await H(t);
|
|
2111
2121
|
if (Array.isArray(n)) {
|
|
2112
|
-
const s = n.flatMap((o) => o.features || []), c = N.utc(),
|
|
2122
|
+
const s = n.flatMap((o) => o.features || []), c = N.utc(), i = (e == null ? void 0 : e.id) || c.valueOf().toString(), r = {
|
|
2113
2123
|
Point: "point",
|
|
2114
2124
|
MultiPoint: "point",
|
|
2115
2125
|
LineString: "line",
|
|
@@ -2119,22 +2129,22 @@ class W {
|
|
|
2119
2129
|
};
|
|
2120
2130
|
return s.forEach((o, a) => {
|
|
2121
2131
|
var p;
|
|
2122
|
-
const
|
|
2123
|
-
o.properties = o.properties || {}, o.properties.shape =
|
|
2132
|
+
const u = ((p = o.geometry) == null ? void 0 : p.type) || "", l = r[u] || u.toLowerCase();
|
|
2133
|
+
o.properties = o.properties || {}, o.properties.shape = l, o.properties.parentId = i, o.properties.id = `${i}_${a}`;
|
|
2124
2134
|
const m = Object.keys(o.properties).find((f) => f.toLowerCase().indexOf("name") !== -1), d = m ? o.properties[m] : void 0;
|
|
2125
|
-
o.properties.name = d || `${
|
|
2135
|
+
o.properties.name = d || `${l}_${c.format()}_${a}`;
|
|
2126
2136
|
}), T.featureCollection(s);
|
|
2127
2137
|
}
|
|
2128
2138
|
return n;
|
|
2129
2139
|
} catch (n) {
|
|
2130
|
-
return
|
|
2140
|
+
return k.warn("[%s] failed to convert shp zip: %s", e == null ? void 0 : e.requestId, n), T.featureCollection([]);
|
|
2131
2141
|
}
|
|
2132
2142
|
}
|
|
2133
2143
|
}
|
|
2134
2144
|
export {
|
|
2135
|
-
|
|
2145
|
+
V as AisHelper,
|
|
2136
2146
|
W as GeoJsonHelper,
|
|
2137
|
-
|
|
2147
|
+
b as LaneHelper,
|
|
2138
2148
|
h as LngLatHelper,
|
|
2139
|
-
|
|
2149
|
+
ut as TropicalHelper
|
|
2140
2150
|
};
|