@idm-plugin/geo 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +684 -684
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,9 +10,9 @@ class d {
|
|
|
10
10
|
* @param lng
|
|
11
11
|
* @param lat
|
|
12
12
|
*/
|
|
13
|
-
static guessTimeZoneOffset(
|
|
14
|
-
|
|
15
|
-
const n = V(
|
|
13
|
+
static guessTimeZoneOffset(t, e) {
|
|
14
|
+
t = d.convertToStdLng(t);
|
|
15
|
+
const n = V(e, t), s = b().tz(n).utcOffset();
|
|
16
16
|
return d.roundPrecision(s / 60, 1);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -20,29 +20,29 @@ class d {
|
|
|
20
20
|
* @param offset => 8.5
|
|
21
21
|
* @return timezone => +08:30
|
|
22
22
|
*/
|
|
23
|
-
static prettyTimeZoneOffset(
|
|
24
|
-
let
|
|
25
|
-
return n = n > 9 ? n : `0${n}`,
|
|
23
|
+
static prettyTimeZoneOffset(t) {
|
|
24
|
+
let e = Math.floor(Math.abs(t)), n = Math.round((Math.abs(t) - e) * 60);
|
|
25
|
+
return n = n > 9 ? n : `0${n}`, e = e > 9 ? e : `0${e}`, t > 0 ? `+${e}:${n}` : `-${e}:${n}`;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* @param lng
|
|
29
29
|
* @param precision 3位小数在百米级,4位小数在十米级, 5位小数在米级
|
|
30
30
|
* @param format
|
|
31
31
|
*/
|
|
32
|
-
static lng2pretty(
|
|
33
|
-
|
|
32
|
+
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
33
|
+
t = d.convertToStdLng(t, e);
|
|
34
34
|
let s = "E";
|
|
35
|
-
|
|
36
|
-
let o =
|
|
37
|
-
|
|
38
|
-
const f = `${n.replace(/S+/gi,
|
|
35
|
+
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
36
|
+
let o = t * 3600, r, i, c, a, l, u;
|
|
37
|
+
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i = d.padNumber(r, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = d.roundPrecision(c, e).toString().padStart(2, "0") : a = d.padNumber(c, 2, 3), o = o - c * 60), l = o / 3600, n.indexOf("M") !== -1 ? u = d.roundPrecision(l, e).toString().padStart(3, "0") : u = d.padNumber(l, 3, 6), Number(i) >= 60 && (a = Number(a) + 1, i = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
38
|
+
const f = `${n.replace(/S+/gi, i).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
39
39
|
return {
|
|
40
40
|
direction: s,
|
|
41
|
-
degree: d.roundPrecision(l,
|
|
42
|
-
minute: d.roundPrecision(c,
|
|
43
|
-
second: d.roundPrecision(
|
|
41
|
+
degree: d.roundPrecision(l, e),
|
|
42
|
+
minute: d.roundPrecision(c, e),
|
|
43
|
+
second: d.roundPrecision(r, e),
|
|
44
44
|
pretty: f,
|
|
45
|
-
S:
|
|
45
|
+
S: i,
|
|
46
46
|
M: a,
|
|
47
47
|
H: u
|
|
48
48
|
};
|
|
@@ -53,104 +53,104 @@ class d {
|
|
|
53
53
|
* @param precision 精确度
|
|
54
54
|
* @param format 格式化
|
|
55
55
|
*/
|
|
56
|
-
static lat2pretty(
|
|
57
|
-
|
|
56
|
+
static lat2pretty(t, e = 6, n = "H°M′") {
|
|
57
|
+
t = t % 180;
|
|
58
58
|
let s = "N";
|
|
59
|
-
|
|
60
|
-
let o =
|
|
61
|
-
|
|
62
|
-
const f = `${n.replace(/S+/gi,
|
|
59
|
+
t < 0 && (s = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
60
|
+
let o = t * 3600, r, i, c, a, l, u;
|
|
61
|
+
r = o % 3600 % 60, n.indexOf("S") !== -1 && (o = o - r, i = d.padNumber(r, 2, 2)), c = o / 60 % 60, n.indexOf("M") !== -1 && (n.indexOf("S") !== -1 ? a = d.roundPrecision(c, e).toString().padStart(2, "0") : a = d.padNumber(c, 2, 3), o = o - c * 60), l = o / 3600, n.indexOf("M") !== -1 ? u = d.roundPrecision(l, e).toString().padStart(2, "0") : u = d.padNumber(l, 2, 6), Number(i) >= 60 && (a = Number(a) + 1, i = 0), Number(a) >= 60 && (u = Number(u) + 1, a = 0);
|
|
62
|
+
const f = `${n.replace(/S+/gi, i).replace(/M+/gi, a).replace(/H+/gi, u)}${s}`;
|
|
63
63
|
return {
|
|
64
64
|
direction: s,
|
|
65
|
-
degree: d.roundPrecision(l,
|
|
66
|
-
minute: d.roundPrecision(c,
|
|
67
|
-
second: d.roundPrecision(
|
|
65
|
+
degree: d.roundPrecision(l, e),
|
|
66
|
+
minute: d.roundPrecision(c, e),
|
|
67
|
+
second: d.roundPrecision(r, e),
|
|
68
68
|
pretty: f,
|
|
69
|
-
S:
|
|
69
|
+
S: i,
|
|
70
70
|
M: a,
|
|
71
71
|
H: u
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
static str2Lng(
|
|
74
|
+
static str2Lng(t, e = 6) {
|
|
75
75
|
let n;
|
|
76
|
-
if (isNaN(
|
|
77
|
-
|
|
78
|
-
const s =
|
|
79
|
-
|
|
80
|
-
const o =
|
|
81
|
-
let [
|
|
82
|
-
if (
|
|
83
|
-
const a = this.roundPrecision(
|
|
84
|
-
|
|
76
|
+
if (isNaN(t)) {
|
|
77
|
+
t = d.strReplace(t, "LNG");
|
|
78
|
+
const s = t[t.length - 1].toUpperCase();
|
|
79
|
+
t = t.substring(0, t.length - 1).trim();
|
|
80
|
+
const o = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
81
|
+
let [r, i, c] = o;
|
|
82
|
+
if (i = i || 0, i = i > 60 ? i / Math.pow(10, String(i).length - 2) : i, c = c || 0, c = c > 60 ? c / Math.pow(10, String(c).length - 2) : c, r > 360 && !i) {
|
|
83
|
+
const a = this.roundPrecision(r / 100, 0);
|
|
84
|
+
i = r - a * 100, r = a;
|
|
85
85
|
}
|
|
86
|
-
n =
|
|
86
|
+
n = r + i / 60 + c / 3600, s === "W" && (n = n * -1);
|
|
87
87
|
} else
|
|
88
|
-
n = Number(
|
|
89
|
-
return d.convertToStdLng(n,
|
|
88
|
+
n = Number(t);
|
|
89
|
+
return d.convertToStdLng(n, e);
|
|
90
90
|
}
|
|
91
|
-
static str2Lat(
|
|
91
|
+
static str2Lat(t, e = 6) {
|
|
92
92
|
let n;
|
|
93
|
-
if (isNaN(
|
|
94
|
-
|
|
95
|
-
const s =
|
|
96
|
-
|
|
97
|
-
const o =
|
|
98
|
-
let [
|
|
99
|
-
if (c = c || 0,
|
|
100
|
-
const a = this.roundPrecision(
|
|
101
|
-
|
|
93
|
+
if (isNaN(t)) {
|
|
94
|
+
t = d.strReplace(t, "LAT");
|
|
95
|
+
const s = t[t.length - 1].toUpperCase();
|
|
96
|
+
t = t.substring(0, t.length - 1).trim();
|
|
97
|
+
const o = t.split(" ").filter((a) => a !== "").map((a) => Math.abs(Number(a)));
|
|
98
|
+
let [r, i, c] = o;
|
|
99
|
+
if (c = c || 0, i = i || 0, i = i > 60 ? i / Math.pow(10, String(i).length - 2) : i, c = c > 60 ? c / Math.pow(10, String(c).length - 2) : c, r > 90 && !i) {
|
|
100
|
+
const a = this.roundPrecision(r / 100, 0);
|
|
101
|
+
i = r - a * 100, r = a;
|
|
102
102
|
}
|
|
103
|
-
if (n =
|
|
104
|
-
throw new Error(`latitude out of range: ${
|
|
103
|
+
if (n = r + i / 60 + c / 3600, n > 90)
|
|
104
|
+
throw new Error(`latitude out of range: ${t}${s}`);
|
|
105
105
|
s === "S" && (n = n * -1);
|
|
106
106
|
} else
|
|
107
|
-
n = Number(
|
|
108
|
-
return d.roundPrecision(n,
|
|
107
|
+
n = Number(t);
|
|
108
|
+
return d.roundPrecision(n, e);
|
|
109
109
|
}
|
|
110
|
-
static str2LngOrLat(
|
|
111
|
-
|
|
112
|
-
const s =
|
|
110
|
+
static str2LngOrLat(t, e = 6, n = "LAT") {
|
|
111
|
+
t = d.strReplace(t, n);
|
|
112
|
+
const s = t[t.length - 1].toUpperCase();
|
|
113
113
|
return ["N", "S"].includes(s) ? {
|
|
114
|
-
lat: d.str2Lat(
|
|
114
|
+
lat: d.str2Lat(t, e)
|
|
115
115
|
} : {
|
|
116
|
-
lng: d.str2Lng(
|
|
116
|
+
lng: d.str2Lng(t, e)
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
static convertToStdLng(
|
|
120
|
-
return
|
|
119
|
+
static convertToStdLng(t, e = 6) {
|
|
120
|
+
return t > 180 ? (t = t % 360, t = t > 180 ? t - 360 : t) : t < -180 && (t = t % 360, t = t < -180 ? t + 360 : t), d.roundPrecision(t, e);
|
|
121
121
|
}
|
|
122
|
-
static roundPrecision(
|
|
123
|
-
const n = Number("1".padEnd(
|
|
124
|
-
return Math.round(
|
|
122
|
+
static roundPrecision(t, e = 6) {
|
|
123
|
+
const n = Number("1".padEnd(e + 1, "0"));
|
|
124
|
+
return Math.round(t * n) / n;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* 转换为按经度单调增/减的坐标数组
|
|
128
128
|
* @param coordinates
|
|
129
129
|
*/
|
|
130
|
-
static convertToMonotonicLng2(
|
|
131
|
-
for (let
|
|
132
|
-
e
|
|
133
|
-
return
|
|
130
|
+
static convertToMonotonicLng2(t) {
|
|
131
|
+
for (let e = 1; e < t.length; e++)
|
|
132
|
+
t[e][0] += Math.round((t[e - 1][0] - t[e][0]) / 360) * 360;
|
|
133
|
+
return t;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* 转移为按经度单调增/减的坐标数组
|
|
137
137
|
* @param coordinates
|
|
138
138
|
*/
|
|
139
|
-
static convertToMonotonicLng(
|
|
140
|
-
for (let
|
|
141
|
-
e
|
|
142
|
-
return
|
|
139
|
+
static convertToMonotonicLng(t) {
|
|
140
|
+
for (let e = 1; e < t.length; e++)
|
|
141
|
+
t[e].lng += Math.round((t[e - 1].lng - t[e].lng) / 360) * 360;
|
|
142
|
+
return t;
|
|
143
143
|
}
|
|
144
|
-
static strReplace(
|
|
145
|
-
|
|
146
|
-
const n =
|
|
144
|
+
static strReplace(t, e = "LAT") {
|
|
145
|
+
t = t.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g, "$1 $2").replace(/([0-9]+)-([0-9]+\.[0-9]+)/g, "$1 $2").replace(/°/, " ").replace(/(\d+)-(\d?)/g, "$1 $2").replace(/'/g, " ").replace(/′/g, " ").replace(/"/g, " ").replace(/∼/g, " ").replace(/°/g, " ").replace(/,/g, ".").replace(/^ /g, "").replace(/ $/g, "").trim();
|
|
146
|
+
const n = t[t.length - 1].toUpperCase();
|
|
147
147
|
if (!["N", "S", "E", "W"].includes(n)) {
|
|
148
|
-
const s =
|
|
148
|
+
const s = t, o = Number(s.split(" ")[0]);
|
|
149
149
|
if (isNaN(o))
|
|
150
|
-
throw new Error(`invalid Lat/Lng: ${
|
|
151
|
-
o >= 90 ?
|
|
150
|
+
throw new Error(`invalid Lat/Lng: ${t}`);
|
|
151
|
+
o >= 90 ? t = `${s}E` : o <= -90 ? t = `${s}W` : ["LAN", "LNG"].includes(e == null ? void 0 : e.toUpperCase()) ? t = `${s}${o > 0 ? "E" : "W"}` : t = `${s}${o > 0 ? "N" : "S"}`;
|
|
152
152
|
}
|
|
153
|
-
return
|
|
153
|
+
return t;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* 数据格式
|
|
@@ -159,25 +159,25 @@ class d {
|
|
|
159
159
|
* @param intPrecision 整数位数
|
|
160
160
|
* @param dcmPrecision 小数位数
|
|
161
161
|
*/
|
|
162
|
-
static padNumber(
|
|
163
|
-
const s = d.roundPrecision(
|
|
162
|
+
static padNumber(t, e = 2, n = 2) {
|
|
163
|
+
const s = d.roundPrecision(t - Math.trunc(t), n), o = s >= 1 ? Math.trunc(t + 1).toString().padStart(e, "0") : Math.trunc(t).toString().padStart(e, "0");
|
|
164
164
|
return s >= 1 ? o : n > 0 ? `${o}.${Math.trunc(s * Math.pow(10, n)).toString().padStart(n, "0")}` : o;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
class K {
|
|
168
|
-
static json2Str(
|
|
169
|
-
const
|
|
170
|
-
return `${
|
|
168
|
+
static json2Str(t) {
|
|
169
|
+
const e = t.type ? t.type[0].toUpperCase() : "A";
|
|
170
|
+
return `${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo || {})}|${t.vendor}|${t.deleted}`;
|
|
171
171
|
}
|
|
172
|
-
static str2Json(
|
|
173
|
-
const [
|
|
172
|
+
static str2Json(t) {
|
|
173
|
+
const [e, n, s, o, r, i, c, a, l, u, f] = t.split("|");
|
|
174
174
|
return {
|
|
175
|
-
lat: Number(
|
|
175
|
+
lat: Number(e),
|
|
176
176
|
lng: Number(n),
|
|
177
177
|
positionTime: Number(s),
|
|
178
178
|
sog: Number(o),
|
|
179
|
-
cog: Number(
|
|
180
|
-
hdg: Number(
|
|
179
|
+
cog: Number(r),
|
|
180
|
+
hdg: Number(i),
|
|
181
181
|
//@ts-ignore
|
|
182
182
|
draught: isNaN(c) ? null : Number(c),
|
|
183
183
|
type: a,
|
|
@@ -187,50 +187,50 @@ class K {
|
|
|
187
187
|
deleted: f === "true"
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
-
static inspectStoppages(
|
|
191
|
-
const s =
|
|
192
|
-
s ||
|
|
190
|
+
static inspectStoppages(t, e = 1, n = !0) {
|
|
191
|
+
const s = t.at(0).positionTime < t.at(-1).positionTime;
|
|
192
|
+
s || t.sort((c, a) => c.positionTime - a.positionTime);
|
|
193
193
|
const o = [];
|
|
194
|
-
let
|
|
195
|
-
for (let c = 0; c <
|
|
196
|
-
const a =
|
|
194
|
+
let r, i;
|
|
195
|
+
for (let c = 0; c < t.length - 1; c++) {
|
|
196
|
+
const a = t[c];
|
|
197
197
|
if (!(n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))) {
|
|
198
|
-
for (let l = c + 1; l <
|
|
199
|
-
const u =
|
|
198
|
+
for (let l = c + 1; l < t.length; l++) {
|
|
199
|
+
const u = t[l - 1], f = t[l];
|
|
200
200
|
if (n && ["N", "B", "E", "NOON", "BOSP", "EOSP"].includes(a.type))
|
|
201
201
|
continue;
|
|
202
202
|
const h = f.positionTime - u.positionTime;
|
|
203
|
-
if (v.calculateDistance(f, u, !0, 4) / (h / 3600) <
|
|
204
|
-
|
|
203
|
+
if (v.calculateDistance(f, u, !0, 4) / (h / 3600) < e)
|
|
204
|
+
r || (r = a), l === t.length - 1 && (i = f, c = l);
|
|
205
205
|
else {
|
|
206
|
-
|
|
206
|
+
r && (i = t[l - 1], c = l);
|
|
207
207
|
break;
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
if ((
|
|
210
|
+
if ((i == null ? void 0 : i.positionTime) > (r == null ? void 0 : r.positionTime) && r) {
|
|
211
211
|
const l = {
|
|
212
212
|
start: {
|
|
213
|
-
lat: i.lat,
|
|
214
|
-
lng: i.lng,
|
|
215
|
-
sog: i.sog,
|
|
216
|
-
positionTime: i.positionTime,
|
|
217
|
-
utc: b.unix(i.positionTime).utc().format()
|
|
218
|
-
},
|
|
219
|
-
end: {
|
|
220
213
|
lat: r.lat,
|
|
221
214
|
lng: r.lng,
|
|
222
215
|
sog: r.sog,
|
|
223
216
|
positionTime: r.positionTime,
|
|
224
217
|
utc: b.unix(r.positionTime).utc().format()
|
|
225
218
|
},
|
|
226
|
-
|
|
227
|
-
|
|
219
|
+
end: {
|
|
220
|
+
lat: i.lat,
|
|
221
|
+
lng: i.lng,
|
|
222
|
+
sog: i.sog,
|
|
223
|
+
positionTime: i.positionTime,
|
|
224
|
+
utc: b.unix(i.positionTime).utc().format()
|
|
225
|
+
},
|
|
226
|
+
duration: i.positionTime - r.positionTime
|
|
227
|
+
}, u = t.filter((h) => h.positionTime >= l.start.positionTime && h.positionTime <= l.end.positionTime), f = v.divideAccordingToLng(u);
|
|
228
228
|
l.distance = v.calculateRouteDistance(f), l.hours = Math.round(l.duration / 3600 * 10) / 10, l.avgSog = Math.round(l.distance / l.hours * 10) / 10, o.push(l);
|
|
229
229
|
}
|
|
230
|
-
|
|
230
|
+
r = void 0, i = void 0;
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
return s ||
|
|
233
|
+
return s || t.sort((c, a) => a.positionTime - c.positionTime), o;
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* 计算轨迹摘要
|
|
@@ -238,17 +238,17 @@ class K {
|
|
|
238
238
|
* @param stm
|
|
239
239
|
* @param etm
|
|
240
240
|
*/
|
|
241
|
-
static inspectSummary(
|
|
242
|
-
const s = b(
|
|
243
|
-
let
|
|
244
|
-
if (
|
|
245
|
-
for (let l = 0; l <
|
|
246
|
-
const u =
|
|
247
|
-
|
|
241
|
+
static inspectSummary(t, e, n) {
|
|
242
|
+
const s = b(e), o = b(n), r = t.filter((l) => l.positionTime >= s.unix() && l.positionTime <= o.unix());
|
|
243
|
+
let i = 0, c = 0;
|
|
244
|
+
if (r.length > 1)
|
|
245
|
+
for (let l = 0; l < r.length - 1; l++) {
|
|
246
|
+
const u = r[l], f = r[l + 1];
|
|
247
|
+
i += v.calculateDistance(u, f, !0, 4), c += Math.abs(f.positionTime - u.positionTime);
|
|
248
248
|
}
|
|
249
|
-
|
|
250
|
-
const a = c ? Math.round(
|
|
251
|
-
return { distance:
|
|
249
|
+
i = Math.round(i * 100) / 100, c = Math.round(c / 3600 * 100) / 100;
|
|
250
|
+
const a = c ? Math.round(i / c * 100) / 100 : 0;
|
|
251
|
+
return { distance: i, interval: c, avgSpd: a };
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
let X;
|
|
@@ -259,48 +259,48 @@ try {
|
|
|
259
259
|
}
|
|
260
260
|
const Q = (() => {
|
|
261
261
|
const C = new Uint32Array(256);
|
|
262
|
-
for (let
|
|
263
|
-
let
|
|
262
|
+
for (let t = 0; t < 256; t++) {
|
|
263
|
+
let e = t;
|
|
264
264
|
for (let n = 0; n < 8; n++)
|
|
265
|
-
|
|
266
|
-
C[
|
|
265
|
+
e = e & 1 ? 3988292384 ^ e >>> 1 : e >>> 1;
|
|
266
|
+
C[t] = e;
|
|
267
267
|
}
|
|
268
268
|
return C;
|
|
269
269
|
})();
|
|
270
270
|
function Y(C) {
|
|
271
|
-
let
|
|
272
|
-
for (let
|
|
273
|
-
|
|
274
|
-
return (
|
|
271
|
+
let t = 4294967295;
|
|
272
|
+
for (let e = 0; e < C.length; e++)
|
|
273
|
+
t = Q[(t ^ C[e]) & 255] ^ t >>> 8;
|
|
274
|
+
return (t ^ 4294967295) >>> 0;
|
|
275
275
|
}
|
|
276
276
|
function _(C) {
|
|
277
|
-
const
|
|
277
|
+
const t = new TextEncoder(), e = [], n = [];
|
|
278
278
|
let s = 0;
|
|
279
279
|
for (const h of C) {
|
|
280
|
-
const g =
|
|
281
|
-
S.setUint32(0, 67324752, !0), S.setUint16(4, 20, !0), S.setUint16(8, 0, !0), S.setUint32(14, m, !0), S.setUint32(18, h.data.length, !0), S.setUint32(22, h.data.length, !0), S.setUint16(26, g.length, !0), p.set(g, 30),
|
|
280
|
+
const g = t.encode(h.name), m = Y(h.data), p = new Uint8Array(30 + g.length), S = new DataView(p.buffer);
|
|
281
|
+
S.setUint32(0, 67324752, !0), S.setUint16(4, 20, !0), S.setUint16(8, 0, !0), S.setUint32(14, m, !0), S.setUint32(18, h.data.length, !0), S.setUint32(22, h.data.length, !0), S.setUint16(26, g.length, !0), p.set(g, 30), e.push({ nameBytes: g, data: h.data, crc: m, offset: s }), s += p.length + h.data.length, n.push(p, h.data);
|
|
282
282
|
}
|
|
283
|
-
const o = s,
|
|
284
|
-
let
|
|
285
|
-
for (const h of
|
|
283
|
+
const o = s, r = [];
|
|
284
|
+
let i = 0;
|
|
285
|
+
for (const h of e) {
|
|
286
286
|
const g = new Uint8Array(46 + h.nameBytes.length), m = new DataView(g.buffer);
|
|
287
|
-
m.setUint32(0, 33639248, !0), m.setUint16(4, 20, !0), m.setUint16(6, 20, !0), m.setUint16(10, 0, !0), m.setUint32(16, h.crc, !0), m.setUint32(20, h.data.length, !0), m.setUint32(24, h.data.length, !0), m.setUint16(28, h.nameBytes.length, !0), m.setUint32(42, h.offset, !0), g.set(h.nameBytes, 46),
|
|
287
|
+
m.setUint32(0, 33639248, !0), m.setUint16(4, 20, !0), m.setUint16(6, 20, !0), m.setUint16(10, 0, !0), m.setUint32(16, h.crc, !0), m.setUint32(20, h.data.length, !0), m.setUint32(24, h.data.length, !0), m.setUint16(28, h.nameBytes.length, !0), m.setUint32(42, h.offset, !0), g.set(h.nameBytes, 46), i += g.length, r.push(g);
|
|
288
288
|
}
|
|
289
289
|
const c = new Uint8Array(22), a = new DataView(c.buffer);
|
|
290
|
-
a.setUint32(0, 101010256, !0), a.setUint16(8,
|
|
291
|
-
const l = n.reduce((h, g) => h + g.length, 0) +
|
|
290
|
+
a.setUint32(0, 101010256, !0), a.setUint16(8, e.length, !0), a.setUint16(10, e.length, !0), a.setUint32(12, i, !0), a.setUint32(16, o, !0);
|
|
291
|
+
const l = n.reduce((h, g) => h + g.length, 0) + i + 22, u = new Uint8Array(l);
|
|
292
292
|
let f = 0;
|
|
293
293
|
for (const h of n)
|
|
294
294
|
u.set(h, f), f += h.length;
|
|
295
|
-
for (const h of
|
|
295
|
+
for (const h of r)
|
|
296
296
|
u.set(h, f), f += h.length;
|
|
297
297
|
return u.set(c, f), u;
|
|
298
298
|
}
|
|
299
299
|
function z(C) {
|
|
300
|
-
let
|
|
301
|
-
for (;
|
|
302
|
-
|
|
303
|
-
return
|
|
300
|
+
let t = "", e = C;
|
|
301
|
+
for (; e >= 0; )
|
|
302
|
+
t = String.fromCharCode(65 + e % 26) + t, e = Math.floor(e / 26) - 1;
|
|
303
|
+
return t;
|
|
304
304
|
}
|
|
305
305
|
class v {
|
|
306
306
|
/**
|
|
@@ -311,13 +311,13 @@ class v {
|
|
|
311
311
|
* @param precision
|
|
312
312
|
* @returns {number} 单位度
|
|
313
313
|
*/
|
|
314
|
-
static calculateBearing(
|
|
314
|
+
static calculateBearing(t, e, n = !0, s = 4) {
|
|
315
315
|
const o = T.points([
|
|
316
|
-
[
|
|
317
|
-
[
|
|
316
|
+
[t.lng, t.lat],
|
|
317
|
+
[e.lng, e.lat]
|
|
318
318
|
]);
|
|
319
|
-
let
|
|
320
|
-
return n ?
|
|
319
|
+
let r;
|
|
320
|
+
return n ? r = T.rhumbBearing(o.features[0], o.features[1]) : r = T.bearing(o.features[0], o.features[1]), r < 0 && (r += 360), d.roundPrecision(r, s);
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
323
|
* 计算两点间距离
|
|
@@ -328,14 +328,14 @@ class v {
|
|
|
328
328
|
* @param units 单位,默认 nm(海里)
|
|
329
329
|
* @returns {number}
|
|
330
330
|
*/
|
|
331
|
-
static calculateDistance(
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
[
|
|
335
|
-
[
|
|
331
|
+
static calculateDistance(t, e, n = !0, s = 4, o = "nauticalmiles") {
|
|
332
|
+
t = { ...t }, e = { ...e }, t.lng = d.convertToStdLng(t.lng, s), e.lng = d.convertToStdLng(e.lng, s);
|
|
333
|
+
const r = T.points([
|
|
334
|
+
[t.lng, t.lat],
|
|
335
|
+
[e.lng, e.lat]
|
|
336
336
|
]);
|
|
337
|
-
let
|
|
338
|
-
return n ?
|
|
337
|
+
let i;
|
|
338
|
+
return n ? i = T.rhumbDistance(r.features[0], r.features[1], { units: o }) : i = T.distance(r.features[0], r.features[1], { units: o }), d.roundPrecision(i, s);
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* 计算航线距离
|
|
@@ -343,16 +343,16 @@ class v {
|
|
|
343
343
|
* @param precision
|
|
344
344
|
* @param units
|
|
345
345
|
*/
|
|
346
|
-
static calculateRouteDistance(
|
|
346
|
+
static calculateRouteDistance(t, e = 4, n = "nauticalmiles") {
|
|
347
347
|
let s = 0, o;
|
|
348
|
-
for (const
|
|
349
|
-
for (let
|
|
350
|
-
const c = { lng: i
|
|
351
|
-
|
|
352
|
-
const a = { lng: i
|
|
353
|
-
s += this.calculateDistance(c, a, !0,
|
|
348
|
+
for (const r of t)
|
|
349
|
+
for (let i = 0; i < r.length - 1; i++) {
|
|
350
|
+
const c = { lng: r[i][0], lat: r[i][1] };
|
|
351
|
+
i === 0 && o && (s += this.calculateDistance(o, c, !0, e, n));
|
|
352
|
+
const a = { lng: r[i + 1][0], lat: r[i + 1][1] };
|
|
353
|
+
s += this.calculateDistance(c, a, !0, e, n), o = a;
|
|
354
354
|
}
|
|
355
|
-
return d.roundPrecision(s,
|
|
355
|
+
return d.roundPrecision(s, e);
|
|
356
356
|
}
|
|
357
357
|
/**
|
|
358
358
|
* 计算坐标(基于方位角和距离)
|
|
@@ -362,11 +362,11 @@ class v {
|
|
|
362
362
|
* @param units 单位,默认 nm(海里)
|
|
363
363
|
* @param rhumb
|
|
364
364
|
*/
|
|
365
|
-
static calculateCoordinate(
|
|
366
|
-
const
|
|
367
|
-
let
|
|
368
|
-
o ?
|
|
369
|
-
const c =
|
|
365
|
+
static calculateCoordinate(t, e, n, s = "nauticalmiles", o = !0) {
|
|
366
|
+
const r = T.point([t.lng, t.lat]);
|
|
367
|
+
let i;
|
|
368
|
+
o ? i = T.rhumbDestination(r, n, e, { units: s }) : i = T.destination(r, n, e, { units: s });
|
|
369
|
+
const c = i.geometry.coordinates;
|
|
370
370
|
return { lng: d.convertToStdLng(c[0], 8), lat: d.roundPrecision(c[1], 8) };
|
|
371
371
|
}
|
|
372
372
|
/**
|
|
@@ -378,13 +378,13 @@ class v {
|
|
|
378
378
|
* @param includeTail true 包含终点 to
|
|
379
379
|
* @param units 单位,默认 nm(海里)
|
|
380
380
|
*/
|
|
381
|
-
static interpolateCoordinates(
|
|
382
|
-
const
|
|
383
|
-
s &&
|
|
381
|
+
static interpolateCoordinates(t, e, n, s = !0, o = !0, r = "nauticalmiles") {
|
|
382
|
+
const i = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, r);
|
|
383
|
+
s && i.push({ lng: t.lng, lat: t.lat });
|
|
384
384
|
let l = 0;
|
|
385
385
|
for (; l < a; )
|
|
386
|
-
l += n, l < a &&
|
|
387
|
-
return o &&
|
|
386
|
+
l += n, l < a && i.push(this.calculateCoordinate(t, c, l, r, !1));
|
|
387
|
+
return o && i.push({ lng: e.lng, lat: e.lat }), i;
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
390
390
|
* 分组坐标(如相邻两个坐标经度差超180度,需以180为界将坐标分为两组)
|
|
@@ -398,23 +398,23 @@ class v {
|
|
|
398
398
|
* [[-170,40],[-160,30]]
|
|
399
399
|
* ]
|
|
400
400
|
*/
|
|
401
|
-
static divideAccordingToLng(
|
|
402
|
-
if ((
|
|
401
|
+
static divideAccordingToLng(t, e = !1, n = !0) {
|
|
402
|
+
if ((t == null ? void 0 : t.length) < 2)
|
|
403
403
|
return [];
|
|
404
|
-
|
|
404
|
+
t = n ? this.deduplicateCoordinates(t) : t;
|
|
405
405
|
let s = [];
|
|
406
406
|
const o = [];
|
|
407
|
-
let
|
|
408
|
-
for (let c = 0; c <
|
|
409
|
-
|
|
410
|
-
const a =
|
|
407
|
+
let r, i;
|
|
408
|
+
for (let c = 0; c < t.length - 1; c++) {
|
|
409
|
+
r = d.convertToStdLng(t[c].lng, 8), i = d.convertToStdLng(t[c + 1].lng, 8), t[c].lat = d.roundPrecision(t[c].lat, 8), t[c + 1].lat = d.roundPrecision(t[c + 1].lat, 8), s.push([r, t[c].lat]);
|
|
410
|
+
const a = r - i;
|
|
411
411
|
if (Math.abs(a) > 180) {
|
|
412
412
|
const l = d.convertToMonotonicLng2([
|
|
413
|
-
[
|
|
414
|
-
[
|
|
413
|
+
[r, t[c].lat],
|
|
414
|
+
[i, t[c + 1].lat]
|
|
415
415
|
]);
|
|
416
416
|
let u, f;
|
|
417
|
-
|
|
417
|
+
e ? (u = T.lineString(l), f = T.lineString([
|
|
418
418
|
[a > 0 ? 180 : -180, 89],
|
|
419
419
|
[a > 0 ? 180 : -180, -89]
|
|
420
420
|
])) : (u = T.greatCircle(l[0], l[1]), f = T.greatCircle([a > 0 ? 180 : -180, 89], [a > 0 ? 180 : -180, -89]));
|
|
@@ -424,10 +424,10 @@ class v {
|
|
|
424
424
|
const m = T.getCoord(h.features[0]);
|
|
425
425
|
g = d.roundPrecision(m[1], 8);
|
|
426
426
|
} else
|
|
427
|
-
g =
|
|
427
|
+
g = t[c].lat;
|
|
428
428
|
a > 0 ? (s.push([180 - 1e-6, g]), o.push([...s]), s = [], s.push([-(180 - 1e-6), g])) : (s.push([-(180 - 1e-6), g]), o.push([...s]), s = [], s.push([180 - 1e-6, g]));
|
|
429
429
|
}
|
|
430
|
-
c ===
|
|
430
|
+
c === t.length - 2 && s.push([i, t[c + 1].lat]);
|
|
431
431
|
}
|
|
432
432
|
return o.push(s), o;
|
|
433
433
|
}
|
|
@@ -435,43 +435,43 @@ class v {
|
|
|
435
435
|
* 去除重复坐标
|
|
436
436
|
* @param route
|
|
437
437
|
*/
|
|
438
|
-
static deduplicateRoute(
|
|
439
|
-
const
|
|
440
|
-
for (const n of
|
|
441
|
-
const s = n.reduce((o,
|
|
442
|
-
|
|
438
|
+
static deduplicateRoute(t) {
|
|
439
|
+
const e = [];
|
|
440
|
+
for (const n of t) {
|
|
441
|
+
const s = n.reduce((o, r) => (o.findIndex((i) => i[0] === r[0] && i[1] === r[1]) === -1 && o.push(r), o), []);
|
|
442
|
+
e.push(s);
|
|
443
443
|
}
|
|
444
|
-
return
|
|
444
|
+
return e;
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
447
|
* 去除重新坐标
|
|
448
448
|
* @param coordinates
|
|
449
449
|
*/
|
|
450
|
-
static deduplicateCoordinates(
|
|
451
|
-
return
|
|
450
|
+
static deduplicateCoordinates(t) {
|
|
451
|
+
return t.reduce((e, n) => (e.findIndex((s) => s.lat === n.lat && s.lng === n.lng) === -1 && e.push(n), e), []);
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
454
|
* 移出坐标
|
|
455
455
|
* @param coordinate {lng, lat}
|
|
456
456
|
* @param route 航线[[[lng, lat],[lng, lat]]]
|
|
457
457
|
*/
|
|
458
|
-
static removeCoordinateFromRoute(
|
|
459
|
-
|
|
460
|
-
for (const n of
|
|
458
|
+
static removeCoordinateFromRoute(t, e) {
|
|
459
|
+
t.lng = d.convertToStdLng(t.lng, 8);
|
|
460
|
+
for (const n of e)
|
|
461
461
|
for (let s = n.length - 1; s >= 0; s--)
|
|
462
|
-
d.roundPrecision(n[s][0], 8) ===
|
|
463
|
-
return
|
|
462
|
+
d.roundPrecision(n[s][0], 8) === t.lng && d.roundPrecision(n[s][1], 8) === d.roundPrecision(t.lat, 8) && n.splice(s, 1);
|
|
463
|
+
return e;
|
|
464
464
|
}
|
|
465
465
|
/**
|
|
466
466
|
* 移出坐标
|
|
467
467
|
* @param coordinate {lng, lat}
|
|
468
468
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
469
469
|
*/
|
|
470
|
-
static removeCoordinateFromWaypoints(
|
|
471
|
-
|
|
472
|
-
for (let n =
|
|
473
|
-
d.roundPrecision(
|
|
474
|
-
return
|
|
470
|
+
static removeCoordinateFromWaypoints(t, e) {
|
|
471
|
+
t.lng = d.convertToStdLng(t.lng, 8);
|
|
472
|
+
for (let n = e.length - 1; n >= 0; n--)
|
|
473
|
+
d.roundPrecision(e[n].lng, 8) === t.lng && d.roundPrecision(e[n].lat, 8) === d.roundPrecision(t.lat, 8) && e.splice(n, 1);
|
|
474
|
+
return e;
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
477
|
* 合并坐标进航线(基于坐标到线段最短距离边合并)
|
|
@@ -484,44 +484,44 @@ class v {
|
|
|
484
484
|
* @return
|
|
485
485
|
* [[[120, 30], [120, 35], [125,40], [130, 37]], [[-150, 40], [-130, 30]]]
|
|
486
486
|
*/
|
|
487
|
-
static mergeCoordinateToRoute(
|
|
488
|
-
|
|
489
|
-
let n = Number.MAX_VALUE, s = 0, o = 0,
|
|
490
|
-
return
|
|
487
|
+
static mergeCoordinateToRoute(t, e) {
|
|
488
|
+
t.lng = d.convertToStdLng(t.lng, 8);
|
|
489
|
+
let n = Number.MAX_VALUE, s = 0, o = 0, r, i;
|
|
490
|
+
return e.forEach((c, a) => {
|
|
491
491
|
for (let l = 0; l < c.length - 1; l++) {
|
|
492
|
-
const u = { lng: c[l][0], lat: c[l][1] }, f = { lng: c[l + 1][0], lat: c[l + 1][1] }, h = this.calculatePointToLineDistance(
|
|
493
|
-
n > h && (n = h, o = l, s = a,
|
|
492
|
+
const u = { lng: c[l][0], lat: c[l][1] }, f = { lng: c[l + 1][0], lat: c[l + 1][1] }, h = this.calculatePointToLineDistance(t, u, f);
|
|
493
|
+
n > h && (n = h, o = l, s = a, r = this.calculateDistance(u, t), i = this.calculateDistance(f, t));
|
|
494
494
|
}
|
|
495
|
-
}),
|
|
495
|
+
}), r !== 0 && i !== 0 ? e[s].splice(o + 1, 0, [t.lng, t.lat]) : r === 0 ? e[s].splice(o, 1, [t.lng, t.lat]) : i === 0 && e[s].splice(o + 1, 1, [t.lng, t.lat]), e;
|
|
496
496
|
}
|
|
497
497
|
/**
|
|
498
498
|
* 向Route尾加1个坐标
|
|
499
499
|
* @param coordinate
|
|
500
500
|
* @param route
|
|
501
501
|
*/
|
|
502
|
-
static appendCoordinateToRoute(
|
|
503
|
-
|
|
504
|
-
const n = v.convertRouteToCoordinates(
|
|
505
|
-
return n.push(
|
|
502
|
+
static appendCoordinateToRoute(t, e) {
|
|
503
|
+
t.lng = d.convertToStdLng(t.lng, 8);
|
|
504
|
+
const n = v.convertRouteToCoordinates(e);
|
|
505
|
+
return n.push(t), v.divideAccordingToLng(n);
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
508
508
|
* 向route头加1个坐标
|
|
509
509
|
* @param coordinate
|
|
510
510
|
* @param route
|
|
511
511
|
*/
|
|
512
|
-
static unshiftCoordinateToRoute(
|
|
513
|
-
const n = v.convertRouteToCoordinates(
|
|
514
|
-
return n.unshift(
|
|
512
|
+
static unshiftCoordinateToRoute(t, e) {
|
|
513
|
+
const n = v.convertRouteToCoordinates(e);
|
|
514
|
+
return n.unshift(t), v.divideAccordingToLng(n);
|
|
515
515
|
}
|
|
516
516
|
/**
|
|
517
517
|
* 合并多个waypoints进航线
|
|
518
518
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
519
519
|
* @param route 航线 [[[lng, lat],[lng, lat]]]
|
|
520
520
|
*/
|
|
521
|
-
static mergeWaypointsToRoute(
|
|
522
|
-
for (const n of
|
|
523
|
-
|
|
524
|
-
return
|
|
521
|
+
static mergeWaypointsToRoute(t, e) {
|
|
522
|
+
for (const n of t)
|
|
523
|
+
e = this.mergeCoordinateToRoute(n, e);
|
|
524
|
+
return e;
|
|
525
525
|
}
|
|
526
526
|
/**
|
|
527
527
|
* 计算区间航线
|
|
@@ -530,22 +530,22 @@ class v {
|
|
|
530
530
|
* @param route [[[lng, lat]]]
|
|
531
531
|
* @return [[[lng, lat]]]
|
|
532
532
|
*/
|
|
533
|
-
static calculateRangeRoute(
|
|
534
|
-
n = this.mergeWaypointsToRoute([
|
|
533
|
+
static calculateRangeRoute(t, e, n) {
|
|
534
|
+
n = this.mergeWaypointsToRoute([t, e], n);
|
|
535
535
|
const s = [];
|
|
536
536
|
let o = 0;
|
|
537
|
-
return n.forEach((
|
|
537
|
+
return n.forEach((r) => {
|
|
538
538
|
if (o === 2)
|
|
539
539
|
return;
|
|
540
|
-
const
|
|
541
|
-
for (const c of
|
|
542
|
-
if (d.roundPrecision(
|
|
543
|
-
|
|
540
|
+
const i = [];
|
|
541
|
+
for (const c of r) {
|
|
542
|
+
if (d.roundPrecision(e.lng, 8) === d.roundPrecision(c[0], 8) && d.roundPrecision(e.lat, 8) === d.roundPrecision(c[1], 8)) {
|
|
543
|
+
i.push(c), o === 0 && i.push([t.lng, t.lat]), o = 2;
|
|
544
544
|
break;
|
|
545
545
|
}
|
|
546
|
-
o === 1 ?
|
|
546
|
+
o === 1 ? i.push(c) : d.roundPrecision(t.lng, 8) === d.roundPrecision(c[0], 8) && d.roundPrecision(t.lat, 8) === d.roundPrecision(c[1], 8) && (o = 1, i.push(c));
|
|
547
547
|
}
|
|
548
|
-
|
|
548
|
+
i.length && s.push(i);
|
|
549
549
|
}), s;
|
|
550
550
|
}
|
|
551
551
|
/**
|
|
@@ -556,25 +556,25 @@ class v {
|
|
|
556
556
|
* @param waypoints
|
|
557
557
|
* @return [{lng, lat}]
|
|
558
558
|
*/
|
|
559
|
-
static calculateRangeWaypoints(
|
|
560
|
-
const o = this.convertRouteToCoordinates(n, 0),
|
|
561
|
-
(l) => d.roundPrecision(e.lng, 8) === d.roundPrecision(l.lng, 8) && d.roundPrecision(e.lat, 8) === d.roundPrecision(l.lat, 8)
|
|
562
|
-
), c = i.findIndex(
|
|
559
|
+
static calculateRangeWaypoints(t, e, n, s = []) {
|
|
560
|
+
const o = this.convertRouteToCoordinates(n, 0), r = this.mergeCoordinatesToWaypoints([t, e], o.length ? o : s), i = r.findIndex(
|
|
563
561
|
(l) => d.roundPrecision(t.lng, 8) === d.roundPrecision(l.lng, 8) && d.roundPrecision(t.lat, 8) === d.roundPrecision(l.lat, 8)
|
|
562
|
+
), c = r.findIndex(
|
|
563
|
+
(l) => d.roundPrecision(e.lng, 8) === d.roundPrecision(l.lng, 8) && d.roundPrecision(e.lat, 8) === d.roundPrecision(l.lat, 8)
|
|
564
564
|
);
|
|
565
|
-
return
|
|
565
|
+
return r.filter((l, u) => u >= i && u <= c);
|
|
566
566
|
}
|
|
567
567
|
/**
|
|
568
568
|
* 计算坐标到航路上的最短距离
|
|
569
569
|
* @param from
|
|
570
570
|
* @param route
|
|
571
571
|
*/
|
|
572
|
-
static calculateMinDistanceToRoute(
|
|
572
|
+
static calculateMinDistanceToRoute(t, e) {
|
|
573
573
|
let n = Number.MAX_VALUE, s = 0, o = 0;
|
|
574
|
-
return
|
|
575
|
-
for (let c = 0; c <
|
|
576
|
-
const a = { lng:
|
|
577
|
-
n > u && (n = u, s = c, o =
|
|
574
|
+
return e.forEach((r, i) => {
|
|
575
|
+
for (let c = 0; c < r.length - 1; c++) {
|
|
576
|
+
const a = { lng: r[c][0], lat: r[c][1] }, l = { lng: r[c + 1][0], lat: r[c + 1][1] }, u = this.calculatePointToLineDistance(t, a, l);
|
|
577
|
+
n > u && (n = u, s = c, o = i);
|
|
578
578
|
}
|
|
579
579
|
}), { minDist: n, segIndex: o, minIndex: s };
|
|
580
580
|
}
|
|
@@ -584,23 +584,23 @@ class v {
|
|
|
584
584
|
* @param route [[[lng, lat]]] 剩余航线
|
|
585
585
|
* @return [[[lng, lat]]]
|
|
586
586
|
*/
|
|
587
|
-
static calculateSubRoute(
|
|
588
|
-
const n = v.convertRouteToCoordinates(
|
|
589
|
-
v.mergeCoordinateToWaypoints(
|
|
590
|
-
const { segIndex: s, minIndex: o } = this.calculateMinDistanceToRoute({ ...
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
let
|
|
594
|
-
for (let c = s; c <
|
|
595
|
-
if (
|
|
587
|
+
static calculateSubRoute(t, e) {
|
|
588
|
+
const n = v.convertRouteToCoordinates(e);
|
|
589
|
+
v.mergeCoordinateToWaypoints(t, n, !0), e = v.divideAccordingToLng(n);
|
|
590
|
+
const { segIndex: s, minIndex: o } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
591
|
+
t.lng = d.convertToStdLng(t.lng);
|
|
592
|
+
const r = [];
|
|
593
|
+
let i = !0;
|
|
594
|
+
for (let c = s; c < e.length; c++)
|
|
595
|
+
if (i) {
|
|
596
596
|
const a = [];
|
|
597
|
-
a.push([
|
|
598
|
-
for (let l = o + 1; l <
|
|
599
|
-
|
|
600
|
-
|
|
597
|
+
a.push([t.lng, t.lat]);
|
|
598
|
+
for (let l = o + 1; l < e[c].length; l++)
|
|
599
|
+
t.lng === e[c][l][0] && t.lat === e[c][l][1] || a.push(e[c][l]);
|
|
600
|
+
r.push(a), i = !1;
|
|
601
601
|
} else
|
|
602
|
-
|
|
603
|
-
return
|
|
602
|
+
r.push([...e[c]]);
|
|
603
|
+
return r;
|
|
604
604
|
}
|
|
605
605
|
/**
|
|
606
606
|
* 计算子途经点
|
|
@@ -608,21 +608,21 @@ class v {
|
|
|
608
608
|
* @param waypoints [{lng, lat}]
|
|
609
609
|
* @return [{lng, lat}]
|
|
610
610
|
*/
|
|
611
|
-
static calculateSubWaypoints(
|
|
611
|
+
static calculateSubWaypoints(t, e) {
|
|
612
612
|
let n = Number.MAX_VALUE, s = 0;
|
|
613
|
-
for (let
|
|
614
|
-
const
|
|
615
|
-
if (this.calculateDistance(
|
|
616
|
-
return
|
|
617
|
-
if (this.calculateDistance(
|
|
618
|
-
return
|
|
619
|
-
const a = this.calculatePointToLineDistance(
|
|
620
|
-
n > a && (n = a, s =
|
|
613
|
+
for (let r = 0; r < e.length - 1; r++) {
|
|
614
|
+
const i = e[r], c = e[r + 1];
|
|
615
|
+
if (this.calculateDistance(t, i) === 0)
|
|
616
|
+
return e;
|
|
617
|
+
if (this.calculateDistance(t, c) === 0)
|
|
618
|
+
return e.filter((l, u) => u > 0);
|
|
619
|
+
const a = this.calculatePointToLineDistance(t, i, c);
|
|
620
|
+
n > a && (n = a, s = r);
|
|
621
621
|
}
|
|
622
|
-
|
|
623
|
-
const o = [
|
|
624
|
-
for (let
|
|
625
|
-
o.push(
|
|
622
|
+
t.lng = d.convertToStdLng(t.lng);
|
|
623
|
+
const o = [t];
|
|
624
|
+
for (let r = s + 1; r < e.length; r++)
|
|
625
|
+
o.push(e[r]);
|
|
626
626
|
return o;
|
|
627
627
|
}
|
|
628
628
|
/**
|
|
@@ -632,38 +632,38 @@ class v {
|
|
|
632
632
|
* @param to { lng, lat }
|
|
633
633
|
* @param options
|
|
634
634
|
*/
|
|
635
|
-
static calculatePointToLineDistance(
|
|
636
|
-
|
|
637
|
-
const o = d.convertToMonotonicLng([
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
[
|
|
635
|
+
static calculatePointToLineDistance(t, e, n, s = { units: "nauticalmiles", method: "geodesic" }) {
|
|
636
|
+
t.lng = d.convertToStdLng(t.lng, 8), e = { ...e }, n = { ...n }, e.lng = d.convertToStdLng(e.lng, 8), n.lng = d.convertToStdLng(n.lng, 8);
|
|
637
|
+
const o = d.convertToMonotonicLng([e, n]);
|
|
638
|
+
e = o[0], n = o[1];
|
|
639
|
+
const r = T.lineString([
|
|
640
|
+
[e.lng, e.lat],
|
|
641
641
|
[n.lng, n.lat]
|
|
642
|
-
]),
|
|
643
|
-
return d.roundPrecision(Math.min(
|
|
642
|
+
]), i = T.pointToLineDistance(T.point([t.lng, t.lat]), r, s), c = T.pointToLineDistance(T.point([t.lng > 0 ? t.lng - 360 : t.lng + 360, t.lat]), r, s);
|
|
643
|
+
return d.roundPrecision(Math.min(i, c), 6);
|
|
644
644
|
}
|
|
645
645
|
/**
|
|
646
646
|
* 计算途经点的COG, Distance等属性
|
|
647
647
|
* @param waypoints
|
|
648
648
|
* @param route
|
|
649
649
|
*/
|
|
650
|
-
static calculateWaypointsPropInRoute(
|
|
651
|
-
|
|
652
|
-
for (let n = 0; n <
|
|
653
|
-
const s =
|
|
654
|
-
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(
|
|
650
|
+
static calculateWaypointsPropInRoute(t, e) {
|
|
651
|
+
e = this.mergeWaypointsToRoute(t, e);
|
|
652
|
+
for (let n = 0; n < t.length - 1; n++) {
|
|
653
|
+
const s = t[n], o = t[n + 1], r = this.calculateRangeRoute(s, o, e);
|
|
654
|
+
n === 0 && (s.distanceFromPrevious = 0, s.distanceFromStart = 0), o.distanceFromPrevious = this.calculateRouteDistance(r), o.distanceFromStart = d.roundPrecision((s.distanceFromStart || 0) + o.distanceFromPrevious);
|
|
655
655
|
}
|
|
656
|
-
return
|
|
656
|
+
return t;
|
|
657
657
|
}
|
|
658
658
|
/**
|
|
659
659
|
* @param coordinates [{lng, lat}]
|
|
660
660
|
* @param waypoints [{lng, lat}]
|
|
661
661
|
* @param replace true replace the same waypoint with coordinate
|
|
662
662
|
*/
|
|
663
|
-
static mergeCoordinatesToWaypoints(
|
|
664
|
-
for (const s of
|
|
665
|
-
this.mergeCoordinateToWaypoints(s,
|
|
666
|
-
return
|
|
663
|
+
static mergeCoordinatesToWaypoints(t, e, n = !0) {
|
|
664
|
+
for (const s of t)
|
|
665
|
+
this.mergeCoordinateToWaypoints(s, e, n);
|
|
666
|
+
return e;
|
|
667
667
|
}
|
|
668
668
|
/**
|
|
669
669
|
* 合并坐标进航路途经点
|
|
@@ -677,21 +677,21 @@ class v {
|
|
|
677
677
|
* @return
|
|
678
678
|
* [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: 179, lat: 50}, {lng: -170, lat: 40}, {lng: -160, lat: 30}]
|
|
679
679
|
*/
|
|
680
|
-
static mergeCoordinateToWaypoints(
|
|
681
|
-
|
|
682
|
-
let s = Number.MAX_VALUE, o = 0,
|
|
683
|
-
if (
|
|
684
|
-
|
|
680
|
+
static mergeCoordinateToWaypoints(t, e, n = !0) {
|
|
681
|
+
t.lng = d.convertToStdLng(t.lng, 8);
|
|
682
|
+
let s = Number.MAX_VALUE, o = 0, r = 0, i = 0;
|
|
683
|
+
if (e.length < 2)
|
|
684
|
+
e.push(t);
|
|
685
685
|
else {
|
|
686
|
-
for (let c = 0; c <
|
|
687
|
-
const a = { lng:
|
|
688
|
-
s >= u && (s = u, o = c,
|
|
686
|
+
for (let c = 0; c < e.length - 1; c++) {
|
|
687
|
+
const a = { lng: e[c].lng, lat: e[c].lat }, l = { lng: e[c + 1].lng, lat: e[c + 1].lat }, u = this.calculatePointToLineDistance(t, a, l);
|
|
688
|
+
s >= u && (s = u, o = c, r = this.calculateDistance(a, t, !1, 6), i = this.calculateDistance(l, t, !1, 6));
|
|
689
689
|
}
|
|
690
|
-
|
|
690
|
+
r !== 0 && i !== 0 ? r <= s && o === 0 ? e.unshift(t) : i <= s && o === e.length - 2 ? e.push(t) : e.splice(o + 1, 0, t) : r === 0 ? n ? e.splice(o, 1, t) : e.splice(o + 1, 0, t) : i === 0 && (n ? e.splice(o + 1, 1, t) : e.splice(o + 1, 0, t));
|
|
691
691
|
}
|
|
692
|
-
return
|
|
692
|
+
return e.map((c, a) => {
|
|
693
693
|
c.lng = d.convertToStdLng(c.lng);
|
|
694
|
-
const l =
|
|
694
|
+
const l = e[a + 1];
|
|
695
695
|
if (l && ((c.bearing === null || c.bearing === void 0) && ((c.positionTime || 0) > (l.positionTime || 0) ? c.bearing = this.calculateBearing(l, c, !0) : c.bearing = this.calculateBearing(c, l, !0)), c.cog = c.cog || c.bearing, !c.sog && c.positionTime && l.positionTime)) {
|
|
696
696
|
const u = this.calculateDistance(c, l, !0), f = Math.abs(l.positionTime - c.positionTime) / 3600;
|
|
697
697
|
c.sog = d.roundPrecision(u / f, 2);
|
|
@@ -706,25 +706,25 @@ class v {
|
|
|
706
706
|
* @param rhumb
|
|
707
707
|
* @param deduplicate
|
|
708
708
|
*/
|
|
709
|
-
static generateRouteAccordingToWaypoints(
|
|
709
|
+
static generateRouteAccordingToWaypoints(t, e = !0, n = !0) {
|
|
710
710
|
const s = [];
|
|
711
|
-
for (let o = 1; o <
|
|
712
|
-
const
|
|
713
|
-
if (o === 1 && s.push(
|
|
714
|
-
const c = this.interpolateCoordinates(
|
|
711
|
+
for (let o = 1; o < t.length; o++) {
|
|
712
|
+
const r = t[o - 1], i = t[o];
|
|
713
|
+
if (o === 1 && s.push(r), i.gcToPrevious) {
|
|
714
|
+
const c = this.interpolateCoordinates(r, i, 200, !1, !0, "nauticalmiles");
|
|
715
715
|
s.push(...c);
|
|
716
716
|
} else
|
|
717
|
-
s.push(
|
|
717
|
+
s.push(i);
|
|
718
718
|
}
|
|
719
|
-
return this.divideAccordingToLng(s,
|
|
719
|
+
return this.divideAccordingToLng(s, e, n);
|
|
720
720
|
}
|
|
721
721
|
/**
|
|
722
722
|
* 最近点(从route中找出距离目标点最近的点)
|
|
723
723
|
* @param coordinate 目标点 {lng, lat}
|
|
724
724
|
* @param route [[[lng, lat]]]
|
|
725
725
|
*/
|
|
726
|
-
static nearestCoordinateInRoute(
|
|
727
|
-
const n = T.point([
|
|
726
|
+
static nearestCoordinateInRoute(t, e) {
|
|
727
|
+
const n = T.point([t.lng, t.lat]), o = this.convertRouteToCoordinates(e).map((a) => [a.lng, a.lat]), r = T.lineString(o), i = T.nearestPointOnLine(r, n), c = T.getCoord(i);
|
|
728
728
|
return { lng: d.roundPrecision(c[0], 8), lat: d.roundPrecision(c[1], 8) };
|
|
729
729
|
}
|
|
730
730
|
/**
|
|
@@ -732,21 +732,21 @@ class v {
|
|
|
732
732
|
* @param from
|
|
733
733
|
* @param waypoints
|
|
734
734
|
*/
|
|
735
|
-
static calculatePrevWaypoint(
|
|
735
|
+
static calculatePrevWaypoint(t, e) {
|
|
736
736
|
let n = 0;
|
|
737
|
-
this.mergeCoordinateToWaypoints(
|
|
738
|
-
for (let s = 0; s <
|
|
739
|
-
const o =
|
|
740
|
-
if (this.calculateDistance(
|
|
737
|
+
this.mergeCoordinateToWaypoints(t, e);
|
|
738
|
+
for (let s = 0; s < e.length - 1; s++) {
|
|
739
|
+
const o = e[s], r = e[s + 1];
|
|
740
|
+
if (this.calculateDistance(t, o) === 0) {
|
|
741
741
|
n = s;
|
|
742
742
|
break;
|
|
743
743
|
}
|
|
744
|
-
if (this.calculateDistance(
|
|
744
|
+
if (this.calculateDistance(t, r) === 0) {
|
|
745
745
|
n = s + 1;
|
|
746
746
|
break;
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
|
-
return
|
|
749
|
+
return e[n === 0 ? 0 : n - 1];
|
|
750
750
|
}
|
|
751
751
|
/**
|
|
752
752
|
* 计算下一个距离单位的坐标及其子航线
|
|
@@ -756,13 +756,13 @@ class v {
|
|
|
756
756
|
* @param units
|
|
757
757
|
* @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
|
|
758
758
|
*/
|
|
759
|
-
static calculateNextCoordinateAlongRoute(
|
|
759
|
+
static calculateNextCoordinateAlongRoute(t, e, n, s = "nauticalmiles") {
|
|
760
760
|
var f;
|
|
761
|
-
const o =
|
|
762
|
-
let
|
|
763
|
-
if (
|
|
761
|
+
const o = t.speed || 12, r = [];
|
|
762
|
+
let i = [], c = !1, a = 0, l = 0, u;
|
|
763
|
+
if (e && n.length ? (r.push(t), n.forEach((h, g) => {
|
|
764
764
|
if (c)
|
|
765
|
-
|
|
765
|
+
i.push(h);
|
|
766
766
|
else {
|
|
767
767
|
const m = [];
|
|
768
768
|
let p;
|
|
@@ -771,28 +771,28 @@ class v {
|
|
|
771
771
|
m.push(h[S]);
|
|
772
772
|
else {
|
|
773
773
|
p = { lng: h[S][0], lat: h[S][1] };
|
|
774
|
-
const x = this.calculateDistance(
|
|
775
|
-
if (a += x, a <
|
|
776
|
-
l += x, x &&
|
|
774
|
+
const x = this.calculateDistance(t, p, !0, 8, s);
|
|
775
|
+
if (a += x, a < e)
|
|
776
|
+
l += x, x && r.push(p), t = p;
|
|
777
777
|
else {
|
|
778
|
-
if (l =
|
|
778
|
+
if (l = e, a === e)
|
|
779
779
|
u = p, m.push([u.lng, u.lat]);
|
|
780
780
|
else {
|
|
781
|
-
const M = a -
|
|
781
|
+
const M = a - e, y = this.calculateBearing(p, t);
|
|
782
782
|
u = this.calculateCoordinate(p, y, M, s), m.push([u.lng, u.lat]), m.push([p.lng, p.lat]);
|
|
783
783
|
}
|
|
784
784
|
c = !0;
|
|
785
785
|
}
|
|
786
786
|
}
|
|
787
|
-
m.length &&
|
|
787
|
+
m.length && i.push(m), g === n.length - 1 && !u && (u = p);
|
|
788
788
|
}
|
|
789
|
-
})) : (
|
|
790
|
-
if (
|
|
791
|
-
const h = { lng:
|
|
789
|
+
})) : (i = n, u = { ...t }), u)
|
|
790
|
+
if (r.push(u), u.distanceFromPrevious = Math.round(l * 1e4) / 1e4, u.hourFromPrevious = Math.round(l / o * 1e4) / 1e4, ((f = i[0]) == null ? void 0 : f.length) > 1) {
|
|
791
|
+
const h = { lng: i[0][1][0], lat: i[0][1][1] };
|
|
792
792
|
u.bearing = this.calculateBearing(u, h);
|
|
793
793
|
} else
|
|
794
794
|
u.bearing = 0;
|
|
795
|
-
return { coordinate: u, nextRoute:
|
|
795
|
+
return { coordinate: u, nextRoute: i, prevRoute: r };
|
|
796
796
|
}
|
|
797
797
|
/**
|
|
798
798
|
* 返回最近点及其是否为垂足(最近点不是起点或终点)
|
|
@@ -800,31 +800,31 @@ class v {
|
|
|
800
800
|
* @param from {lng, lat}
|
|
801
801
|
* @param to {lng, lat}
|
|
802
802
|
*/
|
|
803
|
-
static nearestCoordinateInLine(
|
|
804
|
-
const s = d.convertToStdLng(
|
|
805
|
-
[
|
|
806
|
-
[
|
|
803
|
+
static nearestCoordinateInLine(t, e, n) {
|
|
804
|
+
const s = d.convertToStdLng(t.lng, 6), o = T.point([s, t.lat]), r = d.convertToStdLng(e.lng, 6), i = d.convertToStdLng(n.lng, 6), c = T.lineString([
|
|
805
|
+
[r, e.lat],
|
|
806
|
+
[i, n.lat]
|
|
807
807
|
]), a = T.nearestPointOnLine(c, o), l = T.getCoord(a), u = d.roundPrecision(l[0], 6), f = d.roundPrecision(l[1], 6);
|
|
808
|
-
return { lng: u, lat: f, inline: !(u ===
|
|
808
|
+
return { lng: u, lat: f, inline: !(u === r && f === e.lat) && !(u === i && f === n.lat) };
|
|
809
809
|
}
|
|
810
810
|
/**
|
|
811
811
|
* 将route转coordinate
|
|
812
812
|
* @param route
|
|
813
813
|
* @param distance 临近点过虑
|
|
814
814
|
*/
|
|
815
|
-
static convertRouteToCoordinates(
|
|
815
|
+
static convertRouteToCoordinates(t, e = 0) {
|
|
816
816
|
const n = [];
|
|
817
817
|
let s, o;
|
|
818
|
-
return
|
|
819
|
-
|
|
820
|
-
const c = { lng: d.roundPrecision(
|
|
818
|
+
return t.forEach((r) => {
|
|
819
|
+
r.forEach((i) => {
|
|
820
|
+
const c = { lng: d.roundPrecision(i[0], 8), lat: d.roundPrecision(i[1], 8) };
|
|
821
821
|
if (!o)
|
|
822
822
|
n.push(c), o = c;
|
|
823
823
|
else if (o.bearing === void 0 || o.bearing === null)
|
|
824
824
|
o.bearing = this.calculateBearing(o, c, !0);
|
|
825
825
|
else {
|
|
826
826
|
const a = this.calculateDistance(s, c, !0);
|
|
827
|
-
a && a >=
|
|
827
|
+
a && a >= e && (s.bearing = this.calculateBearing(s, c, !0), n.push(s), o = s);
|
|
828
828
|
}
|
|
829
829
|
s = c;
|
|
830
830
|
});
|
|
@@ -836,76 +836,76 @@ class v {
|
|
|
836
836
|
* @param waypoints [{ lng, lat, gcToPrevious }]
|
|
837
837
|
* @param distance
|
|
838
838
|
*/
|
|
839
|
-
static simplifyRouteToCoordinates(
|
|
840
|
-
let s = this.convertRouteToCoordinates(
|
|
841
|
-
return s = this.simplifyGCCoordinates(s,
|
|
839
|
+
static simplifyRouteToCoordinates(t, e, n = 1) {
|
|
840
|
+
let s = this.convertRouteToCoordinates(t, n);
|
|
841
|
+
return s = this.simplifyGCCoordinates(s, e), s;
|
|
842
842
|
}
|
|
843
843
|
/**
|
|
844
844
|
* 基于大圆标识抽稀
|
|
845
845
|
* @param coordinates
|
|
846
846
|
* @param waypoints
|
|
847
847
|
*/
|
|
848
|
-
static simplifyGCCoordinates(
|
|
849
|
-
|
|
850
|
-
this.mergeCoordinateToWaypoints(s,
|
|
848
|
+
static simplifyGCCoordinates(t, e) {
|
|
849
|
+
e.forEach((s) => {
|
|
850
|
+
this.mergeCoordinateToWaypoints(s, t, !0);
|
|
851
851
|
});
|
|
852
|
-
for (let s = 1; s <
|
|
853
|
-
const o =
|
|
854
|
-
if (
|
|
855
|
-
const
|
|
856
|
-
for (let a = c - 1; a >
|
|
857
|
-
|
|
852
|
+
for (let s = 1; s < e.length; s++) {
|
|
853
|
+
const o = e[s - 1], r = e[s];
|
|
854
|
+
if (r.gcToPrevious) {
|
|
855
|
+
const i = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng === r.lng && a.lat === r.lat);
|
|
856
|
+
for (let a = c - 1; a > i; a--)
|
|
857
|
+
t.splice(a, 1);
|
|
858
858
|
}
|
|
859
859
|
}
|
|
860
860
|
let n = 0;
|
|
861
|
-
for (let s = 1; s <
|
|
862
|
-
const o =
|
|
863
|
-
|
|
861
|
+
for (let s = 1; s < t.length; s++) {
|
|
862
|
+
const o = t[s - 1], r = t[s];
|
|
863
|
+
r.gcToPrevious ? (o.bearing = this.calculateBearing(o, r, !1), r.distanceFromPrevious = this.calculateDistance(o, r, !1)) : (o.bearing = this.calculateBearing(o, r, !0), r.distanceFromPrevious = this.calculateDistance(o, r, !0)), n = d.roundPrecision(n + r.distanceFromPrevious), r.distanceFromStart = n;
|
|
864
864
|
}
|
|
865
|
-
return
|
|
865
|
+
return t.map((s) => (s.lng = d.convertToStdLng(s.lng), s));
|
|
866
866
|
}
|
|
867
867
|
/**
|
|
868
868
|
* 计算轨迹中心点
|
|
869
869
|
* @param route
|
|
870
870
|
*/
|
|
871
|
-
static calculateCenter(
|
|
872
|
-
const
|
|
873
|
-
for (const
|
|
874
|
-
for (const c of
|
|
875
|
-
|
|
876
|
-
const n = T.featureCollection([]), s = d.convertToMonotonicLng2(
|
|
877
|
-
for (const
|
|
878
|
-
n.features.push(T.point(
|
|
879
|
-
const
|
|
880
|
-
return { lng: d.convertToStdLng(
|
|
871
|
+
static calculateCenter(t) {
|
|
872
|
+
const e = [];
|
|
873
|
+
for (const i of t)
|
|
874
|
+
for (const c of i)
|
|
875
|
+
e.push(c);
|
|
876
|
+
const n = T.featureCollection([]), s = d.convertToMonotonicLng2(e);
|
|
877
|
+
for (const i of s)
|
|
878
|
+
n.features.push(T.point(i));
|
|
879
|
+
const r = T.center(n).geometry.coordinates;
|
|
880
|
+
return { lng: d.convertToStdLng(r[0], 8), lat: d.roundPrecision(r[1], 8) };
|
|
881
881
|
}
|
|
882
882
|
/**
|
|
883
883
|
* 计算中心点
|
|
884
884
|
* @param coords
|
|
885
885
|
*/
|
|
886
|
-
static calculateCenter2(
|
|
887
|
-
const
|
|
888
|
-
return this.calculateCenter(
|
|
886
|
+
static calculateCenter2(t) {
|
|
887
|
+
const e = this.generateRouteAccordingToWaypoints(t);
|
|
888
|
+
return this.calculateCenter(e);
|
|
889
889
|
}
|
|
890
890
|
/**
|
|
891
891
|
* 计算BBox
|
|
892
892
|
* @param route
|
|
893
893
|
*/
|
|
894
|
-
static calculateBBox(
|
|
895
|
-
const
|
|
896
|
-
for (const o of
|
|
897
|
-
for (const
|
|
898
|
-
|
|
899
|
-
const n = d.convertToMonotonicLng2(
|
|
894
|
+
static calculateBBox(t) {
|
|
895
|
+
const e = [];
|
|
896
|
+
for (const o of t)
|
|
897
|
+
for (const r of o)
|
|
898
|
+
e.push(r);
|
|
899
|
+
const n = d.convertToMonotonicLng2(e), s = T.lineString(n);
|
|
900
900
|
return T.bbox(s);
|
|
901
901
|
}
|
|
902
902
|
/**
|
|
903
903
|
* 计算BBox
|
|
904
904
|
* @param coords
|
|
905
905
|
*/
|
|
906
|
-
static calculateBBox2(
|
|
907
|
-
const
|
|
908
|
-
return this.calculateBBox(
|
|
906
|
+
static calculateBBox2(t) {
|
|
907
|
+
const e = this.generateRouteAccordingToWaypoints(t);
|
|
908
|
+
return this.calculateBBox(e);
|
|
909
909
|
}
|
|
910
910
|
/**
|
|
911
911
|
* 抽稀 三点抽稀, 对比A,B,C; 基于三点距离及夹角抽稀
|
|
@@ -913,17 +913,17 @@ class v {
|
|
|
913
913
|
* @param distance 三点最小距离, 小于此距离时,B点将被忽略(三点太近)
|
|
914
914
|
* @param angle 三点夹角, 大于此角度时,B点将被忽略(近似走RL)
|
|
915
915
|
*/
|
|
916
|
-
static simplifyCoordinates(
|
|
916
|
+
static simplifyCoordinates(t, e = 1, n = 180) {
|
|
917
917
|
const s = [];
|
|
918
|
-
for (let o = 1; o <
|
|
919
|
-
const
|
|
918
|
+
for (let o = 1; o < t.length; o++) {
|
|
919
|
+
const r = t[o - 1], i = t[o], c = t[o + 1];
|
|
920
920
|
let a = !1, l = !1;
|
|
921
|
-
if ((
|
|
922
|
-
const u = v.calculateDistance(
|
|
923
|
-
Math.round(Math.acos(g) * 180 / Math.PI) < n && h >
|
|
921
|
+
if ((r.velocity || r.suspend || r.important || r.pilot || o === 1) && (a = !0, s.push(r)), i.gcToPrevious && (a || (a = !0, s.push(r)), l = !0, s.push(i), o++), c) {
|
|
922
|
+
const u = v.calculateDistance(r, i, !0), f = v.calculateDistance(i, c, !0), h = v.calculateDistance(r, c, !0), g = (Math.pow(u, 2) + Math.pow(f, 2) - Math.pow(h, 2)) / (2 * u * f);
|
|
923
|
+
Math.round(Math.acos(g) * 180 / Math.PI) < n && h > e && !l && (s.push(i), o++);
|
|
924
924
|
}
|
|
925
|
-
if (o >=
|
|
926
|
-
const u =
|
|
925
|
+
if (o >= t.length - 1) {
|
|
926
|
+
const u = t.at(-1);
|
|
927
927
|
u && s.push(u);
|
|
928
928
|
}
|
|
929
929
|
}
|
|
@@ -935,24 +935,24 @@ class v {
|
|
|
935
935
|
* @param step 时间步长, 前后n小时
|
|
936
936
|
* @param waypoints 带时间的轨迹, 单位秒
|
|
937
937
|
*/
|
|
938
|
-
static nearestTSPointInWaypoints(
|
|
939
|
-
const s = b.unix(
|
|
940
|
-
(
|
|
938
|
+
static nearestTSPointInWaypoints(t, e, n) {
|
|
939
|
+
const s = b.unix(t), o = n.filter(
|
|
940
|
+
(r) => s.clone().subtract(e, "hour").unix() <= (r.positionTime || 0) && s.clone().add(e, "h").unix() >= (r.positionTime || 0)
|
|
941
941
|
);
|
|
942
|
-
return o.sort((
|
|
942
|
+
return o.sort((r, i) => (r.positionTime || 0) - (i.positionTime || 0)), o.at(-1);
|
|
943
943
|
}
|
|
944
944
|
/**
|
|
945
945
|
* 推测船位
|
|
946
946
|
* @param ts 目标时间的船位,单位 s
|
|
947
947
|
* @param positions 带时间(positionTime)的轨迹
|
|
948
948
|
*/
|
|
949
|
-
static deadReckoning(
|
|
950
|
-
var o,
|
|
951
|
-
|
|
952
|
-
const n = b.unix(
|
|
953
|
-
let s =
|
|
949
|
+
static deadReckoning(t, e) {
|
|
950
|
+
var o, r, i, c;
|
|
951
|
+
t > 1e12 && (t = Math.round(t / 1e3));
|
|
952
|
+
const n = b.unix(t);
|
|
953
|
+
let s = e.find((a) => a.positionTime === n.unix());
|
|
954
954
|
if (!s) {
|
|
955
|
-
const a = (
|
|
955
|
+
const a = (r = (o = e.filter((u) => (u == null ? void 0 : u.positionTime) < n.unix())) == null ? void 0 : o.sort((u, f) => (u.positionTime || 0) - (f.positionTime || 0))) == null ? void 0 : r.at(-1), l = (c = (i = e.filter((u) => (u == null ? void 0 : u.positionTime) > n.unix())) == null ? void 0 : i.sort((u, f) => (u.positionTime || 0) - (f.positionTime || 0))) == null ? void 0 : c.at(0);
|
|
956
956
|
if (a && l) {
|
|
957
957
|
const u = v.calculateBearing(a, l, !0), f = v.calculateDistance(a, l), h = (n.unix() - a.positionTime) / (l.positionTime - a.positionTime);
|
|
958
958
|
s = v.calculateCoordinate(a, u, f * h), s.positionTime = n.unix(), s.utc = n.utc().format(), s.cog = u, s.sog = Math.round(f / ((l.positionTime - a.positionTime) / 3600) * 100) / 100;
|
|
@@ -966,47 +966,47 @@ class v {
|
|
|
966
966
|
* @param coordinate
|
|
967
967
|
* @param positions
|
|
968
968
|
*/
|
|
969
|
-
static deadReckoningTime(
|
|
970
|
-
|
|
969
|
+
static deadReckoningTime(t, e) {
|
|
970
|
+
e = JSON.parse(JSON.stringify(e)), e.sort((a, l) => (a.positionTime || 0) - (l.positionTime || 0));
|
|
971
971
|
let n = Number.MAX_SAFE_INTEGER, s = Number.MAX_SAFE_INTEGER;
|
|
972
|
-
for (let a = 0; a <
|
|
973
|
-
const l =
|
|
972
|
+
for (let a = 0; a < e.length - 1; a++) {
|
|
973
|
+
const l = e[a], u = e[a + 1], f = v.calculatePointToLineDistance(t, l, u);
|
|
974
974
|
f < n && (n = f, s = a);
|
|
975
975
|
}
|
|
976
|
-
const o =
|
|
977
|
-
if (
|
|
978
|
-
|
|
976
|
+
const o = e[s], r = e[s + 1], i = v.calculateDistance(o, t), c = v.calculateDistance(r, t);
|
|
977
|
+
if (i === 0)
|
|
978
|
+
t = o;
|
|
979
979
|
else if (c === 0)
|
|
980
|
-
|
|
980
|
+
t = r;
|
|
981
981
|
else {
|
|
982
|
-
const a = o.positionTime || 0, l =
|
|
983
|
-
|
|
982
|
+
const a = o.positionTime || 0, l = r.positionTime || 0, u = v.calculateDistance(o, r);
|
|
983
|
+
t.positionTime = Math.round(a + (l - a) * (i / u));
|
|
984
984
|
}
|
|
985
|
-
return
|
|
985
|
+
return t.utc = t.positionTime ? b.unix(t.positionTime).utc().format() : void 0, t.positionTime ? t : void 0;
|
|
986
986
|
}
|
|
987
987
|
/**
|
|
988
988
|
* 翻转轨迹
|
|
989
989
|
* @param route
|
|
990
990
|
*/
|
|
991
|
-
static reverseRoute(
|
|
992
|
-
const
|
|
993
|
-
for (const n of
|
|
994
|
-
|
|
995
|
-
return
|
|
991
|
+
static reverseRoute(t) {
|
|
992
|
+
const e = [];
|
|
993
|
+
for (const n of t)
|
|
994
|
+
e.push(n.reverse());
|
|
995
|
+
return e;
|
|
996
996
|
}
|
|
997
997
|
/**
|
|
998
998
|
* 翻转坐标
|
|
999
999
|
* @param coordinates
|
|
1000
1000
|
*/
|
|
1001
|
-
static reverseCoordinates(
|
|
1002
|
-
return
|
|
1001
|
+
static reverseCoordinates(t) {
|
|
1002
|
+
return t.reverse();
|
|
1003
1003
|
}
|
|
1004
1004
|
/**
|
|
1005
1005
|
* XML转义
|
|
1006
1006
|
* @param s
|
|
1007
1007
|
*/
|
|
1008
|
-
static xmlEscape(
|
|
1009
|
-
return
|
|
1008
|
+
static xmlEscape(t) {
|
|
1009
|
+
return t == null ? "" : String(t).trim().replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1010
1010
|
}
|
|
1011
1011
|
/**
|
|
1012
1012
|
* 路径转RTZ 1.2
|
|
@@ -1016,9 +1016,9 @@ class v {
|
|
|
1016
1016
|
* @see https://cirm.org/api/documents/download/64?documents/October2022/bWjrTyyfNGseK9ch3TKf.xsd
|
|
1017
1017
|
*
|
|
1018
1018
|
*/
|
|
1019
|
-
static waypoints2RTZ(
|
|
1019
|
+
static waypoints2RTZ(t, e) {
|
|
1020
1020
|
const s = [];
|
|
1021
|
-
return s.push('<?xml version="1.0" encoding="UTF-8"?>'), s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), s.push(` <routeInfo routeName="${v.xmlEscape(
|
|
1021
|
+
return s.push('<?xml version="1.0" encoding="UTF-8"?>'), s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'), s.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), s.push(...v.toRTZWaypoints(e, 6)), s.push("</route>"), s.join(`
|
|
1022
1022
|
`);
|
|
1023
1023
|
}
|
|
1024
1024
|
/**
|
|
@@ -1027,30 +1027,30 @@ class v {
|
|
|
1027
1027
|
* @param waypoints 途径点
|
|
1028
1028
|
* @see https://cirm.org/rtz-xml-schemas
|
|
1029
1029
|
*/
|
|
1030
|
-
static waypoints2RTZ10(
|
|
1030
|
+
static waypoints2RTZ10(t, e, n = !0) {
|
|
1031
1031
|
const o = [];
|
|
1032
|
-
return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${v.xmlEscape(
|
|
1032
|
+
return o.push('<?xml version="1.0" encoding="UTF-8"?>'), o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'), o.push(` <routeInfo routeName="${v.xmlEscape(t)}"></routeInfo>`), o.push(...v.toRTZWaypoints(e, 6, n)), o.push("</route>"), o.join(`
|
|
1033
1033
|
`);
|
|
1034
1034
|
}
|
|
1035
|
-
static toRTZWaypoints(
|
|
1035
|
+
static toRTZWaypoints(t, e = 6, n = !0) {
|
|
1036
1036
|
const s = [];
|
|
1037
1037
|
s.push(" <waypoints>");
|
|
1038
|
-
for (let o = 0; o <
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
const u =
|
|
1038
|
+
for (let o = 0; o < t.length; o++) {
|
|
1039
|
+
const r = t[o], i = o + 1, c = (r.lat ?? "").toFixed ? r.lat.toFixed(e).padEnd(e + 2, "0") : r.lat, a = (r.lng ?? "").toFixed ? r.lng.toFixed(e).padEnd(e + 2, "0") : r.lng, l = [`id="${i}"`, 'revision="0"'];
|
|
1040
|
+
if (r.name && l.push(`name="${v.xmlEscape(r.name)}"`), s.push(` <waypoint ${l.join(" ")}>`), s.push(` <position lat="${v.xmlEscape(c)}" lon="${v.xmlEscape(a)}" />`), o > 0) {
|
|
1041
|
+
const u = r.gcToPrevious ? "Orthodrome" : "Loxodrome";
|
|
1042
1042
|
s.push(` <leg geometryType="${u}" />`);
|
|
1043
1043
|
}
|
|
1044
1044
|
if (n) {
|
|
1045
1045
|
const u = [];
|
|
1046
|
-
if (
|
|
1047
|
-
u.push(` <time>${v.xmlEscape(
|
|
1048
|
-
else if (
|
|
1046
|
+
if (r.description && u.push(` <description>${v.xmlEscape(r.description)}</description>`), r.utc)
|
|
1047
|
+
u.push(` <time>${v.xmlEscape(r.utc)}</time>`);
|
|
1048
|
+
else if (r.positionTime)
|
|
1049
1049
|
try {
|
|
1050
|
-
u.push(` <time>${v.xmlEscape(b.unix(
|
|
1050
|
+
u.push(` <time>${v.xmlEscape(b.unix(r.positionTime).utc().format())}</time>`);
|
|
1051
1051
|
} catch {
|
|
1052
1052
|
}
|
|
1053
|
-
|
|
1053
|
+
r.cog !== void 0 && u.push(` <cog>${v.xmlEscape(r.cog)}</cog>`), r.sog !== void 0 && u.push(` <sog>${v.xmlEscape(r.sog)}</sog>`), u.length && (s.push(" <extensions>"), s.push(...u), s.push(" </extensions>"));
|
|
1054
1054
|
}
|
|
1055
1055
|
s.push(" </waypoint>");
|
|
1056
1056
|
}
|
|
@@ -1063,15 +1063,15 @@ class v {
|
|
|
1063
1063
|
* @param waypoints 途径点
|
|
1064
1064
|
* @param options.precision 经纬度小数位数,默认6
|
|
1065
1065
|
*/
|
|
1066
|
-
static waypoints2CSV(
|
|
1067
|
-
X.debug("keep name for waypoints2CSV for legacy compatibility only",
|
|
1068
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, o =
|
|
1069
|
-
o && g.push("Name"),
|
|
1066
|
+
static waypoints2CSV(t, e, n) {
|
|
1067
|
+
X.debug("keep name for waypoints2CSV for legacy compatibility only", t);
|
|
1068
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, o = e.some((p) => p.name), r = e.some((p) => p.description), i = e.some((p) => p.port != null), c = e.some((p) => p.stbd != null), a = e.some((p) => p.arrRad != null), l = e.some((p) => p.speed != null), u = e.some((p, S) => S > 0 && p.gcToPrevious != null), f = e.some((p) => p.bearing != null), h = e.some((p) => p.distanceFromPrevious != null), g = ["WPT No.", "Latitude", "Longitude"];
|
|
1069
|
+
o && g.push("Name"), r && g.push("Description"), u && g.push("Leg"), f && g.push("Bearing[deg]"), h && g.push("Distance[NM]"), l && g.push("Speed[kn]"), i && g.push("PORT XTD[NM]"), c && g.push("STBD XTD[NM]"), a && g.push("Arr.Rad[NM]");
|
|
1070
1070
|
const m = [];
|
|
1071
1071
|
m.push(g.map((p) => v.csvEscapeField(p)).join(","));
|
|
1072
|
-
for (let p = 0; p <
|
|
1073
|
-
const S =
|
|
1074
|
-
x.push((p + 1).toString()), x.push(S.lat.toFixed(s)), x.push(S.lng.toFixed(s)), o && x.push(S.name ?? ""),
|
|
1072
|
+
for (let p = 0; p < e.length; p++) {
|
|
1073
|
+
const S = e[p], x = [];
|
|
1074
|
+
x.push((p + 1).toString()), x.push(S.lat.toFixed(s)), x.push(S.lng.toFixed(s)), o && x.push(S.name ?? ""), r && x.push(S.description ?? ""), u && x.push(p === 0 ? "" : S.gcToPrevious ? "GC" : "RL"), f && x.push(S.bearing != null ? String(S.bearing) : ""), h && x.push(S.distanceFromPrevious != null ? String(S.distanceFromPrevious) : ""), l && x.push(S.speed != null ? String(S.speed) : ""), i && x.push(S.port != null ? String(S.port) : ""), c && x.push(S.stbd != null ? String(S.stbd) : ""), a && x.push(S.arrRad != null ? String(S.arrRad) : ""), m.push(x.map((M) => v.csvEscapeField(M)).join(","));
|
|
1075
1075
|
}
|
|
1076
1076
|
return m.join(`
|
|
1077
1077
|
`);
|
|
@@ -1087,20 +1087,20 @@ class v {
|
|
|
1087
1087
|
* @param options.precision 经纬度小数位数,默认6
|
|
1088
1088
|
* @returns Uint8Array 二进制数据,可直接用于 new Blob([result], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
|
|
1089
1089
|
*/
|
|
1090
|
-
static waypoints2XLSX(
|
|
1091
|
-
const s = (n == null ? void 0 : n.precision) ?? 6, o =
|
|
1092
|
-
|
|
1090
|
+
static waypoints2XLSX(t, e, n) {
|
|
1091
|
+
const s = (n == null ? void 0 : n.precision) ?? 6, o = t || "Route", r = e.some((P) => P.name), i = e.some((P) => P.description), c = e.some((P) => P.port != null), a = e.some((P) => P.stbd != null), l = e.some((P) => P.arrRad != null), u = e.some((P) => P.speed != null), f = e.some((P, I) => I > 0 && P.gcToPrevious != null), h = e.some((P) => P.bearing != null), g = e.some((P) => P.distanceFromPrevious != null), m = ["WPT No.", "Latitude", "Longitude"];
|
|
1092
|
+
r && m.push("Name"), i && m.push("Description"), f && m.push("Leg"), h && m.push("Bearing[deg]"), g && m.push("Distance[NM]"), u && m.push("Speed[kn]"), c && m.push("PORT XTD[NM]"), a && m.push("STBD XTD[NM]"), l && m.push("Arr.Rad[NM]");
|
|
1093
1093
|
const p = (P) => P == null ? "" : String(P).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1094
1094
|
let x = `<row r="1">${m.map((P, I) => `<c r="${z(I)}1" s="1" t="inlineStr"><is><t>${p(P)}</t></is></c>`).join("")}</row>`;
|
|
1095
|
-
for (let P = 0; P <
|
|
1096
|
-
const I =
|
|
1095
|
+
for (let P = 0; P < e.length; P++) {
|
|
1096
|
+
const I = e[P], E = P + 2, B = [], Z = (W, j) => B.push(`<c r="${z(W)}${E}"><v>${j}</v></c>`), A = (W, j) => B.push(`<c r="${z(W)}${E}" t="inlineStr"><is><t>${p(j)}</t></is></c>`), k = (W, j) => {
|
|
1097
1097
|
j != null ? Z(W, j) : A(W, "");
|
|
1098
1098
|
};
|
|
1099
1099
|
Z(0, P + 1), A(1, d.lat2pretty(I.lat, s).pretty), A(2, d.lng2pretty(I.lng, s).pretty);
|
|
1100
1100
|
let D = 3;
|
|
1101
|
-
|
|
1101
|
+
r && (A(D, I.name ?? ""), D++), i && (A(D, I.description ?? ""), D++), f && (A(D, P === 0 ? "" : I.gcToPrevious ? "GC" : "RL"), D++), h && (k(D, I.bearing), D++), g && (k(D, I.distanceFromPrevious), D++), u && (k(D, I.speed), D++), c && (k(D, I.port), D++), a && (k(D, I.stbd), D++), l && (k(D, I.arrRad), D++), x += `<row r="${E}">${B.join("")}</row>`;
|
|
1102
1102
|
}
|
|
1103
|
-
const M = "0." + "0".repeat(s), y = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>' + x + "</sheetData></worksheet>", N = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>', w = '<?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>', q = '<?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="' + p(o) + '" sheetId="1" r:id="rId1"/></sheets></workbook>', U = '<?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>', L = '<?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="' + M + '"/></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="
|
|
1103
|
+
const M = "0." + "0".repeat(s), y = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>' + x + "</sheetData></worksheet>", N = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>', w = '<?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>', q = '<?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="' + p(o) + '" sheetId="1" r:id="rId1"/></sheets></workbook>', U = '<?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>', L = '<?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="' + M + '"/></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>', O = new TextEncoder();
|
|
1104
1104
|
return _([
|
|
1105
1105
|
{ name: "[Content_Types].xml", data: O.encode(N) },
|
|
1106
1106
|
{ name: "_rels/.rels", data: O.encode(w) },
|
|
@@ -1113,44 +1113,44 @@ class v {
|
|
|
1113
1113
|
/**
|
|
1114
1114
|
* RFC 4180 CSV字段转义:含逗号、双引号、换行时用双引号包裹,内部双引号翻倍
|
|
1115
1115
|
*/
|
|
1116
|
-
static csvEscapeField(
|
|
1117
|
-
if (
|
|
1116
|
+
static csvEscapeField(t) {
|
|
1117
|
+
if (t == null)
|
|
1118
1118
|
return "";
|
|
1119
|
-
const
|
|
1120
|
-
return
|
|
1121
|
-
`) ||
|
|
1119
|
+
const e = String(t);
|
|
1120
|
+
return e.includes(",") || e.includes('"') || e.includes(`
|
|
1121
|
+
`) || e.includes("\r") ? `"${e.replace(/"/g, '""')}"` : e;
|
|
1122
1122
|
}
|
|
1123
1123
|
/**
|
|
1124
1124
|
* 十进制度数转NMEA度分格式 (DDMM.MM / DDDMM.MM)
|
|
1125
1125
|
* @param value 十进制度数
|
|
1126
1126
|
* @param isLat true为纬度,false为经度
|
|
1127
1127
|
*/
|
|
1128
|
-
static decimalToNmeaDm(
|
|
1129
|
-
const n = Math.abs(
|
|
1130
|
-
return { dm:
|
|
1128
|
+
static decimalToNmeaDm(t, e) {
|
|
1129
|
+
const n = Math.abs(t), s = Math.floor(n), o = (n - s) * 60, r = e ? `${s.toString().padStart(2, "0")}${o.toFixed(2).padStart(5, "0")}` : `${s.toString().padStart(3, "0")}${o.toFixed(2).padStart(5, "0")}`, i = e ? t >= 0 ? "N" : "S" : t >= 0 ? "E" : "W";
|
|
1130
|
+
return { dm: r, dir: i };
|
|
1131
1131
|
}
|
|
1132
1132
|
/**
|
|
1133
1133
|
* 计算NMEA 0183校验和 ($与*之间所有字符的异或,两字符十六进制大写)
|
|
1134
1134
|
* @param sentence $与*之间的字符串
|
|
1135
1135
|
*/
|
|
1136
|
-
static nmeaChecksum(
|
|
1137
|
-
let
|
|
1138
|
-
for (let n = 0; n <
|
|
1139
|
-
|
|
1140
|
-
return
|
|
1136
|
+
static nmeaChecksum(t) {
|
|
1137
|
+
let e = 0;
|
|
1138
|
+
for (let n = 0; n < t.length; n++)
|
|
1139
|
+
e ^= t.charCodeAt(n);
|
|
1140
|
+
return e.toString(16).toUpperCase().padStart(2, "0");
|
|
1141
1141
|
}
|
|
1142
1142
|
/**
|
|
1143
1143
|
* 路径转NMEA 0183 WPL航点语句
|
|
1144
1144
|
* @param waypoints 途径点
|
|
1145
1145
|
* @returns 多条$GPWPL语句,以\r\n分隔
|
|
1146
1146
|
*/
|
|
1147
|
-
static waypoints2NMEA(
|
|
1148
|
-
const
|
|
1149
|
-
for (let n = 0; n <
|
|
1150
|
-
const s =
|
|
1151
|
-
|
|
1147
|
+
static waypoints2NMEA(t) {
|
|
1148
|
+
const e = [];
|
|
1149
|
+
for (let n = 0; n < t.length; n++) {
|
|
1150
|
+
const s = t[n], o = v.decimalToNmeaDm(s.lat, !0), r = v.decimalToNmeaDm(s.lng, !1), i = s.name ? String(s.name).slice(0, 6) : `WPT${(n + 1).toString().padStart(3, "0")}`, c = `GPWPL,${o.dm},${o.dir},${r.dm},${r.dir},${i}`, a = v.nmeaChecksum(c);
|
|
1151
|
+
e.push(`$${c}*${a}`);
|
|
1152
1152
|
}
|
|
1153
|
-
return
|
|
1153
|
+
return e.join(`\r
|
|
1154
1154
|
`);
|
|
1155
1155
|
}
|
|
1156
1156
|
/**
|
|
@@ -1165,19 +1165,19 @@ class v {
|
|
|
1165
1165
|
* avgSpeed: number // 平均航速,单位节
|
|
1166
1166
|
* }
|
|
1167
1167
|
*/
|
|
1168
|
-
static coordinatesSummary(
|
|
1169
|
-
if (
|
|
1170
|
-
const n =
|
|
1168
|
+
static coordinatesSummary(t, e = 3) {
|
|
1169
|
+
if (t.length > 1) {
|
|
1170
|
+
const n = t[0], s = t[t.length - 1], o = (n == null ? void 0 : n.positionTime) < (s == null ? void 0 : s.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(s == null ? void 0 : s.positionTime), r = (n == null ? void 0 : n.positionTime) > (s == null ? void 0 : s.positionTime) ? b.unix(n == null ? void 0 : n.positionTime) : b.unix(s == null ? void 0 : s.positionTime), i = Math.round(r.diff(o, "hours", !0) * 100) / 100, c = this.generateRouteAccordingToWaypoints(t, !0, !0), a = this.calculateRouteDistance(c), u = K.inspectStoppages(t, e).reduce(
|
|
1171
1171
|
(h, g) => (h.duration += g.duration, h.distance += g.distance, h),
|
|
1172
1172
|
{ hours: 0, distance: 0, spd: 0, duration: 0 }
|
|
1173
1173
|
);
|
|
1174
1174
|
u.hours = Math.round(u.duration / 3600 * 100) / 100, u.distance = Math.round(u.distance * 100) / 100, u.spd = u.hours ? Math.round(u.distance / u.hours * 100) / 100 : 0;
|
|
1175
|
-
const f =
|
|
1175
|
+
const f = i ? Math.round((a - u.distance) / (i - u.hours) * 100) / 100 : 0;
|
|
1176
1176
|
return {
|
|
1177
1177
|
begin: o.utc().format(),
|
|
1178
|
-
end:
|
|
1178
|
+
end: r.utc().format(),
|
|
1179
1179
|
distance: Math.round((a - u.distance) * 100) / 100,
|
|
1180
|
-
hours: Math.round((
|
|
1180
|
+
hours: Math.round((i - u.hours) * 100) / 100,
|
|
1181
1181
|
avgSpeed: f,
|
|
1182
1182
|
stoppage: u
|
|
1183
1183
|
};
|
|
@@ -1199,18 +1199,18 @@ class v {
|
|
|
1199
1199
|
* hour: Coordinate
|
|
1200
1200
|
* }
|
|
1201
1201
|
*/
|
|
1202
|
-
static pickUTCSampleFromSpeed(
|
|
1202
|
+
static pickUTCSampleFromSpeed(t, e) {
|
|
1203
1203
|
var l, u, f;
|
|
1204
|
-
if (!((u = (l =
|
|
1204
|
+
if (!((u = (l = e == null ? void 0 : e.sample) == null ? void 0 : l.hours) != null && u.length))
|
|
1205
1205
|
return { routes: [], hour: void 0 };
|
|
1206
|
-
const n =
|
|
1207
|
-
let
|
|
1208
|
-
if (!
|
|
1209
|
-
const h =
|
|
1210
|
-
|
|
1211
|
-
const { cFactor: m, cog: p, wxFactor: S, meteo: x } = h, M = Math.round(
|
|
1212
|
-
|
|
1213
|
-
...
|
|
1206
|
+
const n = e.sample.hours.at(0), s = b.utc(t), o = b.utc(e.eta), r = s.isAfter(o) ? o : s;
|
|
1207
|
+
let i = e.sample.all.find((h) => h.eta === r.format());
|
|
1208
|
+
if (!i) {
|
|
1209
|
+
const h = e.sample.all.filter((N) => b.utc(N.eta).isBefore(r)).at(-1), g = this.calculateSubRoute(h, e.route);
|
|
1210
|
+
i = (f = this.calculateNextCoordinateAlongRoute(h, h.speed * r.diff(b(h.etd), "hours", !0), g)) == null ? void 0 : f.coordinate;
|
|
1211
|
+
const { cFactor: m, cog: p, wxFactor: S, meteo: x } = h, M = Math.round(i.distanceFromPrevious * 1e4) / 1e4, y = Math.round((M + h.distanceFromStart) * 1e4) / 1e4;
|
|
1212
|
+
i = {
|
|
1213
|
+
...i,
|
|
1214
1214
|
cFactor: m,
|
|
1215
1215
|
cog: p,
|
|
1216
1216
|
speed: h.speed,
|
|
@@ -1218,15 +1218,15 @@ class v {
|
|
|
1218
1218
|
distanceFromStart: y,
|
|
1219
1219
|
distanceFromPrevious: M,
|
|
1220
1220
|
meteo: x,
|
|
1221
|
-
eta:
|
|
1222
|
-
etd:
|
|
1221
|
+
eta: r.format(),
|
|
1222
|
+
etd: r.format()
|
|
1223
1223
|
};
|
|
1224
1224
|
}
|
|
1225
|
-
|
|
1226
|
-
const c = this.calculateRangeWaypoints(n,
|
|
1225
|
+
i.distanceToGo = Math.round((e.distance - i.distanceFromStart) * 100) / 100, i.timeToGo = Math.round(o.diff(i.etd, "hours", !0) * 100) / 100;
|
|
1226
|
+
const c = this.calculateRangeWaypoints(n, i, e.route);
|
|
1227
1227
|
return {
|
|
1228
1228
|
routes: this.generateRouteAccordingToWaypoints(c),
|
|
1229
|
-
hour:
|
|
1229
|
+
hour: i
|
|
1230
1230
|
};
|
|
1231
1231
|
}
|
|
1232
1232
|
/**
|
|
@@ -1239,13 +1239,13 @@ class v {
|
|
|
1239
1239
|
* hour: Coordinate
|
|
1240
1240
|
* }
|
|
1241
1241
|
*/
|
|
1242
|
-
static pickUTCSampleFromRoute(
|
|
1242
|
+
static pickUTCSampleFromRoute(t, e, n) {
|
|
1243
1243
|
var h;
|
|
1244
|
-
const s = this.calculateSubRoute(
|
|
1245
|
-
a.speed =
|
|
1244
|
+
const s = this.calculateSubRoute(e, n), o = this.calculateRouteDistance(s), r = o / e.speed, i = b.utc(t), c = b(e.etd), a = (h = this.calculateNextCoordinateAlongRoute(e, e.speed * i.diff(b(e.etd), "hours", !0), s)) == null ? void 0 : h.coordinate;
|
|
1245
|
+
a.speed = e.speed;
|
|
1246
1246
|
const l = c.clone().add(a.hourFromPrevious, "hour");
|
|
1247
|
-
a.eta = Math.abs(l.diff(
|
|
1248
|
-
const u = this.calculateRangeWaypoints(
|
|
1247
|
+
a.eta = Math.abs(l.diff(i, "second")) < 2 ? i.format() : l.format(), a.etd = a.eta, a.distanceFromStart = Math.round(a.distanceFromPrevious * 100) / 100, a.distanceToGo = Math.round((o - a.distanceFromStart) * 100) / 100, a.timeToGo = Math.round(c.clone().add(r, "hour").diff(b(a.etd), "hour") * 100) / 100;
|
|
1248
|
+
const u = this.calculateRangeWaypoints(e, a, n);
|
|
1249
1249
|
return {
|
|
1250
1250
|
routes: this.generateRouteAccordingToWaypoints(u),
|
|
1251
1251
|
hour: a
|
|
@@ -1256,9 +1256,9 @@ class v {
|
|
|
1256
1256
|
* @param bearing 航首向
|
|
1257
1257
|
* @param degree 要素角度,如 swell.degree
|
|
1258
1258
|
*/
|
|
1259
|
-
static includedAngle(
|
|
1260
|
-
X == null || X.debug("calculate bearing via: %j", { bearing:
|
|
1261
|
-
let n = Math.abs(
|
|
1259
|
+
static includedAngle(t, e) {
|
|
1260
|
+
X == null || X.debug("calculate bearing via: %j", { bearing: t, degree: e });
|
|
1261
|
+
let n = Math.abs(t % 360 - (e % 360 || 0));
|
|
1262
1262
|
return n = n > 180 ? 360 - n : n, n;
|
|
1263
1263
|
}
|
|
1264
1264
|
}
|
|
@@ -1268,28 +1268,28 @@ try {
|
|
|
1268
1268
|
} catch {
|
|
1269
1269
|
} finally {
|
|
1270
1270
|
}
|
|
1271
|
-
class
|
|
1271
|
+
class it {
|
|
1272
1272
|
/**
|
|
1273
1273
|
* 将原始数据转换为geojson
|
|
1274
1274
|
* @param raw
|
|
1275
1275
|
*/
|
|
1276
|
-
static convert2Geojson(
|
|
1276
|
+
static convert2Geojson(t) {
|
|
1277
1277
|
var n, s, o;
|
|
1278
|
-
const
|
|
1279
|
-
for (const
|
|
1280
|
-
const
|
|
1281
|
-
if (
|
|
1282
|
-
|
|
1283
|
-
for (const c of
|
|
1278
|
+
const e = T.featureCollection([]);
|
|
1279
|
+
for (const r of t) {
|
|
1280
|
+
const i = (n = r.history) == null ? void 0 : n[0];
|
|
1281
|
+
if (r.forecasts) {
|
|
1282
|
+
i && i.wind && (i.wind.kts = i.kts);
|
|
1283
|
+
for (const c of r.forecasts) {
|
|
1284
1284
|
let a;
|
|
1285
|
-
const l = [], u = [], f = b(c.date).utc(), h = `${
|
|
1285
|
+
const l = [], u = [], f = b(c.date).utc(), h = `${r.name}-${c.model}`;
|
|
1286
1286
|
for (const m in c == null ? void 0 : c.hours) {
|
|
1287
1287
|
const p = c.hours[m];
|
|
1288
1288
|
a = a || p;
|
|
1289
1289
|
const S = f.clone().add(Number(m), "hour"), x = T.point([p.lng, p.lat], {
|
|
1290
1290
|
model: c.model,
|
|
1291
|
-
name:
|
|
1292
|
-
nameCn:
|
|
1291
|
+
name: r.name,
|
|
1292
|
+
nameCn: r.nameCn,
|
|
1293
1293
|
date: S.format(),
|
|
1294
1294
|
hour: Number(m),
|
|
1295
1295
|
format: S.format("MMM-DD/HHmm[Z]"),
|
|
@@ -1306,21 +1306,21 @@ class re {
|
|
|
1306
1306
|
kts: void 0,
|
|
1307
1307
|
deg: void 0
|
|
1308
1308
|
};
|
|
1309
|
-
if (
|
|
1310
|
-
const m = b(
|
|
1309
|
+
if (i) {
|
|
1310
|
+
const m = b(i.updated).utc();
|
|
1311
1311
|
if (a) {
|
|
1312
|
-
const S = v.calculateDistance(
|
|
1313
|
-
g.kts = Math.round(S / x * 100) / 100, g.deg = v.calculateBearing(
|
|
1312
|
+
const S = v.calculateDistance(i, a), x = b(a.utc || a.updated).diff(m, "h", !0);
|
|
1313
|
+
g.kts = Math.round(S / x * 100) / 100, g.deg = v.calculateBearing(i, a, !0, 0);
|
|
1314
1314
|
}
|
|
1315
|
-
const p = T.point([
|
|
1315
|
+
const p = T.point([i.lng, i.lat], {
|
|
1316
1316
|
model: c.model,
|
|
1317
|
-
name:
|
|
1318
|
-
nameCn:
|
|
1317
|
+
name: r.name,
|
|
1318
|
+
nameCn: r.nameCn,
|
|
1319
1319
|
date: m.format(),
|
|
1320
1320
|
hour: 0,
|
|
1321
1321
|
format: m.format("MMM-DD/HHmm[Z]"),
|
|
1322
|
-
pressure:
|
|
1323
|
-
wind:
|
|
1322
|
+
pressure: i.pressure > 1e4 ? d.roundPrecision((i == null ? void 0 : i.pressure) / 100, 0) : d.roundPrecision(i.pressure, 0),
|
|
1323
|
+
wind: i.wind,
|
|
1324
1324
|
movement: g,
|
|
1325
1325
|
category: h,
|
|
1326
1326
|
type: "forecast",
|
|
@@ -1329,74 +1329,74 @@ class re {
|
|
|
1329
1329
|
});
|
|
1330
1330
|
u.unshift(p), l.unshift(p.geometry.coordinates);
|
|
1331
1331
|
}
|
|
1332
|
-
if (
|
|
1332
|
+
if (e.features.push(...u), (l == null ? void 0 : l.length) > 1) {
|
|
1333
1333
|
const m = T.lineString(d.convertToMonotonicLng2(l), {
|
|
1334
|
-
date: (
|
|
1335
|
-
id:
|
|
1334
|
+
date: (i == null ? void 0 : i.updated) || (f == null ? void 0 : f.format()),
|
|
1335
|
+
id: r.id || r.name,
|
|
1336
1336
|
model: c.model,
|
|
1337
|
-
name:
|
|
1337
|
+
name: r.name,
|
|
1338
1338
|
category: h,
|
|
1339
1339
|
type: "forecast",
|
|
1340
1340
|
movement: g
|
|
1341
1341
|
});
|
|
1342
|
-
|
|
1342
|
+
e.features.push(m);
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
1345
|
}
|
|
1346
|
-
if (
|
|
1347
|
-
const c = [], a = b(
|
|
1348
|
-
for (const f of
|
|
1346
|
+
if (e.features.sort((c, a) => c.properties.type === "forecast" && a.properties.type === "forecast" && c.geometry.type === "Point" && a.geometry.type === "Point" ? b(c.properties.date).valueOf() - b(a.properties.date).valueOf() : 0), (s = r.history) != null && s.length) {
|
|
1347
|
+
const c = [], a = b(i == null ? void 0 : i.updated).utc(), l = b((o = r.history) == null ? void 0 : o.at(-1).updated).utc(), u = a.diff(l, "h") % 24 > 2 ? 24 : 12;
|
|
1348
|
+
for (const f of r.history) {
|
|
1349
1349
|
const h = b(f.updated).utc(), g = h.isSameOrBefore(a) || h.isSame(l);
|
|
1350
1350
|
g && a.add(-u, "h");
|
|
1351
1351
|
const m = T.point([f.lng, f.lat], {
|
|
1352
|
-
name:
|
|
1353
|
-
nameCn:
|
|
1352
|
+
name: r.name,
|
|
1353
|
+
nameCn: r.nameCn,
|
|
1354
1354
|
date: h.format(),
|
|
1355
1355
|
format: h.format("MMM-DD/HHmm[Z]"),
|
|
1356
1356
|
pressure: f.pressure > 1e4 ? d.roundPrecision(f.pressure / 100, 0) : d.roundPrecision(f.pressure, 0),
|
|
1357
1357
|
kts: f.kts,
|
|
1358
1358
|
level: f.type,
|
|
1359
1359
|
type: "history",
|
|
1360
|
-
category: `${
|
|
1360
|
+
category: `${r.name}-history`,
|
|
1361
1361
|
wind: f.wind,
|
|
1362
1362
|
movement: f.movement,
|
|
1363
1363
|
important: g
|
|
1364
1364
|
});
|
|
1365
|
-
|
|
1365
|
+
e.features.push(m), c.push(m.geometry.coordinates);
|
|
1366
1366
|
}
|
|
1367
1367
|
if (c.length === 1 && c.push(c[0]), c.length > 1) {
|
|
1368
1368
|
const f = T.lineString(d.convertToMonotonicLng2(c), {
|
|
1369
|
-
name:
|
|
1369
|
+
name: r.name,
|
|
1370
1370
|
type: "history",
|
|
1371
|
-
updated:
|
|
1372
|
-
pressure: (
|
|
1373
|
-
kts:
|
|
1374
|
-
level:
|
|
1371
|
+
updated: i == null ? void 0 : i.updated,
|
|
1372
|
+
pressure: (i == null ? void 0 : i.pressure) > 1e4 ? d.roundPrecision((i == null ? void 0 : i.pressure) / 100, 0) : d.roundPrecision(i == null ? void 0 : i.pressure, 0),
|
|
1373
|
+
kts: i == null ? void 0 : i.kts,
|
|
1374
|
+
level: i == null ? void 0 : i.type
|
|
1375
1375
|
});
|
|
1376
|
-
|
|
1376
|
+
e.features.push(f);
|
|
1377
1377
|
}
|
|
1378
1378
|
}
|
|
1379
1379
|
}
|
|
1380
|
-
return
|
|
1380
|
+
return e;
|
|
1381
1381
|
}
|
|
1382
1382
|
/**
|
|
1383
1383
|
* 插值台风预报轨迹
|
|
1384
1384
|
* @param tropicals
|
|
1385
1385
|
* @param step
|
|
1386
1386
|
*/
|
|
1387
|
-
static interpolate(
|
|
1388
|
-
var o,
|
|
1389
|
-
const n = (o =
|
|
1387
|
+
static interpolate(t, e = 3) {
|
|
1388
|
+
var o, r, i, c;
|
|
1389
|
+
const n = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
|
|
1390
1390
|
for (const a of n) {
|
|
1391
1391
|
const l = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = a.properties.disabled, g = b(a.properties.date).utc();
|
|
1392
|
-
let m =
|
|
1393
|
-
const p = (
|
|
1392
|
+
let m = e * 60;
|
|
1393
|
+
const p = (r = t == null ? void 0 : t.data) == null ? void 0 : r.features.filter(
|
|
1394
1394
|
(M) => M.geometry.type === "Point" && M.properties.type === "forecast" && M.properties.category === `${l}-${u}`
|
|
1395
1395
|
);
|
|
1396
1396
|
let S, x = g.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1397
1397
|
for (; S = this.pickIndex(p, x), S <= p.length - 1; ) {
|
|
1398
1398
|
if (S > 0) {
|
|
1399
|
-
const M = p[S], y = S === 0 ? void 0 : p[S - 1], N = (m / 60 - ((
|
|
1399
|
+
const M = p[S], y = S === 0 ? void 0 : p[S - 1], N = (m / 60 - ((i = y == null ? void 0 : y.properties) == null ? void 0 : i.hour)) / (M.properties.hour - ((c = y == null ? void 0 : y.properties) == null ? void 0 : c.hour)), w = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[0], M.geometry.coordinates[0], N), q = this.computeNumber(y == null ? void 0 : y.geometry.coordinates[1], M.geometry.coordinates[1], N), U = T.point([w, q], {
|
|
1400
1400
|
name: l,
|
|
1401
1401
|
model: u,
|
|
1402
1402
|
category: M == null ? void 0 : M.properties.category,
|
|
@@ -1413,7 +1413,7 @@ class re {
|
|
|
1413
1413
|
});
|
|
1414
1414
|
s.push(U);
|
|
1415
1415
|
}
|
|
1416
|
-
m +=
|
|
1416
|
+
m += e * 60, x = g.clone().add(m, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
1417
1417
|
}
|
|
1418
1418
|
}
|
|
1419
1419
|
return s;
|
|
@@ -1424,9 +1424,9 @@ class re {
|
|
|
1424
1424
|
* @param tropical 台风数据 { history: any[], forecasts: any[] }
|
|
1425
1425
|
* @param options
|
|
1426
1426
|
*/
|
|
1427
|
-
static accelPassageAt(
|
|
1428
|
-
const { t1: n, t2: s, hr: o, hours:
|
|
1429
|
-
return { t1: n, t2: s, hr: o, hours:
|
|
1427
|
+
static accelPassageAt(t, e) {
|
|
1428
|
+
const { t1: n, t2: s, hr: o, hours: r } = this.tropicalCenterTwin(t, 24, e);
|
|
1429
|
+
return { t1: n, t2: s, hr: o, hours: r };
|
|
1430
1430
|
}
|
|
1431
1431
|
/**
|
|
1432
1432
|
* 计算最佳绕航点
|
|
@@ -1439,32 +1439,32 @@ class re {
|
|
|
1439
1439
|
* @param speed 前进速度
|
|
1440
1440
|
* @param options
|
|
1441
1441
|
*/
|
|
1442
|
-
static diversionPassageAt(
|
|
1443
|
-
const { t1: o, t2:
|
|
1444
|
-
if (o &&
|
|
1442
|
+
static diversionPassageAt(t, e, n, s = {}) {
|
|
1443
|
+
const { t1: o, t2: r, hr: i, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
1444
|
+
if (o && r) {
|
|
1445
1445
|
if (!s.debug) {
|
|
1446
|
-
const g = v.calculateDistance(
|
|
1446
|
+
const g = v.calculateDistance(t, o), m = v.calculateDistance(t, r);
|
|
1447
1447
|
if (g > 2 * n && m > 2 * n)
|
|
1448
1448
|
return $ == null || $.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j", s.requestId, g, m, {
|
|
1449
|
-
from:
|
|
1449
|
+
from: t,
|
|
1450
1450
|
t1: o,
|
|
1451
|
-
t2:
|
|
1452
|
-
hr:
|
|
1451
|
+
t2: r,
|
|
1452
|
+
hr: i
|
|
1453
1453
|
}), {};
|
|
1454
1454
|
}
|
|
1455
|
-
const a = v.calculateBearing(
|
|
1455
|
+
const a = v.calculateBearing(t, o), l = v.calculateBearing(o, r), u = Math.abs(a - l);
|
|
1456
1456
|
let f = 0;
|
|
1457
1457
|
u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
|
|
1458
1458
|
const h = v.calculateCoordinate(o, f, n);
|
|
1459
1459
|
return $ == null || $.info("[%s] the right tangent position: %j", s.requestId, {
|
|
1460
|
-
from:
|
|
1460
|
+
from: t,
|
|
1461
1461
|
t1: o,
|
|
1462
|
-
t2:
|
|
1462
|
+
t2: r,
|
|
1463
1463
|
radius: n,
|
|
1464
1464
|
bearing1: a,
|
|
1465
1465
|
bearing2: l,
|
|
1466
1466
|
right: h
|
|
1467
|
-
}), { at: h, t1: o, t2:
|
|
1467
|
+
}), { at: h, t1: o, t2: r, hr: Number(i), hours: c };
|
|
1468
1468
|
}
|
|
1469
1469
|
return {};
|
|
1470
1470
|
}
|
|
@@ -1478,23 +1478,23 @@ class re {
|
|
|
1478
1478
|
* @param radius 与台风中心的距离
|
|
1479
1479
|
* @param options
|
|
1480
1480
|
*/
|
|
1481
|
-
static driftPassageAt(
|
|
1482
|
-
const { t1: o, t2:
|
|
1483
|
-
if (o &&
|
|
1481
|
+
static driftPassageAt(t, e, n, s = {}) {
|
|
1482
|
+
const { t1: o, t2: r, hr: i, hours: c } = this.tropicalCenterTwin(e, 24, s);
|
|
1483
|
+
if (o && r) {
|
|
1484
1484
|
if (!s.debug) {
|
|
1485
|
-
const h = v.calculateDistance(
|
|
1485
|
+
const h = v.calculateDistance(t, o), g = v.calculateDistance(t, r);
|
|
1486
1486
|
if (h > 2 * n && g > 2 * n)
|
|
1487
1487
|
return $ == null || $.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j", s.requestId, h, g, {
|
|
1488
|
-
from:
|
|
1488
|
+
from: t,
|
|
1489
1489
|
t1: o,
|
|
1490
|
-
t2:
|
|
1491
|
-
hr:
|
|
1490
|
+
t2: r,
|
|
1491
|
+
hr: i
|
|
1492
1492
|
}), {};
|
|
1493
1493
|
}
|
|
1494
|
-
const a = v.calculateBearing(
|
|
1495
|
-
return { at: v.calculateCoordinate(o, a - l + 180, n < u ? n : u), t1: o, t2:
|
|
1494
|
+
const a = v.calculateBearing(t, o), l = v.calculateBearing(o, r), u = v.calculateDistance(t, o);
|
|
1495
|
+
return { at: v.calculateCoordinate(o, a - l + 180, n < u ? n : u), t1: o, t2: r, hr: Number(i), hours: c };
|
|
1496
1496
|
} else
|
|
1497
|
-
return $ == null || $.info("[%s] no need drift: %j", s.requestId, { from:
|
|
1497
|
+
return $ == null || $.info("[%s] no need drift: %j", s.requestId, { from: t, t1: o, t2: r, hr: i }), {};
|
|
1498
1498
|
}
|
|
1499
1499
|
/**
|
|
1500
1500
|
* 获取台风中心点对
|
|
@@ -1504,53 +1504,53 @@ class re {
|
|
|
1504
1504
|
* @returns { t1: 当前台风中心点, t2: 未来hr小时台风中心点, hr: 未来台风中心点与当前台风中心点之间的时间差, hours: 未来24小时内所有台风中心点 }
|
|
1505
1505
|
* @private
|
|
1506
1506
|
*/
|
|
1507
|
-
static tropicalCenterTwin(
|
|
1507
|
+
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
1508
1508
|
var l, u, f, h, g;
|
|
1509
1509
|
let s = {};
|
|
1510
|
-
(l =
|
|
1510
|
+
(l = t.forecasts) == null || l.forEach((m) => {
|
|
1511
1511
|
s = { ...m.hours, ...s };
|
|
1512
1512
|
});
|
|
1513
|
-
const o = ((u =
|
|
1513
|
+
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (s == null ? void 0 : s[(f = Object.keys(s)) == null ? void 0 : f[0]]);
|
|
1514
1514
|
$ == null || $.info("[%s] the first tropical center: %j", n.requestId, o);
|
|
1515
|
-
let
|
|
1516
|
-
|
|
1517
|
-
const
|
|
1518
|
-
$ == null || $.info("[%s] the second tropical center: %j in %d hrs", n.requestId,
|
|
1519
|
-
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(
|
|
1515
|
+
let r = (h = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
|
|
1516
|
+
r || (r = (g = Object.keys(s || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : g.at(-1));
|
|
1517
|
+
const i = s == null ? void 0 : s[r || -1];
|
|
1518
|
+
$ == null || $.info("[%s] the second tropical center: %j in %d hrs", n.requestId, i, r);
|
|
1519
|
+
const c = Object.keys(s || {}).filter((m) => Number(m) <= Number(r)), a = { 0: o };
|
|
1520
1520
|
for (const m of c)
|
|
1521
1521
|
a[m] = s[m];
|
|
1522
|
-
return { t1: o, t2:
|
|
1522
|
+
return { t1: o, t2: i, hr: Number(r), hours: a };
|
|
1523
1523
|
}
|
|
1524
|
-
static pickIndex(
|
|
1524
|
+
static pickIndex(t, e) {
|
|
1525
1525
|
let n = 0;
|
|
1526
|
-
for (const s of
|
|
1527
|
-
if (b(s.properties.date).isAfter(
|
|
1526
|
+
for (const s of t) {
|
|
1527
|
+
if (b(s.properties.date).isAfter(e))
|
|
1528
1528
|
return n === 0 ? -1 : n;
|
|
1529
1529
|
n++;
|
|
1530
1530
|
}
|
|
1531
1531
|
return n;
|
|
1532
1532
|
}
|
|
1533
|
-
static computeNumber(
|
|
1534
|
-
if (
|
|
1535
|
-
if (
|
|
1536
|
-
if (isNaN(
|
|
1533
|
+
static computeNumber(t, e, n) {
|
|
1534
|
+
if (t)
|
|
1535
|
+
if (e) {
|
|
1536
|
+
if (isNaN(t) && isNaN(e) && typeof t != "string" && typeof e != "string") {
|
|
1537
1537
|
const s = {};
|
|
1538
|
-
for (const o in
|
|
1539
|
-
s[o] = this.computeNumber(
|
|
1538
|
+
for (const o in t)
|
|
1539
|
+
s[o] = this.computeNumber(t[o], e[o], n);
|
|
1540
1540
|
return s;
|
|
1541
1541
|
}
|
|
1542
|
-
return Math.round((
|
|
1542
|
+
return Math.round((t + (e - t) * n) * 100) / 100;
|
|
1543
1543
|
} else
|
|
1544
|
-
return
|
|
1544
|
+
return t;
|
|
1545
1545
|
else
|
|
1546
|
-
return
|
|
1546
|
+
return e;
|
|
1547
1547
|
}
|
|
1548
1548
|
}
|
|
1549
1549
|
typeof globalThis < "u" && typeof globalThis.Buffer > "u" && (globalThis.Buffer = {
|
|
1550
1550
|
isBuffer(C) {
|
|
1551
1551
|
return C instanceof Uint8Array;
|
|
1552
1552
|
},
|
|
1553
|
-
from(C,
|
|
1553
|
+
from(C, t) {
|
|
1554
1554
|
if (typeof C == "string")
|
|
1555
1555
|
return new TextEncoder().encode(C);
|
|
1556
1556
|
if (C instanceof ArrayBuffer)
|
|
@@ -1569,8 +1569,8 @@ try {
|
|
|
1569
1569
|
function H() {
|
|
1570
1570
|
if (typeof DOMParser < "u")
|
|
1571
1571
|
return new DOMParser();
|
|
1572
|
-
const { JSDOM: C } = require("jsdom"), { DOMParser:
|
|
1573
|
-
return new
|
|
1572
|
+
const { JSDOM: C } = require("jsdom"), { DOMParser: t } = new C("").window;
|
|
1573
|
+
return new t();
|
|
1574
1574
|
}
|
|
1575
1575
|
class F {
|
|
1576
1576
|
/**
|
|
@@ -1580,8 +1580,8 @@ class F {
|
|
|
1580
1580
|
* @param buf
|
|
1581
1581
|
* @returns
|
|
1582
1582
|
*/
|
|
1583
|
-
static toArrayBuffer(
|
|
1584
|
-
return
|
|
1583
|
+
static toArrayBuffer(t) {
|
|
1584
|
+
return t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
|
|
1585
1585
|
}
|
|
1586
1586
|
/**
|
|
1587
1587
|
* 基于turf画圆,返回GeoJSON Feature<Polygon>
|
|
@@ -1590,11 +1590,11 @@ class F {
|
|
|
1590
1590
|
* @param radius 半径
|
|
1591
1591
|
* @param options 步数、单位等选项
|
|
1592
1592
|
*/
|
|
1593
|
-
static drawCircle(
|
|
1594
|
-
const o = (s == null ? void 0 : s.steps) ?? 64,
|
|
1595
|
-
|
|
1593
|
+
static drawCircle(t, e, n, s = {}) {
|
|
1594
|
+
const o = (s == null ? void 0 : s.steps) ?? 64, r = (s == null ? void 0 : s.units) ?? "nauticalmiles", i = (s == null ? void 0 : s.properties) ?? {}, c = T.point([t, e]), a = T.destination(c, n, 90, { units: r }), l = b.utc();
|
|
1595
|
+
i.id = (s == null ? void 0 : s.id) || l.valueOf().toString();
|
|
1596
1596
|
const u = "circle";
|
|
1597
|
-
return
|
|
1597
|
+
return i.name = (s == null ? void 0 : s.name) || `${u}_${l.format()}`, i.radius = n, i.center = [t, e], i.end = a.geometry.coordinates.map((f) => d.roundPrecision(f, 9)), i.units = r, i.steps = o, i.shape = "circle", R.info("[%s] draw circle with %j", s == null ? void 0 : s.requestId, i), T.circle(c, n, { steps: o, units: r, properties: i });
|
|
1598
1598
|
}
|
|
1599
1599
|
/**
|
|
1600
1600
|
* 基于turf画矩形,返回GeoJSON Feature<Polygon>
|
|
@@ -1602,12 +1602,12 @@ class F {
|
|
|
1602
1602
|
* @param end 对角线终点 [lng, lat]
|
|
1603
1603
|
* @param options 选项
|
|
1604
1604
|
*/
|
|
1605
|
-
static drawRect(
|
|
1605
|
+
static drawRect(t, e, n = {}) {
|
|
1606
1606
|
const s = (n == null ? void 0 : n.properties) ?? {}, o = b.utc();
|
|
1607
1607
|
s.id = (n == null ? void 0 : n.id) || o.valueOf().toString();
|
|
1608
|
-
const
|
|
1609
|
-
s.name = (n == null ? void 0 : n.name) || `${
|
|
1610
|
-
const [
|
|
1608
|
+
const r = "rect";
|
|
1609
|
+
s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.start = t.map((l) => d.roundPrecision(l, 9)), s.end = e.map((l) => d.roundPrecision(l, 9)), s.shape = "rect", R.info("[%s] draw rect with %j", n == null ? void 0 : n.requestId, s);
|
|
1610
|
+
const [i, c] = d.convertToMonotonicLng2([t, e]), a = [Math.min(i[0], c[0]), Math.min(i[1], c[1]), Math.max(i[0], c[0]), Math.max(i[1], c[1])];
|
|
1611
1611
|
return T.bboxPolygon(a, { properties: s });
|
|
1612
1612
|
}
|
|
1613
1613
|
/**
|
|
@@ -1617,13 +1617,13 @@ class F {
|
|
|
1617
1617
|
* @param options
|
|
1618
1618
|
* @returns
|
|
1619
1619
|
*/
|
|
1620
|
-
static drawLine(
|
|
1621
|
-
const n = (
|
|
1622
|
-
n.id = (
|
|
1620
|
+
static drawLine(t, e = {}) {
|
|
1621
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = b.utc();
|
|
1622
|
+
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1623
1623
|
const o = "line";
|
|
1624
|
-
n.name = (
|
|
1625
|
-
const
|
|
1626
|
-
return T.lineString(
|
|
1624
|
+
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.shape = "line", R.info("[%s] draw line with %j", e == null ? void 0 : e.requestId, n);
|
|
1625
|
+
const r = d.convertToMonotonicLng2(t);
|
|
1626
|
+
return T.lineString(r, n);
|
|
1627
1627
|
}
|
|
1628
1628
|
/**
|
|
1629
1629
|
* 基于turf画多边形,返回GeoJSON Feature<Polygon>
|
|
@@ -1631,13 +1631,13 @@ class F {
|
|
|
1631
1631
|
* @param options
|
|
1632
1632
|
* @returns
|
|
1633
1633
|
*/
|
|
1634
|
-
static drawPolygon(
|
|
1635
|
-
const n = (
|
|
1636
|
-
n.id = (
|
|
1634
|
+
static drawPolygon(t, e = {}) {
|
|
1635
|
+
const n = (e == null ? void 0 : e.properties) ?? {}, s = b.utc();
|
|
1636
|
+
n.id = (e == null ? void 0 : e.id) || s.valueOf().toString();
|
|
1637
1637
|
const o = "polygon";
|
|
1638
|
-
n.name = (
|
|
1639
|
-
const
|
|
1640
|
-
return T.polygon([
|
|
1638
|
+
n.name = (e == null ? void 0 : e.name) || `${o}_${s.format()}`, n.coordinates = t.map((i) => i.map((c) => d.roundPrecision(c, 9))), n.shape = "polygon", R.info("[%s] draw polygon with %j", e == null ? void 0 : e.requestId, n);
|
|
1639
|
+
const r = d.convertToMonotonicLng2(t);
|
|
1640
|
+
return T.polygon([r], n);
|
|
1641
1641
|
}
|
|
1642
1642
|
/**
|
|
1643
1643
|
* 基于turf画点,返回GeoJSON Feature<Point>
|
|
@@ -1646,11 +1646,11 @@ class F {
|
|
|
1646
1646
|
* @param options
|
|
1647
1647
|
* @returns
|
|
1648
1648
|
*/
|
|
1649
|
-
static drawPoint(
|
|
1649
|
+
static drawPoint(t, e, n = {}) {
|
|
1650
1650
|
const s = (n == null ? void 0 : n.properties) ?? {}, o = b.utc();
|
|
1651
1651
|
s.id = (n == null ? void 0 : n.id) || o.valueOf().toString();
|
|
1652
|
-
const
|
|
1653
|
-
return s.name = (n == null ? void 0 : n.name) || `${
|
|
1652
|
+
const r = "point";
|
|
1653
|
+
return s.name = (n == null ? void 0 : n.name) || `${r}_${o.format()}`, s.shape = "point", R.info("[%s] draw point with %j", n == null ? void 0 : n.requestId, s), T.point([e, t], s);
|
|
1654
1654
|
}
|
|
1655
1655
|
/**
|
|
1656
1656
|
* 解析ORM GeoJSON Feature (圆), 返回FeatureCollection
|
|
@@ -1659,29 +1659,29 @@ class F {
|
|
|
1659
1659
|
* @returns
|
|
1660
1660
|
* 如果feature是圆,则返回圆的中心、端点、半径线 和 边线四个Feature
|
|
1661
1661
|
*/
|
|
1662
|
-
static parseCircle(
|
|
1662
|
+
static parseCircle(t, e = {}) {
|
|
1663
1663
|
var s, o;
|
|
1664
|
-
R.info("[%s] parse circle with %j",
|
|
1665
|
-
const n =
|
|
1664
|
+
R.info("[%s] parse circle with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1665
|
+
const n = t.properties || {};
|
|
1666
1666
|
if (n.shape == "circle") {
|
|
1667
|
-
const
|
|
1668
|
-
n.id = (n == null ? void 0 : n.id) ||
|
|
1669
|
-
const
|
|
1667
|
+
const r = b.utc();
|
|
1668
|
+
n.id = (n == null ? void 0 : n.id) || r.valueOf().toString();
|
|
1669
|
+
const i = n == null ? void 0 : n.id, c = ((s = n == null ? void 0 : n.center) == null ? void 0 : s.length) == 2 ? T.point(n.center) : T.centroid(t);
|
|
1670
1670
|
let a = "center";
|
|
1671
|
-
c.properties = { id: `${a}_${
|
|
1671
|
+
c.properties = { id: `${a}_${i}`, parentId: i, name: a };
|
|
1672
1672
|
const l = (n == null ? void 0 : n.units) || "nauticalmiles";
|
|
1673
1673
|
let u = n == null ? void 0 : n.radius;
|
|
1674
1674
|
if (!u) {
|
|
1675
|
-
const g = T.polygonToLine(
|
|
1675
|
+
const g = T.polygonToLine(t);
|
|
1676
1676
|
u = T.pointToLineDistance(c, g, { units: l });
|
|
1677
1677
|
}
|
|
1678
1678
|
a = "end";
|
|
1679
1679
|
const f = ((o = n == null ? void 0 : n.end) == null ? void 0 : o.length) == 2 ? T.point(n.end) : T.destination(c, u, 90, { units: l });
|
|
1680
|
-
f.properties = { id: `${a}_${
|
|
1680
|
+
f.properties = { id: `${a}_${i}`, parentId: i, name: a, radius: u, units: l };
|
|
1681
1681
|
const h = T.lineString([c.geometry.coordinates, f.geometry.coordinates]);
|
|
1682
|
-
return a = "edge", h.properties = { id: `${a}_${
|
|
1682
|
+
return a = "edge", h.properties = { id: `${a}_${i}`, parentId: i, name: a, radius: u, units: l }, T.featureCollection([c, f, h, t]);
|
|
1683
1683
|
} else
|
|
1684
|
-
return R.warn("[%s] not a orm-std circle, just return the original feature",
|
|
1684
|
+
return R.warn("[%s] not a orm-std circle, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1685
1685
|
}
|
|
1686
1686
|
/**
|
|
1687
1687
|
* 解析ORM GeoJSON Feature (矩形), 返回FeatureCollection
|
|
@@ -1690,19 +1690,19 @@ class F {
|
|
|
1690
1690
|
* @returns
|
|
1691
1691
|
* 如果feature是矩形,则返回矩形的四个顶点和矩形Feature
|
|
1692
1692
|
*/
|
|
1693
|
-
static parseRect(
|
|
1694
|
-
R.info("[%s] parse rect with %j",
|
|
1695
|
-
const n =
|
|
1693
|
+
static parseRect(t, e = {}) {
|
|
1694
|
+
R.info("[%s] parse rect with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1695
|
+
const n = t.properties || {};
|
|
1696
1696
|
if (n.shape == "rect") {
|
|
1697
1697
|
const s = b.utc();
|
|
1698
1698
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1699
|
-
const o = n == null ? void 0 : n.id,
|
|
1700
|
-
const u = T.point(
|
|
1699
|
+
const o = n == null ? void 0 : n.id, r = t.geometry.coordinates[0], c = ["sw", "nw", "ne", "se"].map((a, l) => {
|
|
1700
|
+
const u = T.point(r[l]);
|
|
1701
1701
|
return u.properties = { id: `${a}_${o}`, parentId: o, name: a }, u;
|
|
1702
1702
|
});
|
|
1703
|
-
return T.featureCollection([...c,
|
|
1703
|
+
return T.featureCollection([...c, t]);
|
|
1704
1704
|
} else
|
|
1705
|
-
return R.warn("[%s] not a orm-std rect, just return the original feature",
|
|
1705
|
+
return R.warn("[%s] not a orm-std rect, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1706
1706
|
}
|
|
1707
1707
|
/**
|
|
1708
1708
|
* 解析ORM GeoJSON Feature (线), 返回FeatureCollection
|
|
@@ -1711,19 +1711,19 @@ class F {
|
|
|
1711
1711
|
* @returns
|
|
1712
1712
|
* 如果feature是线,则返回所有坐标点(首为start、尾为end、中间为point_N)以及线Feature
|
|
1713
1713
|
*/
|
|
1714
|
-
static parseLine(
|
|
1715
|
-
R.info("[%s] parse line with %j",
|
|
1716
|
-
const n =
|
|
1714
|
+
static parseLine(t, e = {}) {
|
|
1715
|
+
R.info("[%s] parse line with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1716
|
+
const n = t.properties || {};
|
|
1717
1717
|
if (n.shape == "line") {
|
|
1718
1718
|
const s = b.utc();
|
|
1719
1719
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1720
|
-
const o = n == null ? void 0 : n.id,
|
|
1720
|
+
const o = n == null ? void 0 : n.id, i = t.geometry.coordinates.map((c, a) => {
|
|
1721
1721
|
const l = `point_${a}`, u = T.point(c);
|
|
1722
1722
|
return u.properties = { id: `${l}_${o}`, parentId: o, name: l, index: a }, u;
|
|
1723
1723
|
});
|
|
1724
|
-
return T.featureCollection([...
|
|
1724
|
+
return T.featureCollection([...i, t]);
|
|
1725
1725
|
} else
|
|
1726
|
-
return R.warn("[%s] not a orm-std line, just return the original feature",
|
|
1726
|
+
return R.warn("[%s] not a orm-std line, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1727
1727
|
}
|
|
1728
1728
|
/**
|
|
1729
1729
|
* 解析ORM GeoJSON Feature (多边形), 返回FeatureCollection
|
|
@@ -1732,19 +1732,19 @@ class F {
|
|
|
1732
1732
|
* @returns
|
|
1733
1733
|
* 如果feature是多边形,则返回多边形的顶点和多边形Feature
|
|
1734
1734
|
*/
|
|
1735
|
-
static parsePolygon(
|
|
1736
|
-
R.info("[%s] parse polygon with %j",
|
|
1737
|
-
const n =
|
|
1735
|
+
static parsePolygon(t, e = {}) {
|
|
1736
|
+
R.info("[%s] parse polygon with %j", e == null ? void 0 : e.requestId, t.properties);
|
|
1737
|
+
const n = t.properties || {};
|
|
1738
1738
|
if (n.shape == "polygon") {
|
|
1739
1739
|
const s = b.utc();
|
|
1740
1740
|
n.id = (n == null ? void 0 : n.id) || s.valueOf().toString();
|
|
1741
|
-
const o = n == null ? void 0 : n.id,
|
|
1741
|
+
const o = n == null ? void 0 : n.id, i = t.geometry.coordinates[0].map((c, a) => {
|
|
1742
1742
|
const l = T.point(c), u = `corner_${a}`;
|
|
1743
1743
|
return l.properties = { id: `${u}_${o}`, parentId: o, name: u, index: a }, l;
|
|
1744
1744
|
});
|
|
1745
|
-
return T.featureCollection([...
|
|
1745
|
+
return T.featureCollection([...i, t]);
|
|
1746
1746
|
} else
|
|
1747
|
-
return R.warn("[%s] not a orm-std polygon, just return the original feature",
|
|
1747
|
+
return R.warn("[%s] not a orm-std polygon, just return the original feature", e == null ? void 0 : e.requestId), T.featureCollection([t]);
|
|
1748
1748
|
}
|
|
1749
1749
|
// ---------------------------------------------------------------------------
|
|
1750
1750
|
// ZIP / KMZ 内部工具
|
|
@@ -1753,11 +1753,11 @@ class F {
|
|
|
1753
1753
|
* 解压 DEFLATE raw 数据(ZIP compressionMethod=8)。
|
|
1754
1754
|
* Node.js 环境使用内置 zlib.inflateRawSync;浏览器环境抛出错误提示使用异步版本。
|
|
1755
1755
|
*/
|
|
1756
|
-
static _inflateRawSync(
|
|
1757
|
-
var
|
|
1758
|
-
if (typeof process < "u" && ((
|
|
1756
|
+
static _inflateRawSync(t) {
|
|
1757
|
+
var e;
|
|
1758
|
+
if (typeof process < "u" && ((e = process.versions) != null && e.node)) {
|
|
1759
1759
|
const n = require("zlib");
|
|
1760
|
-
return new Uint8Array(n.inflateRawSync(Buffer.from(
|
|
1760
|
+
return new Uint8Array(n.inflateRawSync(Buffer.from(t)));
|
|
1761
1761
|
}
|
|
1762
1762
|
throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead");
|
|
1763
1763
|
}
|
|
@@ -1765,19 +1765,19 @@ class F {
|
|
|
1765
1765
|
* 从 ZIP ArrayBuffer 中异步解析所有文件条目(浏览器 DecompressionStream)。
|
|
1766
1766
|
* 使用 Central Directory 解析,避免 Data Descriptor 导致的大小不准问题。
|
|
1767
1767
|
*/
|
|
1768
|
-
static async _parseZipEntries(
|
|
1768
|
+
static async _parseZipEntries(t) {
|
|
1769
1769
|
var f;
|
|
1770
|
-
const
|
|
1771
|
-
let
|
|
1770
|
+
const e = new Uint8Array(t), n = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), s = new DataView(n), o = new Uint8Array(n), r = /* @__PURE__ */ new Map();
|
|
1771
|
+
let i = -1;
|
|
1772
1772
|
for (let h = n.byteLength - 22; h >= 0; h--)
|
|
1773
1773
|
if (s.getUint32(h, !0) === 101010256) {
|
|
1774
|
-
|
|
1774
|
+
i = h;
|
|
1775
1775
|
break;
|
|
1776
1776
|
}
|
|
1777
|
-
if (
|
|
1777
|
+
if (i < 0)
|
|
1778
1778
|
throw new Error("Invalid ZIP file: EOCD not found");
|
|
1779
|
-
s.getUint16(
|
|
1780
|
-
const c = s.getUint32(
|
|
1779
|
+
s.getUint16(i + 8, !0);
|
|
1780
|
+
const c = s.getUint32(i + 12, !0), a = s.getUint32(i + 16, !0);
|
|
1781
1781
|
let l = a;
|
|
1782
1782
|
const u = a + c;
|
|
1783
1783
|
for (; l < u; ) {
|
|
@@ -1785,7 +1785,7 @@ class F {
|
|
|
1785
1785
|
throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);
|
|
1786
1786
|
const g = s.getUint16(l + 10, !0), m = s.getUint32(l + 20, !0), p = s.getUint16(l + 28, !0), S = s.getUint16(l + 30, !0), x = s.getUint16(l + 32, !0), M = s.getUint32(l + 42, !0), y = o.slice(l + 46, l + 46 + p), N = new TextDecoder().decode(y), w = s.getUint16(M + 26, !0), q = s.getUint16(M + 28, !0), U = M + 30 + w + q, L = o.slice(U, U + m);
|
|
1787
1787
|
if (g === 0)
|
|
1788
|
-
|
|
1788
|
+
r.set(N, L);
|
|
1789
1789
|
else if (g === 8) {
|
|
1790
1790
|
if (typeof DecompressionStream < "u") {
|
|
1791
1791
|
const O = new DecompressionStream("deflate-raw"), P = O.writable.getWriter(), I = O.readable.getReader();
|
|
@@ -1802,16 +1802,16 @@ class F {
|
|
|
1802
1802
|
let A = 0;
|
|
1803
1803
|
for (const k of E)
|
|
1804
1804
|
Z.set(k, A), A += k.length;
|
|
1805
|
-
|
|
1805
|
+
r.set(N, Z);
|
|
1806
1806
|
} else if (typeof process < "u" && ((f = process.versions) != null && f.node))
|
|
1807
1807
|
try {
|
|
1808
|
-
|
|
1808
|
+
r.set(N, F._inflateRawSync(L));
|
|
1809
1809
|
} catch {
|
|
1810
1810
|
}
|
|
1811
1811
|
}
|
|
1812
1812
|
l += 46 + p + S + x;
|
|
1813
1813
|
}
|
|
1814
|
-
return
|
|
1814
|
+
return r;
|
|
1815
1815
|
}
|
|
1816
1816
|
// ---------------------------------------------------------------------------
|
|
1817
1817
|
// KMZ / ZIP → GeoJSON
|
|
@@ -1822,14 +1822,14 @@ class F {
|
|
|
1822
1822
|
* @param options
|
|
1823
1823
|
* @returns
|
|
1824
1824
|
*/
|
|
1825
|
-
static async convertKML2GeoJSON(
|
|
1826
|
-
var
|
|
1827
|
-
R.info("[%s] convert kml to geojson",
|
|
1828
|
-
const s = H().parseFromString(
|
|
1825
|
+
static async convertKML2GeoJSON(t, e = {}) {
|
|
1826
|
+
var i, c;
|
|
1827
|
+
R.info("[%s] convert kml to geojson", e == null ? void 0 : e.requestId);
|
|
1828
|
+
const s = H().parseFromString(t, "application/xml"), o = Array.from(s.querySelectorAll("Placemark")), r = [];
|
|
1829
1829
|
for (const a of o) {
|
|
1830
1830
|
const l = {}, u = Array.from(a.querySelectorAll("ExtendedData > Data"));
|
|
1831
1831
|
for (const y of u) {
|
|
1832
|
-
const N = y.getAttribute("name"), w = (c = (
|
|
1832
|
+
const N = y.getAttribute("name"), w = (c = (i = y.querySelector("value")) == null ? void 0 : i.textContent) == null ? void 0 : c.trim();
|
|
1833
1833
|
N && w !== void 0 && w !== null && (l[N] = w);
|
|
1834
1834
|
}
|
|
1835
1835
|
const f = b.utc(), h = Object.keys(l).find((y) => y.toLowerCase().indexOf("name") !== -1), g = h ? l[h] : void 0, m = `${f.valueOf().toString()}_${Math.random().toString(36).slice(2, 8)}`, p = (y) => y.trim().split(/[\s\n]+/).filter((N) => N.length > 0).map((N) => {
|
|
@@ -1840,7 +1840,7 @@ class F {
|
|
|
1840
1840
|
const y = p(S.textContent || "");
|
|
1841
1841
|
if (y.length >= 2) {
|
|
1842
1842
|
const N = T.lineString(y, { ...l, shape: "line", id: m, name: g });
|
|
1843
|
-
|
|
1843
|
+
r.push(N);
|
|
1844
1844
|
}
|
|
1845
1845
|
continue;
|
|
1846
1846
|
}
|
|
@@ -1849,7 +1849,7 @@ class F {
|
|
|
1849
1849
|
const y = p(x.textContent || "");
|
|
1850
1850
|
if (y.length >= 4) {
|
|
1851
1851
|
const N = y[0][0] === y[y.length - 1][0] && y[0][1] === y[y.length - 1][1] ? y : [...y, y[0]], w = T.polygon([N], { ...l, shape: "polygon", id: m, name: g });
|
|
1852
|
-
|
|
1852
|
+
r.push(w);
|
|
1853
1853
|
}
|
|
1854
1854
|
continue;
|
|
1855
1855
|
}
|
|
@@ -1858,12 +1858,12 @@ class F {
|
|
|
1858
1858
|
const y = p(M.textContent || "");
|
|
1859
1859
|
if (y.length >= 1) {
|
|
1860
1860
|
const N = T.point(y[0], { ...l, shape: "point", id: m, name: g });
|
|
1861
|
-
|
|
1861
|
+
r.push(N);
|
|
1862
1862
|
}
|
|
1863
1863
|
continue;
|
|
1864
1864
|
}
|
|
1865
1865
|
}
|
|
1866
|
-
return T.featureCollection(
|
|
1866
|
+
return T.featureCollection(r);
|
|
1867
1867
|
}
|
|
1868
1868
|
/**
|
|
1869
1869
|
* 将 KMZ(ZIP 内含 doc.kml 或首个 .kml 文件)异步转换为 GeoJSON。
|
|
@@ -1874,14 +1874,14 @@ class F {
|
|
|
1874
1874
|
* @param buffer KMZ 文件的 ArrayBuffer
|
|
1875
1875
|
* @param options
|
|
1876
1876
|
*/
|
|
1877
|
-
static async convertKMZ2GeoJSON(
|
|
1878
|
-
var
|
|
1879
|
-
R.info("[%s] convert kmz to geojson (async)",
|
|
1880
|
-
const n = await F._parseZipEntries(
|
|
1877
|
+
static async convertKMZ2GeoJSON(t, e = {}) {
|
|
1878
|
+
var r;
|
|
1879
|
+
R.info("[%s] convert kmz to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = F.toArrayBuffer(t));
|
|
1880
|
+
const n = await F._parseZipEntries(t), s = n.get("doc.kml") ?? ((r = [...n.entries()].find(([i]) => i.toLowerCase().endsWith(".kml"))) == null ? void 0 : r[1]);
|
|
1881
1881
|
if (!s)
|
|
1882
|
-
return R.warn("[%s] no .kml file found in kmz",
|
|
1882
|
+
return R.warn("[%s] no .kml file found in kmz", e == null ? void 0 : e.requestId), T.featureCollection([]);
|
|
1883
1883
|
const o = new TextDecoder().decode(s);
|
|
1884
|
-
return F.convertKML2GeoJSON(o,
|
|
1884
|
+
return F.convertKML2GeoJSON(o, e);
|
|
1885
1885
|
}
|
|
1886
1886
|
/**
|
|
1887
1887
|
* 将 ZIP 文件中所有 .kml 文件合并转换为一个 GeoJSON FeatureCollection(异步)。
|
|
@@ -1892,16 +1892,16 @@ class F {
|
|
|
1892
1892
|
* @param buffer ZIP 文件的 ArrayBuffer
|
|
1893
1893
|
* @param options
|
|
1894
1894
|
*/
|
|
1895
|
-
static async convertZIP2GeoJSON(
|
|
1896
|
-
R.info("[%s] convert zip to geojson (async)",
|
|
1897
|
-
const n = await F._parseZipEntries(
|
|
1898
|
-
for (const [o,
|
|
1895
|
+
static async convertZIP2GeoJSON(t, e = {}) {
|
|
1896
|
+
R.info("[%s] convert zip to geojson (async)", e == null ? void 0 : e.requestId), typeof Buffer < "u" && Buffer.isBuffer(t) && (t = F.toArrayBuffer(t));
|
|
1897
|
+
const n = await F._parseZipEntries(t), s = [];
|
|
1898
|
+
for (const [o, r] of n) {
|
|
1899
1899
|
if (!o.toLowerCase().endsWith(".kml"))
|
|
1900
1900
|
continue;
|
|
1901
|
-
const
|
|
1901
|
+
const i = new TextDecoder().decode(r), c = await F.convertKML2GeoJSON(i, e);
|
|
1902
1902
|
s.push(...c.features);
|
|
1903
1903
|
}
|
|
1904
|
-
return s.length === 0 ? (R.warn("[%s] no .kml files found in zip",
|
|
1904
|
+
return s.length === 0 ? (R.warn("[%s] no .kml files found in zip", e == null ? void 0 : e.requestId), this.convertSHP2GeoJSON(t, e)) : T.featureCollection(s);
|
|
1905
1905
|
}
|
|
1906
1906
|
/**
|
|
1907
1907
|
* 将 Shapefile ZIP(含 .shp/.shx/.dbf/.prj)转换为 GeoJSON FeatureCollection。
|
|
@@ -1911,13 +1911,13 @@ class F {
|
|
|
1911
1911
|
* @param buffer ZIP 文件的 ArrayBuffer
|
|
1912
1912
|
* @param options
|
|
1913
1913
|
*/
|
|
1914
|
-
static async convertSHP2GeoJSON(
|
|
1915
|
-
R.info("[%s] convert shp zip to geojson",
|
|
1914
|
+
static async convertSHP2GeoJSON(t, e = {}) {
|
|
1915
|
+
R.info("[%s] convert shp zip to geojson", e == null ? void 0 : e.requestId);
|
|
1916
1916
|
try {
|
|
1917
|
-
typeof Buffer < "u" && Buffer.isBuffer(
|
|
1918
|
-
const n = await J(
|
|
1917
|
+
typeof Buffer < "u" && Buffer.isBuffer(t) && (t = F.toArrayBuffer(t));
|
|
1918
|
+
const n = await J(t);
|
|
1919
1919
|
if (Array.isArray(n)) {
|
|
1920
|
-
const s = n.flatMap((c) => c.features || []), o = b.utc(),
|
|
1920
|
+
const s = n.flatMap((c) => c.features || []), o = b.utc(), r = (e == null ? void 0 : e.id) || o.valueOf().toString(), i = {
|
|
1921
1921
|
Point: "point",
|
|
1922
1922
|
MultiPoint: "point",
|
|
1923
1923
|
LineString: "line",
|
|
@@ -1927,15 +1927,15 @@ class F {
|
|
|
1927
1927
|
};
|
|
1928
1928
|
return s.forEach((c, a) => {
|
|
1929
1929
|
var g;
|
|
1930
|
-
const l = ((g = c.geometry) == null ? void 0 : g.type) || "", u =
|
|
1931
|
-
c.properties = c.properties || {}, c.properties.shape = u, c.properties.parentId =
|
|
1930
|
+
const l = ((g = c.geometry) == null ? void 0 : g.type) || "", u = i[l] || l.toLowerCase();
|
|
1931
|
+
c.properties = c.properties || {}, c.properties.shape = u, c.properties.parentId = r, c.properties.id = `${r}_${a}`;
|
|
1932
1932
|
const f = Object.keys(c.properties).find((m) => m.toLowerCase().indexOf("name") !== -1), h = f ? c.properties[f] : void 0;
|
|
1933
1933
|
c.properties.name = h || `${u}_${o.format()}_${a}`;
|
|
1934
1934
|
}), T.featureCollection(s);
|
|
1935
1935
|
}
|
|
1936
1936
|
return n;
|
|
1937
1937
|
} catch (n) {
|
|
1938
|
-
return R.warn("[%s] failed to convert shp zip: %s",
|
|
1938
|
+
return R.warn("[%s] failed to convert shp zip: %s", e == null ? void 0 : e.requestId, n), T.featureCollection([]);
|
|
1939
1939
|
}
|
|
1940
1940
|
}
|
|
1941
1941
|
}
|
|
@@ -1944,5 +1944,5 @@ export {
|
|
|
1944
1944
|
F as GeoJsonHelper,
|
|
1945
1945
|
v as LaneHelper,
|
|
1946
1946
|
d as LngLatHelper,
|
|
1947
|
-
|
|
1947
|
+
it as TropicalHelper
|
|
1948
1948
|
};
|