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