@idm-plugin/geo 1.2.7 → 1.2.9
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 +418 -413
- package/dist/index.umd.cjs +1 -1
- package/dist/tropicals/src/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as g from "@turf/turf";
|
|
2
|
-
import
|
|
2
|
+
import D from "moment";
|
|
3
3
|
import "moment-timezone";
|
|
4
4
|
import W from "tz-lookup";
|
|
5
5
|
function E(v) {
|
|
@@ -39,31 +39,31 @@ class l {
|
|
|
39
39
|
* @param lng
|
|
40
40
|
* @param lat
|
|
41
41
|
*/
|
|
42
|
-
static guessTimeZoneOffset(
|
|
43
|
-
const n = W(
|
|
44
|
-
return this.roundPrecision(
|
|
42
|
+
static guessTimeZoneOffset(t, e) {
|
|
43
|
+
const n = W(e, t), i = D().tz(n).utcOffset();
|
|
44
|
+
return this.roundPrecision(i / 60, 1);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* 将时间offset转换为时区,例如:8.5 => +08:30
|
|
48
48
|
* @param offset => 8.5
|
|
49
49
|
* @return timezone => +08:30
|
|
50
50
|
*/
|
|
51
|
-
static prettyTimeZoneOffset(
|
|
52
|
-
let
|
|
53
|
-
return n = n > 9 ? n : `0${n}`,
|
|
54
|
-
}
|
|
55
|
-
static lng2pretty(
|
|
56
|
-
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
s =
|
|
61
|
-
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${
|
|
51
|
+
static prettyTimeZoneOffset(t) {
|
|
52
|
+
let e = Math.floor(Math.abs(t)), n = Math.round((Math.abs(t) - e) * 60);
|
|
53
|
+
return n = n > 9 ? n : `0${n}`, e = e > 9 ? e : `0${e}`, t > 0 ? `+${e}:${n}` : `-${e}:${n}`;
|
|
54
|
+
}
|
|
55
|
+
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
56
|
+
t = l.convertToStdLng(t, e);
|
|
57
|
+
let i = "E";
|
|
58
|
+
t < 0 && (i = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
59
|
+
let o = t * 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, e).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, e).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(d,
|
|
65
|
-
minute: l.roundPrecision(c,
|
|
66
|
-
second: l.roundPrecision(s,
|
|
63
|
+
direction: i,
|
|
64
|
+
degree: l.roundPrecision(d, e),
|
|
65
|
+
minute: l.roundPrecision(c, e),
|
|
66
|
+
second: l.roundPrecision(s, e),
|
|
67
67
|
pretty: f
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -73,102 +73,102 @@ class l {
|
|
|
73
73
|
* @param precision 精确度
|
|
74
74
|
* @param format 格式化
|
|
75
75
|
*/
|
|
76
|
-
static lat2pretty(
|
|
77
|
-
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
s =
|
|
82
|
-
const f = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${
|
|
76
|
+
static lat2pretty(t, e = 6, n = "H°M′") {
|
|
77
|
+
t = t % 180;
|
|
78
|
+
let i = "N";
|
|
79
|
+
t < 0 && (i = "S"), t = Math.abs(t), n = n.toUpperCase();
|
|
80
|
+
let o = t * 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, e).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, e).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(d,
|
|
86
|
-
minute: l.roundPrecision(c,
|
|
87
|
-
second: l.roundPrecision(s,
|
|
84
|
+
direction: i,
|
|
85
|
+
degree: l.roundPrecision(d, e),
|
|
86
|
+
minute: l.roundPrecision(c, e),
|
|
87
|
+
second: l.roundPrecision(s, e),
|
|
88
88
|
pretty: f
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
static str2Lng(
|
|
91
|
+
static str2Lng(t, e = 6) {
|
|
92
92
|
let n;
|
|
93
|
-
if (isNaN(
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
let [s, r] =
|
|
93
|
+
if (isNaN(t)) {
|
|
94
|
+
t = l.strReplace(t, "LNG");
|
|
95
|
+
const i = t[t.length - 1].toUpperCase();
|
|
96
|
+
t = t.substring(0, t.length - 1).trim();
|
|
97
|
+
const o = t.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
|
-
n = Number(
|
|
106
|
-
return l.convertToStdLng(n,
|
|
105
|
+
n = Number(t);
|
|
106
|
+
return l.convertToStdLng(n, e);
|
|
107
107
|
}
|
|
108
|
-
static str2Lat(
|
|
108
|
+
static str2Lat(t, e = 6) {
|
|
109
109
|
let n;
|
|
110
|
-
if (isNaN(
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
let [s, r] =
|
|
110
|
+
if (isNaN(t)) {
|
|
111
|
+
t = l.strReplace(t, "LAT");
|
|
112
|
+
const i = t[t.length - 1].toUpperCase();
|
|
113
|
+
t = t.substring(0, t.length - 1).trim();
|
|
114
|
+
const o = t.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
|
-
n = Number(
|
|
123
|
-
return l.roundPrecision(n,
|
|
124
|
-
}
|
|
125
|
-
static str2LngOrLat(
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
return ["N", "S"].includes(
|
|
129
|
-
lat: l.str2Lat(
|
|
122
|
+
n = Number(t);
|
|
123
|
+
return l.roundPrecision(n, e);
|
|
124
|
+
}
|
|
125
|
+
static str2LngOrLat(t, e = 6, n = "LAT") {
|
|
126
|
+
t = l.strReplace(t, n);
|
|
127
|
+
const i = t[t.length - 1].toUpperCase();
|
|
128
|
+
return ["N", "S"].includes(i) ? {
|
|
129
|
+
lat: l.str2Lat(t, e)
|
|
130
130
|
} : {
|
|
131
|
-
lng: l.str2Lng(
|
|
131
|
+
lng: l.str2Lng(t, e)
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
static convertToStdLng(
|
|
135
|
-
return
|
|
134
|
+
static convertToStdLng(t, e = 4) {
|
|
135
|
+
return t > 180 ? (t = t % 360, t = t > 180 ? t - 360 : t) : t < -180 && (t = t % 360, t = t < -180 ? t + 360 : t), l.roundPrecision(t, e);
|
|
136
136
|
}
|
|
137
|
-
static roundPrecision(
|
|
138
|
-
if (typeof
|
|
139
|
-
const n = Number("1".padEnd(
|
|
140
|
-
return Math.round(
|
|
137
|
+
static roundPrecision(t, e = 4) {
|
|
138
|
+
if (typeof t == "number") {
|
|
139
|
+
const n = Number("1".padEnd(e + 1, "0"));
|
|
140
|
+
return Math.round(t * n) / n;
|
|
141
141
|
}
|
|
142
|
-
return
|
|
142
|
+
return t;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* 转换为按经度单调增/减的坐标数组
|
|
146
146
|
* @param coordinates [[lng, lat]]
|
|
147
147
|
*/
|
|
148
|
-
static convertToMonotonicLng2(
|
|
149
|
-
for (let
|
|
150
|
-
e
|
|
151
|
-
return
|
|
148
|
+
static convertToMonotonicLng2(t) {
|
|
149
|
+
for (let e = 1; e < t.length; e++)
|
|
150
|
+
t[e][0] += Math.round((t[e - 1][0] - t[e][0]) / 360) * 360;
|
|
151
|
+
return t;
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* 转移为按经度单调增/减的坐标数组
|
|
155
155
|
* @param coordinates [{lng, lat}]
|
|
156
156
|
*/
|
|
157
|
-
static convertToMonotonicLng(
|
|
158
|
-
for (let
|
|
159
|
-
e
|
|
160
|
-
return
|
|
157
|
+
static convertToMonotonicLng(t) {
|
|
158
|
+
for (let e = 1; e < t.length; e++)
|
|
159
|
+
t[e].lng += Math.round((t[e - 1].lng - t[e].lng) / 360) * 360;
|
|
160
|
+
return t;
|
|
161
161
|
}
|
|
162
|
-
static strReplace(
|
|
163
|
-
|
|
164
|
-
const n =
|
|
162
|
+
static strReplace(t, e = "LAT") {
|
|
163
|
+
t = t.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
|
+
const n = t[t.length - 1].toUpperCase();
|
|
165
165
|
if (!["N", "S", "E", "W"].includes(n)) {
|
|
166
|
-
const
|
|
167
|
-
if (isNaN(
|
|
168
|
-
throw new Error(`invalid Lat/Lng: ${
|
|
169
|
-
|
|
166
|
+
const i = t, o = Number(i.split(" ")[0]);
|
|
167
|
+
if (isNaN(o))
|
|
168
|
+
throw new Error(`invalid Lat/Lng: ${t}`);
|
|
169
|
+
o >= 90 ? t = `${i}E` : o <= -90 ? t = `${i}W` : ["LAN", "LNG"].includes(e == null ? void 0 : e.toUpperCase()) ? t = `${i}${o > 0 ? "E" : "W"}` : t = `${i}${o > 0 ? "N" : "S"}`;
|
|
170
170
|
}
|
|
171
|
-
return
|
|
171
|
+
return t;
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* 数据格式
|
|
@@ -177,12 +177,12 @@ class l {
|
|
|
177
177
|
* @param intPrecision 整数位数
|
|
178
178
|
* @param dcmPrecision 小数位数
|
|
179
179
|
*/
|
|
180
|
-
static padNumber(
|
|
181
|
-
const
|
|
182
|
-
return `${
|
|
180
|
+
static padNumber(t, e = 2, n = 2) {
|
|
181
|
+
const i = Math.trunc(t).toString().padStart(e, "0"), o = Math.trunc(l.roundPrecision(t - Math.trunc(t), n) * Math.pow(10, n)).toString().padStart(n, "0");
|
|
182
|
+
return `${i}.${o}`;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
class
|
|
185
|
+
class S {
|
|
186
186
|
/**
|
|
187
187
|
* 计算方位角
|
|
188
188
|
* @param from 坐标 {lng, lat}
|
|
@@ -191,13 +191,13 @@ class P {
|
|
|
191
191
|
* @param precision
|
|
192
192
|
* @returns {number} 单位度
|
|
193
193
|
*/
|
|
194
|
-
static calculateBearing(
|
|
195
|
-
const
|
|
196
|
-
[
|
|
197
|
-
[
|
|
194
|
+
static calculateBearing(t, e, n = !0, i = 4) {
|
|
195
|
+
const o = g.points([
|
|
196
|
+
[t.lng, t.lat],
|
|
197
|
+
[e.lng, e.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 P {
|
|
|
208
208
|
* @param units 单位,默认 nm(海里)
|
|
209
209
|
* @returns {number}
|
|
210
210
|
*/
|
|
211
|
-
static calculateDistance(
|
|
212
|
-
|
|
211
|
+
static calculateDistance(t, e, n = !0, i = 4, o = "nauticalmiles") {
|
|
212
|
+
t = { ...t }, e = { ...e }, t.lng = l.convertToStdLng(t.lng, i), e.lng = l.convertToStdLng(e.lng, i);
|
|
213
213
|
const s = g.points([
|
|
214
|
-
[
|
|
215
|
-
[
|
|
214
|
+
[t.lng, t.lat],
|
|
215
|
+
[e.lng, e.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
|
* 计算航线距离
|
|
@@ -223,16 +223,16 @@ class P {
|
|
|
223
223
|
* @param precision
|
|
224
224
|
* @param units
|
|
225
225
|
*/
|
|
226
|
-
static calculateRouteDistance(
|
|
227
|
-
let
|
|
228
|
-
for (const s of
|
|
226
|
+
static calculateRouteDistance(t, e = 4, n = "nauticalmiles") {
|
|
227
|
+
let i = 0, o;
|
|
228
|
+
for (const s of t)
|
|
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, e, n));
|
|
232
232
|
const a = { lng: s[r + 1][0], lat: s[r + 1][1] };
|
|
233
|
-
|
|
233
|
+
i += this.calculateDistance(c, a, !0, e, n), o = a;
|
|
234
234
|
}
|
|
235
|
-
return l.roundPrecision(
|
|
235
|
+
return l.roundPrecision(i, e);
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* 计算坐标(基于方位角和距离)
|
|
@@ -242,10 +242,10 @@ class P {
|
|
|
242
242
|
* @param units 单位,默认 nm(海里)
|
|
243
243
|
* @param rhumb
|
|
244
244
|
*/
|
|
245
|
-
static calculateCoordinate(
|
|
246
|
-
const s = g.point([
|
|
245
|
+
static calculateCoordinate(t, e, n, i = "nauticalmiles", o = !0) {
|
|
246
|
+
const s = g.point([t.lng, t.lat]);
|
|
247
247
|
let r;
|
|
248
|
-
|
|
248
|
+
o ? r = g.rhumbDestination(s, n, e, { units: i }) : r = g.destination(s, n, e, { 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 P {
|
|
|
258
258
|
* @param includeTail true 包含终点 to
|
|
259
259
|
* @param units 单位,默认 nm(海里)
|
|
260
260
|
*/
|
|
261
|
-
static interpolateCoordinates(
|
|
262
|
-
const r = [], c = this.calculateBearing(
|
|
263
|
-
|
|
261
|
+
static interpolateCoordinates(t, e, n, i = !0, o = !0, s = "nauticalmiles") {
|
|
262
|
+
const r = [], c = this.calculateBearing(t, e, !1), a = this.calculateDistance(t, e, !1, 8, s);
|
|
263
|
+
i && r.push({ lng: t.lng, lat: t.lat });
|
|
264
264
|
let d = 0;
|
|
265
265
|
for (; d < a; )
|
|
266
|
-
d += n, d < a && r.push(this.calculateCoordinate(
|
|
267
|
-
return
|
|
266
|
+
d += n, d < a && r.push(this.calculateCoordinate(t, c, d, s, !1));
|
|
267
|
+
return o && r.push({ lng: e.lng, lat: e.lat }), r;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* 分组坐标(如相邻两个坐标经度差超180度,需以180为界将坐标分为两组)
|
|
@@ -277,80 +277,80 @@ class P {
|
|
|
277
277
|
* [[-170,40],[-160,30]]
|
|
278
278
|
* ]
|
|
279
279
|
*/
|
|
280
|
-
static divideAccordingToLng(
|
|
281
|
-
if ((
|
|
280
|
+
static divideAccordingToLng(t, e = !1) {
|
|
281
|
+
if ((t == null ? void 0 : t.length) < 2)
|
|
282
282
|
return [];
|
|
283
|
-
|
|
283
|
+
t = this.deduplicateCoordinates(t);
|
|
284
284
|
let n = [];
|
|
285
|
-
const
|
|
286
|
-
let
|
|
287
|
-
for (let r = 0; r <
|
|
288
|
-
|
|
289
|
-
const c =
|
|
285
|
+
const i = [];
|
|
286
|
+
let o, s;
|
|
287
|
+
for (let r = 0; r < t.length - 1; r++) {
|
|
288
|
+
o = l.convertToStdLng(t[r].lng, 8), s = l.convertToStdLng(t[r + 1].lng, 8), n.push([o, t[r].lat]);
|
|
289
|
+
const c = o - s;
|
|
290
290
|
if (Math.abs(c) > 180) {
|
|
291
291
|
const a = l.convertToMonotonicLng2([
|
|
292
|
-
[
|
|
293
|
-
[s,
|
|
292
|
+
[o, t[r].lat],
|
|
293
|
+
[s, t[r + 1].lat]
|
|
294
294
|
]);
|
|
295
295
|
let d, u;
|
|
296
|
-
|
|
296
|
+
e ? (d = g.lineString(a), u = g.lineString([
|
|
297
297
|
[c > 0 ? 180 : -180, 89],
|
|
298
298
|
[c > 0 ? 180 : -180, -89]
|
|
299
299
|
])) : (d = g.greatCircle(a[0], a[1]), u = g.greatCircle([c > 0 ? 180 : -180, 89], [c > 0 ? 180 : -180, -89]));
|
|
300
300
|
const f = g.lineIntersect(d, u);
|
|
301
301
|
let h;
|
|
302
302
|
if (f.features.length) {
|
|
303
|
-
const
|
|
304
|
-
h = l.roundPrecision(
|
|
303
|
+
const C = g.getCoord(f.features[0]);
|
|
304
|
+
h = l.roundPrecision(C[1], 8);
|
|
305
305
|
} else
|
|
306
|
-
h =
|
|
307
|
-
c > 0 ? (n.push([180 - 1e-6, h]),
|
|
306
|
+
h = t[r].lat;
|
|
307
|
+
c > 0 ? (n.push([180 - 1e-6, h]), i.push([...n]), n = [], n.push([-(180 - 1e-6), h])) : (n.push([-(180 - 1e-6), h]), i.push([...n]), n = [], n.push([180 - 1e-6, h]));
|
|
308
308
|
}
|
|
309
|
-
r ===
|
|
309
|
+
r === t.length - 2 && n.push([s, t[r + 1].lat]);
|
|
310
310
|
}
|
|
311
|
-
return
|
|
311
|
+
return i.push(n), i;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* 去除重复坐标
|
|
315
315
|
* @param route
|
|
316
316
|
*/
|
|
317
|
-
static deduplicateRoute(
|
|
318
|
-
const
|
|
319
|
-
for (const n of
|
|
320
|
-
const
|
|
321
|
-
|
|
317
|
+
static deduplicateRoute(t) {
|
|
318
|
+
const e = [];
|
|
319
|
+
for (const n of t) {
|
|
320
|
+
const i = n.reduce((o, s) => (o.findIndex((r) => r[0] === s[0] && r[1] === s[1]) === -1 && o.push(s), o), []);
|
|
321
|
+
e.push(i);
|
|
322
322
|
}
|
|
323
|
-
return
|
|
323
|
+
return e;
|
|
324
324
|
}
|
|
325
325
|
/**
|
|
326
326
|
* 去除重新坐标
|
|
327
327
|
* @param coordinates
|
|
328
328
|
*/
|
|
329
|
-
static deduplicateCoordinates(
|
|
330
|
-
return
|
|
329
|
+
static deduplicateCoordinates(t) {
|
|
330
|
+
return t.reduce((e, n) => (e.findIndex((i) => i.lat === n.lat && i.lng === n.lng) === -1 && e.push(n), e), []);
|
|
331
331
|
}
|
|
332
332
|
/**
|
|
333
333
|
* 移出坐标
|
|
334
334
|
* @param coordinate {lng, lat}
|
|
335
335
|
* @param route 航线[[[lng, lat],[lng, lat]]]
|
|
336
336
|
*/
|
|
337
|
-
static removeCoordinateFromRoute(
|
|
338
|
-
|
|
339
|
-
for (const n of
|
|
340
|
-
for (let
|
|
341
|
-
l.roundPrecision(n[
|
|
342
|
-
return
|
|
337
|
+
static removeCoordinateFromRoute(t, e) {
|
|
338
|
+
t.lng = l.convertToStdLng(t.lng, 8);
|
|
339
|
+
for (const n of e)
|
|
340
|
+
for (let i = n.length - 1; i >= 0; i--)
|
|
341
|
+
l.roundPrecision(n[i][0], 8) === t.lng && l.roundPrecision(n[i][1], 8) === l.roundPrecision(t.lat, 8) && n.splice(i, 1);
|
|
342
|
+
return e;
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
345
345
|
* 移出坐标
|
|
346
346
|
* @param coordinate {lng, lat}
|
|
347
347
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
348
348
|
*/
|
|
349
|
-
static removeCoordinateFromWaypoints(
|
|
350
|
-
|
|
351
|
-
for (let n =
|
|
352
|
-
l.roundPrecision(
|
|
353
|
-
return
|
|
349
|
+
static removeCoordinateFromWaypoints(t, e) {
|
|
350
|
+
t.lng = l.convertToStdLng(t.lng, 8);
|
|
351
|
+
for (let n = e.length - 1; n >= 0; n--)
|
|
352
|
+
l.roundPrecision(e[n].lng, 8) === t.lng && l.roundPrecision(e[n].lat, 8) === l.roundPrecision(t.lat, 8) && e.splice(n, 1);
|
|
353
|
+
return e;
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
356
356
|
* 合并坐标进航线(基于坐标到线段最短距离边合并)
|
|
@@ -363,44 +363,44 @@ class P {
|
|
|
363
363
|
* @return
|
|
364
364
|
* [[[120, 30], [120, 35], [125,40], [130, 37]], [[-150, 40], [-130, 30]]]
|
|
365
365
|
*/
|
|
366
|
-
static mergeCoordinateToRoute(
|
|
367
|
-
|
|
368
|
-
let n = Number.MAX_VALUE,
|
|
369
|
-
return
|
|
366
|
+
static mergeCoordinateToRoute(t, e) {
|
|
367
|
+
t.lng = l.convertToStdLng(t.lng, 8);
|
|
368
|
+
let n = Number.MAX_VALUE, i = 0, o = 0, s, r;
|
|
369
|
+
return e.forEach((c, a) => {
|
|
370
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] }, h = this.calculatePointToLineDistance(
|
|
372
|
-
n > h && (n = h,
|
|
371
|
+
const u = { lng: c[d][0], lat: c[d][1] }, f = { lng: c[d + 1][0], lat: c[d + 1][1] }, h = this.calculatePointToLineDistance(t, u, f);
|
|
372
|
+
n > h && (n = h, o = d, i = a, s = this.calculateDistance(u, t), r = this.calculateDistance(f, t));
|
|
373
373
|
}
|
|
374
|
-
}), s !== 0 && r !== 0 ?
|
|
374
|
+
}), s !== 0 && r !== 0 ? e[i].splice(o + 1, 0, [t.lng, t.lat]) : s === 0 ? e[i].splice(o, 1, [t.lng, t.lat]) : r === 0 && e[i].splice(o + 1, 1, [t.lng, t.lat]), e;
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
377
377
|
* 向Route尾加1个坐标
|
|
378
378
|
* @param coordinate
|
|
379
379
|
* @param route
|
|
380
380
|
*/
|
|
381
|
-
static appendCoordinateToRoute(
|
|
382
|
-
|
|
383
|
-
const n =
|
|
384
|
-
return n.push(
|
|
381
|
+
static appendCoordinateToRoute(t, e) {
|
|
382
|
+
t.lng = l.convertToStdLng(t.lng, 8);
|
|
383
|
+
const n = S.convertRouteToCoordinates(e);
|
|
384
|
+
return n.push(t), S.divideAccordingToLng(n);
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
387
387
|
* 向route头加1个坐标
|
|
388
388
|
* @param coordinate
|
|
389
389
|
* @param route
|
|
390
390
|
*/
|
|
391
|
-
static unshiftCoordinateToRoute(
|
|
392
|
-
const n =
|
|
393
|
-
return n.unshift(
|
|
391
|
+
static unshiftCoordinateToRoute(t, e) {
|
|
392
|
+
const n = S.convertRouteToCoordinates(e);
|
|
393
|
+
return n.unshift(t), S.divideAccordingToLng(n);
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
396
|
* 合并多个waypoints进航线
|
|
397
397
|
* @param waypoints [{lat, lng}, {lat, lng}]
|
|
398
398
|
* @param route 航线 [[[lng, lat],[lng, lat]]]
|
|
399
399
|
*/
|
|
400
|
-
static mergeWaypointsToRoute(
|
|
401
|
-
for (const n of
|
|
402
|
-
|
|
403
|
-
return
|
|
400
|
+
static mergeWaypointsToRoute(t, e) {
|
|
401
|
+
for (const n of t)
|
|
402
|
+
e = this.mergeCoordinateToRoute(n, e);
|
|
403
|
+
return e;
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
406
406
|
* 计算区间航线
|
|
@@ -409,23 +409,23 @@ class P {
|
|
|
409
409
|
* @param route [[[lng, lat]]]
|
|
410
410
|
* @return [[[lng, lat]]]
|
|
411
411
|
*/
|
|
412
|
-
static calculateRangeRoute(
|
|
413
|
-
n = this.mergeWaypointsToRoute([
|
|
414
|
-
const
|
|
415
|
-
let
|
|
412
|
+
static calculateRangeRoute(t, e, n) {
|
|
413
|
+
n = this.mergeWaypointsToRoute([t, e], n);
|
|
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
|
-
if (l.roundPrecision(
|
|
422
|
-
r.push(c),
|
|
421
|
+
if (l.roundPrecision(e.lng, 8) === l.roundPrecision(c[0], 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(c[1], 8)) {
|
|
422
|
+
r.push(c), o === 0 && r.push([t.lng, t.lat]), o = 2;
|
|
423
423
|
break;
|
|
424
424
|
}
|
|
425
|
-
|
|
425
|
+
o === 1 ? r.push(c) : l.roundPrecision(t.lng, 8) === l.roundPrecision(c[0], 8) && l.roundPrecision(t.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,11 +435,11 @@ class P {
|
|
|
435
435
|
* @param waypoints
|
|
436
436
|
* @return [{lng, lat}]
|
|
437
437
|
*/
|
|
438
|
-
static calculateRangeWaypoints(
|
|
439
|
-
const
|
|
440
|
-
(d) => l.roundPrecision(e.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
441
|
-
), c = s.findIndex(
|
|
438
|
+
static calculateRangeWaypoints(t, e, n, i = []) {
|
|
439
|
+
const o = this.convertRouteToCoordinates(n, 0), s = this.mergeCoordinatesToWaypoints([t, e, ...i], o), r = s.findIndex(
|
|
442
440
|
(d) => l.roundPrecision(t.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(t.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
441
|
+
), c = s.findIndex(
|
|
442
|
+
(d) => l.roundPrecision(e.lng, 8) === l.roundPrecision(d.lng, 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(d.lat, 8)
|
|
443
443
|
);
|
|
444
444
|
return s.filter((d, u) => u >= r && u <= c);
|
|
445
445
|
}
|
|
@@ -448,14 +448,14 @@ class P {
|
|
|
448
448
|
* @param from
|
|
449
449
|
* @param route
|
|
450
450
|
*/
|
|
451
|
-
static calculateMinDistanceToRoute(
|
|
452
|
-
let n = Number.MAX_VALUE,
|
|
453
|
-
return
|
|
451
|
+
static calculateMinDistanceToRoute(t, e) {
|
|
452
|
+
let n = Number.MAX_VALUE, i = 0, o = 0;
|
|
453
|
+
return e.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] }, d = { lng: s[c + 1][0], lat: s[c + 1][1] }, u = this.calculatePointToLineDistance(
|
|
456
|
-
n > u && (n = u,
|
|
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(t, 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
|
* 计算子航线
|
|
@@ -463,21 +463,21 @@ class P {
|
|
|
463
463
|
* @param route [[[lng, lat]]] 剩余航线
|
|
464
464
|
* @return [[[lng, lat]]]
|
|
465
465
|
*/
|
|
466
|
-
static calculateSubRoute(
|
|
467
|
-
const { segIndex: n, minIndex:
|
|
468
|
-
|
|
469
|
-
const
|
|
466
|
+
static calculateSubRoute(t, e) {
|
|
467
|
+
const { segIndex: n, minIndex: i } = this.calculateMinDistanceToRoute({ ...t }, e);
|
|
468
|
+
t.lng = l.convertToStdLng(t.lng);
|
|
469
|
+
const o = [];
|
|
470
470
|
let s = !0;
|
|
471
|
-
for (let r = n; r <
|
|
471
|
+
for (let r = n; r < e.length; r++)
|
|
472
472
|
if (s) {
|
|
473
473
|
const c = [];
|
|
474
|
-
c.push([
|
|
475
|
-
for (let a =
|
|
476
|
-
|
|
477
|
-
|
|
474
|
+
c.push([t.lng, t.lat]);
|
|
475
|
+
for (let a = i + 1; a < e[r].length; a++)
|
|
476
|
+
t.lng === e[r][a][0] && t.lat === e[r][a][1] || c.push(e[r][a]);
|
|
477
|
+
o.push(c), s = !1;
|
|
478
478
|
} else
|
|
479
|
-
|
|
480
|
-
return
|
|
479
|
+
o.push([...e[r]]);
|
|
480
|
+
return o;
|
|
481
481
|
}
|
|
482
482
|
/**
|
|
483
483
|
* 计算子途经点
|
|
@@ -485,22 +485,22 @@ class P {
|
|
|
485
485
|
* @param waypoints [{lng, lat}]
|
|
486
486
|
* @return [{lng, lat}]
|
|
487
487
|
*/
|
|
488
|
-
static calculateSubWaypoints(
|
|
489
|
-
let n = Number.MAX_VALUE,
|
|
490
|
-
for (let s = 0; s <
|
|
491
|
-
const r =
|
|
492
|
-
if (this.calculateDistance(
|
|
493
|
-
return
|
|
494
|
-
if (this.calculateDistance(
|
|
495
|
-
return
|
|
496
|
-
const a = this.calculatePointToLineDistance(
|
|
497
|
-
n > a && (n = a,
|
|
488
|
+
static calculateSubWaypoints(t, e) {
|
|
489
|
+
let n = Number.MAX_VALUE, i = 0;
|
|
490
|
+
for (let s = 0; s < e.length - 1; s++) {
|
|
491
|
+
const r = e[s], c = e[s + 1];
|
|
492
|
+
if (this.calculateDistance(t, r) === 0)
|
|
493
|
+
return e;
|
|
494
|
+
if (this.calculateDistance(t, c) === 0)
|
|
495
|
+
return e.filter((d, u) => u > 0);
|
|
496
|
+
const a = this.calculatePointToLineDistance(t, r, c);
|
|
497
|
+
n > a && (n = a, i = s);
|
|
498
498
|
}
|
|
499
|
-
|
|
500
|
-
const
|
|
501
|
-
for (let s =
|
|
502
|
-
|
|
503
|
-
return
|
|
499
|
+
t.lng = l.convertToStdLng(t.lng);
|
|
500
|
+
const o = [t];
|
|
501
|
+
for (let s = i + 1; s < e.length; s++)
|
|
502
|
+
o.push(e[s]);
|
|
503
|
+
return o;
|
|
504
504
|
}
|
|
505
505
|
/**
|
|
506
506
|
* 计算坐标到以(from, to)横向线上的距离
|
|
@@ -509,14 +509,14 @@ class P {
|
|
|
509
509
|
* @param to { lng, lat }
|
|
510
510
|
* @param options
|
|
511
511
|
*/
|
|
512
|
-
static calculatePointToLineDistance(
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
512
|
+
static calculatePointToLineDistance(t, e, n, i = { units: "nauticalmiles", method: "geodesic" }) {
|
|
513
|
+
t.lng = l.convertToStdLng(t.lng), e = { ...e }, n = { ...n }, e.lng = l.convertToStdLng(e.lng, 8), n.lng = l.convertToStdLng(n.lng, 8);
|
|
514
|
+
const o = l.convertToMonotonicLng([e, n]);
|
|
515
|
+
e = o[0], n = o[1];
|
|
516
516
|
const s = g.lineString([
|
|
517
|
-
[
|
|
517
|
+
[e.lng, e.lat],
|
|
518
518
|
[n.lng, n.lat]
|
|
519
|
-
]), r = g.pointToLineDistance(g.point([
|
|
519
|
+
]), r = g.pointToLineDistance(g.point([t.lng, t.lat]), s, i), c = g.pointToLineDistance(g.point([t.lng > 0 ? t.lng - 360 : t.lng + 360, t.lat]), s, i);
|
|
520
520
|
return l.roundPrecision(Math.min(r, c), 6);
|
|
521
521
|
}
|
|
522
522
|
/**
|
|
@@ -524,23 +524,23 @@ class P {
|
|
|
524
524
|
* @param waypoints
|
|
525
525
|
* @param route
|
|
526
526
|
*/
|
|
527
|
-
static calculateWaypointsPropInRoute(
|
|
528
|
-
|
|
529
|
-
for (let n = 0; n <
|
|
530
|
-
const
|
|
531
|
-
n === 0 && (
|
|
527
|
+
static calculateWaypointsPropInRoute(t, e) {
|
|
528
|
+
e = this.mergeWaypointsToRoute(t, e);
|
|
529
|
+
for (let n = 0; n < t.length - 1; n++) {
|
|
530
|
+
const i = t[n], o = t[n + 1], s = this.calculateRangeRoute(i, o, e);
|
|
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
|
-
return
|
|
533
|
+
return t;
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
536
536
|
* @param coordinates [{lng, lat}]
|
|
537
537
|
* @param waypoints [{lng, lat}]
|
|
538
538
|
* @param replace true replace the same waypoint with coordinate
|
|
539
539
|
*/
|
|
540
|
-
static mergeCoordinatesToWaypoints(
|
|
541
|
-
for (const
|
|
542
|
-
this.mergeCoordinateToWaypoints(
|
|
543
|
-
return
|
|
540
|
+
static mergeCoordinatesToWaypoints(t, e, n = !0) {
|
|
541
|
+
for (const i of t)
|
|
542
|
+
this.mergeCoordinateToWaypoints(i, e, n);
|
|
543
|
+
return e;
|
|
544
544
|
}
|
|
545
545
|
/**
|
|
546
546
|
* 合并坐标进航路途经点
|
|
@@ -554,44 +554,44 @@ class P {
|
|
|
554
554
|
* @return
|
|
555
555
|
* [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: 179, lat: 50}, {lng: -170, lat: 40}, {lng: -160, lat: 30}]
|
|
556
556
|
*/
|
|
557
|
-
static mergeCoordinateToWaypoints(
|
|
558
|
-
|
|
559
|
-
let
|
|
560
|
-
for (let c = 0; c <
|
|
561
|
-
const a = { lng:
|
|
562
|
-
|
|
557
|
+
static mergeCoordinateToWaypoints(t, e, n = !0) {
|
|
558
|
+
t.lng = l.convertToStdLng(t.lng, 8);
|
|
559
|
+
let i = Number.MAX_VALUE, o = 0, s = 0, r = 0;
|
|
560
|
+
for (let c = 0; c < e.length - 1; c++) {
|
|
561
|
+
const a = { lng: e[c].lng, lat: e[c].lat }, d = { lng: e[c + 1].lng, lat: e[c + 1].lat }, u = this.calculatePointToLineDistance(t, a, d);
|
|
562
|
+
i >= u && (i = u, o = c, s = this.calculateDistance(a, t, !1, 6), r = this.calculateDistance(d, t, !1, 6));
|
|
563
563
|
}
|
|
564
|
-
return s !== 0 && r !== 0 ? s <
|
|
564
|
+
return s !== 0 && r !== 0 ? s < i || s === i && o === 0 ? e.unshift(t) : r < i || r === i && o === e.length - 2 ? e.push(t) : e.splice(o + 1, 0, t) : s === 0 ? n && e.splice(o, 1, t) : r === 0 && n && e.splice(o + 1, 1, t), e.map((c) => (c.lng = l.convertToStdLng(c.lng), c));
|
|
565
565
|
}
|
|
566
566
|
/**
|
|
567
567
|
* 生成航线(基于途经点生成大圆/横向航线,并根据是否跨180度分组)
|
|
568
568
|
* @param waypoints [{lng, lat}, {lng: lat, gcToPrevious: true}]
|
|
569
569
|
* @return [[[lng, lat], [lng, lat]]]
|
|
570
570
|
*/
|
|
571
|
-
static generateRouteAccordingToWaypoints(
|
|
572
|
-
const
|
|
573
|
-
for (let n = 1; n <
|
|
574
|
-
const
|
|
575
|
-
if (n === 1 &&
|
|
576
|
-
const s = this.interpolateCoordinates(
|
|
577
|
-
|
|
571
|
+
static generateRouteAccordingToWaypoints(t) {
|
|
572
|
+
const e = [];
|
|
573
|
+
for (let n = 1; n < t.length; n++) {
|
|
574
|
+
const i = t[n - 1], o = t[n];
|
|
575
|
+
if (n === 1 && e.push(i), o.gcToPrevious) {
|
|
576
|
+
const s = this.interpolateCoordinates(i, o, 200, !1, !0, "nauticalmiles");
|
|
577
|
+
e.push(...s);
|
|
578
578
|
} else
|
|
579
|
-
|
|
579
|
+
e.push(o);
|
|
580
580
|
}
|
|
581
|
-
return this.divideAccordingToLng(
|
|
581
|
+
return this.divideAccordingToLng(e, !0);
|
|
582
582
|
}
|
|
583
583
|
/**
|
|
584
584
|
* 最近点(从route中找出距离目标点最近的点)
|
|
585
585
|
* @param coordinate 目标点 {lng, lat}
|
|
586
586
|
* @param route [[[lng, lat]]]
|
|
587
587
|
*/
|
|
588
|
-
static nearestCoordinateInRoute(
|
|
589
|
-
const n = g.point([
|
|
590
|
-
for (const c of
|
|
588
|
+
static nearestCoordinateInRoute(t, e) {
|
|
589
|
+
const n = g.point([t.lng, t.lat]), i = [];
|
|
590
|
+
for (const c of e) {
|
|
591
591
|
const a = c.map((d) => g.point(d));
|
|
592
|
-
|
|
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
|
/**
|
|
@@ -599,21 +599,21 @@ class P {
|
|
|
599
599
|
* @param from
|
|
600
600
|
* @param waypoints
|
|
601
601
|
*/
|
|
602
|
-
static calculatePrevWaypoint(
|
|
602
|
+
static calculatePrevWaypoint(t, e) {
|
|
603
603
|
let n = 0;
|
|
604
|
-
this.mergeCoordinateToWaypoints(
|
|
605
|
-
for (let
|
|
606
|
-
const
|
|
607
|
-
if (this.calculateDistance(
|
|
608
|
-
n =
|
|
604
|
+
this.mergeCoordinateToWaypoints(t, e);
|
|
605
|
+
for (let i = 0; i < e.length - 1; i++) {
|
|
606
|
+
const o = e[i], s = e[i + 1];
|
|
607
|
+
if (this.calculateDistance(t, o) === 0) {
|
|
608
|
+
n = i;
|
|
609
609
|
break;
|
|
610
610
|
}
|
|
611
|
-
if (this.calculateDistance(
|
|
612
|
-
n =
|
|
611
|
+
if (this.calculateDistance(t, s) === 0) {
|
|
612
|
+
n = i + 1;
|
|
613
613
|
break;
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
|
-
return
|
|
616
|
+
return e[n === 0 ? 0 : n - 1];
|
|
617
617
|
}
|
|
618
618
|
/**
|
|
619
619
|
* 计算下一个距离单位的坐标及其子航线
|
|
@@ -623,38 +623,38 @@ class P {
|
|
|
623
623
|
* @param units
|
|
624
624
|
* @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
|
|
625
625
|
*/
|
|
626
|
-
static calculateNextCoordinateAlongRoute(
|
|
626
|
+
static calculateNextCoordinateAlongRoute(t, e, n, i = "nauticalmiles") {
|
|
627
627
|
var f;
|
|
628
|
-
const
|
|
628
|
+
const o = t.speed || 12, s = [];
|
|
629
629
|
let r = [], c = !1, a = 0, d = 0, u;
|
|
630
|
-
if (
|
|
630
|
+
if (e && n.length ? (s.push(t), n.forEach((h, C) => {
|
|
631
631
|
if (c)
|
|
632
632
|
r.push(h);
|
|
633
633
|
else {
|
|
634
634
|
const m = [];
|
|
635
635
|
let b;
|
|
636
|
-
for (let
|
|
636
|
+
for (let M = 0; M < h.length; M++)
|
|
637
637
|
if (u)
|
|
638
|
-
m.push(h[
|
|
638
|
+
m.push(h[M]);
|
|
639
639
|
else {
|
|
640
|
-
b = { lng: h[
|
|
641
|
-
const T = this.calculateDistance(
|
|
642
|
-
if (a += T, a <
|
|
643
|
-
d += T, s.push(b),
|
|
640
|
+
b = { lng: h[M][0], lat: h[M][1] };
|
|
641
|
+
const T = this.calculateDistance(t, b, !0, 8, i);
|
|
642
|
+
if (a += T, a < e)
|
|
643
|
+
d += T, s.push(b), t = b;
|
|
644
644
|
else {
|
|
645
|
-
if (d =
|
|
645
|
+
if (d = e, a === e)
|
|
646
646
|
u = b, m.push([u.lng, u.lat]);
|
|
647
647
|
else {
|
|
648
|
-
const p = a -
|
|
649
|
-
u = this.calculateCoordinate(b,
|
|
648
|
+
const p = a - e, N = this.calculateBearing(b, t);
|
|
649
|
+
u = this.calculateCoordinate(b, N, p, i), m.push([u.lng, u.lat]), m.push([b.lng, b.lat]);
|
|
650
650
|
}
|
|
651
651
|
c = !0;
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
|
-
m.length && r.push(m),
|
|
654
|
+
m.length && r.push(m), C === n.length - 1 && !u && (u = b);
|
|
655
655
|
}
|
|
656
|
-
})) : (r = n, u = { ...
|
|
657
|
-
if (s.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d /
|
|
656
|
+
})) : (r = n, u = { ...t }), 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
658
|
const h = { lng: r[0][1][0], lat: r[0][1][1] };
|
|
659
659
|
u.bearing = this.calculateBearing(u, h);
|
|
660
660
|
} else
|
|
@@ -667,35 +667,35 @@ class P {
|
|
|
667
667
|
* @param from {lng, lat}
|
|
668
668
|
* @param to {lng, lat}
|
|
669
669
|
*/
|
|
670
|
-
static nearestCoordinateInLine(
|
|
671
|
-
const
|
|
672
|
-
[s,
|
|
670
|
+
static nearestCoordinateInLine(t, e, n) {
|
|
671
|
+
const i = l.convertToStdLng(t.lng, 6), o = g.point([i, t.lat]), s = l.convertToStdLng(e.lng, 6), r = l.convertToStdLng(n.lng, 6), c = g.lineString([
|
|
672
|
+
[s, e.lat],
|
|
673
673
|
[r, n.lat]
|
|
674
|
-
]), a = g.nearestPointOnLine(c,
|
|
675
|
-
return { lng: u, lat: f, inline: !(u === s && f ===
|
|
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 === e.lat) && !(u === r && f === n.lat) };
|
|
676
676
|
}
|
|
677
677
|
/**
|
|
678
678
|
* 将route转coordinate
|
|
679
679
|
* @param route
|
|
680
680
|
* @param distance 临近点过虑
|
|
681
681
|
*/
|
|
682
|
-
static convertRouteToCoordinates(
|
|
682
|
+
static convertRouteToCoordinates(t, e = 0) {
|
|
683
683
|
const n = [];
|
|
684
|
-
let
|
|
685
|
-
return
|
|
684
|
+
let i, o;
|
|
685
|
+
return t.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 >=
|
|
693
|
+
const a = this.calculateDistance(i, c, !0);
|
|
694
|
+
a && a >= e && (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
|
* 抽稀(基于转向点)
|
|
@@ -703,45 +703,45 @@ class P {
|
|
|
703
703
|
* @param waypoints [{ lng, lat, gcToPrevious }]
|
|
704
704
|
* @param distance
|
|
705
705
|
*/
|
|
706
|
-
static simplifyRouteToCoordinates(
|
|
707
|
-
let
|
|
708
|
-
return
|
|
706
|
+
static simplifyRouteToCoordinates(t, e, n = 1) {
|
|
707
|
+
let i = this.convertRouteToCoordinates(t, n);
|
|
708
|
+
return i = this.simplifyGCCoordinates(i, e), i;
|
|
709
709
|
}
|
|
710
710
|
/**
|
|
711
711
|
* 基于大圆标识抽稀
|
|
712
712
|
* @param coordinates
|
|
713
713
|
* @param waypoints
|
|
714
714
|
*/
|
|
715
|
-
static simplifyGCCoordinates(
|
|
716
|
-
|
|
717
|
-
this.mergeCoordinateToWaypoints(
|
|
715
|
+
static simplifyGCCoordinates(t, e) {
|
|
716
|
+
e.forEach((i) => {
|
|
717
|
+
this.mergeCoordinateToWaypoints(i, t);
|
|
718
718
|
});
|
|
719
|
-
for (let
|
|
720
|
-
const
|
|
719
|
+
for (let i = 1; i < e.length; i++) {
|
|
720
|
+
const o = e[i - 1], s = e[i];
|
|
721
721
|
if (s.gcToPrevious) {
|
|
722
|
-
const r =
|
|
722
|
+
const r = t.findIndex((a) => a.lng === o.lng && a.lat === o.lat), c = t.findIndex((a) => a.lng === s.lng && a.lat === s.lat);
|
|
723
723
|
for (let a = c - 1; a > r; a--)
|
|
724
|
-
|
|
724
|
+
t.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 < t.length; i++) {
|
|
729
|
+
const o = t[i - 1], s = t[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
|
|
732
|
+
return t.map((i) => (i.lng = l.convertToStdLng(i.lng), i));
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
735
|
* 计算轨迹中心点
|
|
736
736
|
* @param route
|
|
737
737
|
*/
|
|
738
|
-
static calculateCenter(
|
|
739
|
-
const
|
|
740
|
-
for (const r of
|
|
738
|
+
static calculateCenter(t) {
|
|
739
|
+
const e = [];
|
|
740
|
+
for (const r of t)
|
|
741
741
|
for (const c of r)
|
|
742
|
-
|
|
743
|
-
const n = g.featureCollection([]),
|
|
744
|
-
for (const r of
|
|
742
|
+
e.push(c);
|
|
743
|
+
const n = g.featureCollection([]), i = l.convertToMonotonicLng2(e);
|
|
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) };
|
|
@@ -750,65 +750,70 @@ class P {
|
|
|
750
750
|
* 计算中心点
|
|
751
751
|
* @param coords
|
|
752
752
|
*/
|
|
753
|
-
static calculateCenter2(
|
|
754
|
-
const
|
|
755
|
-
return this.calculateCenter(
|
|
753
|
+
static calculateCenter2(t) {
|
|
754
|
+
const e = this.generateRouteAccordingToWaypoints(t);
|
|
755
|
+
return this.calculateCenter(e);
|
|
756
756
|
}
|
|
757
757
|
/**
|
|
758
758
|
* 计算BBox
|
|
759
759
|
* @param route
|
|
760
760
|
*/
|
|
761
|
-
static calculateBBox(
|
|
762
|
-
const
|
|
763
|
-
for (const
|
|
764
|
-
for (const s of
|
|
765
|
-
|
|
766
|
-
const n = l.convertToMonotonicLng2(
|
|
767
|
-
return g.bbox(
|
|
761
|
+
static calculateBBox(t) {
|
|
762
|
+
const e = [];
|
|
763
|
+
for (const o of t)
|
|
764
|
+
for (const s of o)
|
|
765
|
+
e.push(s);
|
|
766
|
+
const n = l.convertToMonotonicLng2(e), i = g.lineString(n);
|
|
767
|
+
return g.bbox(i);
|
|
768
768
|
}
|
|
769
769
|
/**
|
|
770
770
|
* 计算BBox
|
|
771
771
|
* @param coords
|
|
772
772
|
*/
|
|
773
|
-
static calculateBBox2(
|
|
774
|
-
const
|
|
775
|
-
return this.calculateBBox(
|
|
773
|
+
static calculateBBox2(t) {
|
|
774
|
+
const e = this.generateRouteAccordingToWaypoints(t);
|
|
775
|
+
return this.calculateBBox(e);
|
|
776
776
|
}
|
|
777
777
|
}
|
|
778
|
-
|
|
778
|
+
let P;
|
|
779
|
+
try {
|
|
780
|
+
P = L.getLogger("vessel");
|
|
781
|
+
} catch {
|
|
782
|
+
} finally {
|
|
783
|
+
}
|
|
779
784
|
class U {
|
|
780
785
|
/**
|
|
781
786
|
* 将原始数据转换为geojson
|
|
782
787
|
* @param raw
|
|
783
788
|
*/
|
|
784
|
-
static convert2Geojson(
|
|
789
|
+
static convert2Geojson(t) {
|
|
785
790
|
var n;
|
|
786
|
-
const
|
|
787
|
-
for (const
|
|
788
|
-
if (
|
|
789
|
-
const
|
|
790
|
-
for (const s of
|
|
791
|
-
const r = [], c =
|
|
792
|
-
if (
|
|
793
|
-
const d =
|
|
791
|
+
const e = g.featureCollection([]);
|
|
792
|
+
for (const i of t) {
|
|
793
|
+
if (i.forecasts) {
|
|
794
|
+
const o = (n = i.history) == null ? void 0 : n[0];
|
|
795
|
+
for (const s of i.forecasts) {
|
|
796
|
+
const r = [], c = D(s.date).utc(), a = `${i.name}-${s.model}`;
|
|
797
|
+
if (o) {
|
|
798
|
+
const d = D(o.updated).utc(), u = g.point([o.lng, o.lat], {
|
|
794
799
|
model: s.model,
|
|
795
|
-
name:
|
|
800
|
+
name: i.name,
|
|
796
801
|
date: d.format(),
|
|
797
802
|
hour: 0,
|
|
798
803
|
format: d.format("MMM-DD/HHmm[Z]"),
|
|
799
|
-
pressure:
|
|
800
|
-
wind: { kts:
|
|
804
|
+
pressure: o.pressure > 1e4 ? l.roundPrecision(o.pressure / 100, 0) : l.roundPrecision(o.pressure, 0),
|
|
805
|
+
wind: { kts: o.kts, spd: o.speed || o.spd },
|
|
801
806
|
category: a,
|
|
802
807
|
type: "forecast"
|
|
803
808
|
});
|
|
804
|
-
|
|
809
|
+
e.features.push(u), r.push(u.geometry.coordinates);
|
|
805
810
|
}
|
|
806
811
|
for (const d in s == null ? void 0 : s.hours) {
|
|
807
812
|
const u = s.hours[d];
|
|
808
813
|
u.wind.spd = u.wind.spd || u.wind.speed;
|
|
809
814
|
const f = c.clone().add(Number(d), "hour"), h = g.point([u.lng, u.lat], {
|
|
810
815
|
model: s.model,
|
|
811
|
-
name:
|
|
816
|
+
name: i.name,
|
|
812
817
|
date: f.format(),
|
|
813
818
|
hour: Number(d),
|
|
814
819
|
format: f.format("MMM-DD/HHmm[Z]"),
|
|
@@ -819,26 +824,26 @@ class U {
|
|
|
819
824
|
category: a,
|
|
820
825
|
type: "forecast"
|
|
821
826
|
});
|
|
822
|
-
|
|
827
|
+
e.features.push(h), r.push(h.geometry.coordinates);
|
|
823
828
|
}
|
|
824
829
|
if ((r == null ? void 0 : r.length) > 1) {
|
|
825
830
|
const d = g.lineString(l.convertToMonotonicLng2(r), {
|
|
826
831
|
date: s.date,
|
|
827
|
-
id:
|
|
832
|
+
id: i.id || i.name,
|
|
828
833
|
model: s.model,
|
|
829
|
-
name:
|
|
834
|
+
name: i.name,
|
|
830
835
|
category: a,
|
|
831
836
|
type: "forecast"
|
|
832
837
|
});
|
|
833
|
-
|
|
838
|
+
e.features.push(d);
|
|
834
839
|
}
|
|
835
840
|
}
|
|
836
841
|
}
|
|
837
|
-
if (
|
|
838
|
-
const
|
|
839
|
-
for (const r of
|
|
840
|
-
const c =
|
|
841
|
-
name:
|
|
842
|
+
if (i.history) {
|
|
843
|
+
const o = [];
|
|
844
|
+
for (const r of i.history) {
|
|
845
|
+
const c = D(r.updated).utc(), a = g.point([r.lng, r.lat], {
|
|
846
|
+
name: i.name,
|
|
842
847
|
date: c.format(),
|
|
843
848
|
format: c.format("MMM-DD/HHmm[Z]"),
|
|
844
849
|
pressure: r.pressure > 1e4 ? l.roundPrecision(r.pressure / 100, 0) : l.roundPrecision(r.pressure, 0),
|
|
@@ -847,14 +852,14 @@ class U {
|
|
|
847
852
|
source: r.source,
|
|
848
853
|
level: r.type,
|
|
849
854
|
type: "history",
|
|
850
|
-
category: `${
|
|
855
|
+
category: `${i.name}-history`
|
|
851
856
|
});
|
|
852
|
-
|
|
857
|
+
e.features.push(a), o.push(a.geometry.coordinates);
|
|
853
858
|
}
|
|
854
|
-
const s =
|
|
855
|
-
if (
|
|
856
|
-
const r = g.lineString(l.convertToMonotonicLng2(
|
|
857
|
-
name:
|
|
859
|
+
const s = i.history[0];
|
|
860
|
+
if (o.length === 1 && o.push(o[0]), o.length > 1) {
|
|
861
|
+
const r = g.lineString(l.convertToMonotonicLng2(o), {
|
|
862
|
+
name: i.name,
|
|
858
863
|
type: "history",
|
|
859
864
|
updated: s == null ? void 0 : s.updated,
|
|
860
865
|
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),
|
|
@@ -863,49 +868,49 @@ class U {
|
|
|
863
868
|
source: s == null ? void 0 : s.source,
|
|
864
869
|
level: s == null ? void 0 : s.type
|
|
865
870
|
});
|
|
866
|
-
|
|
871
|
+
e.features.push(r);
|
|
867
872
|
}
|
|
868
873
|
}
|
|
869
874
|
}
|
|
870
|
-
return
|
|
875
|
+
return e;
|
|
871
876
|
}
|
|
872
877
|
/**
|
|
873
878
|
* 插值台风预报轨迹
|
|
874
879
|
* @param tropicals
|
|
875
880
|
* @param step
|
|
876
881
|
*/
|
|
877
|
-
static interpolate(
|
|
878
|
-
var
|
|
879
|
-
const n = (
|
|
882
|
+
static interpolate(t, e = 3) {
|
|
883
|
+
var o, s, r, c;
|
|
884
|
+
const n = (o = t == null ? void 0 : t.data) == null ? void 0 : o.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), i = [];
|
|
880
885
|
for (const a of n) {
|
|
881
|
-
const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h =
|
|
882
|
-
let
|
|
883
|
-
const m = (s =
|
|
886
|
+
const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = D(a.properties.date).utc();
|
|
887
|
+
let C = e * 60 - (h.get("hour") * 60 + h.get("minute")) % (e * 60);
|
|
888
|
+
const m = (s = t == null ? void 0 : t.data) == null ? void 0 : s.features.filter(
|
|
884
889
|
(T) => T.geometry.type === "Point" && T.properties.type === "forecast" && T.properties.category === `${d}-${u}`
|
|
885
890
|
);
|
|
886
|
-
let b,
|
|
887
|
-
for (; b = this.pickIndex(m,
|
|
891
|
+
let b, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
892
|
+
for (; b = this.pickIndex(m, M), b <= m.length - 1; ) {
|
|
888
893
|
if (b > 0) {
|
|
889
|
-
const T = m[b], p = b === 0 ? void 0 : m[b - 1],
|
|
894
|
+
const T = m[b], p = b === 0 ? void 0 : m[b - 1], N = (C / 60 - ((r = p == null ? void 0 : p.properties) == null ? void 0 : r.hour)) / (T.properties.hour - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)), x = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], T.geometry.coordinates[0], N), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], T.geometry.coordinates[1], N), $ = g.point([x, I], {
|
|
890
895
|
name: d,
|
|
891
896
|
model: u,
|
|
892
897
|
category: T == null ? void 0 : T.properties.category,
|
|
893
|
-
date:
|
|
894
|
-
format:
|
|
895
|
-
gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, T.properties.gusts,
|
|
896
|
-
hour: this.computeNumber(p == null ? void 0 : p.properties.hour, T.properties.hour,
|
|
897
|
-
movement: this.computeNumber(p == null ? void 0 : p.properties.movement, T.properties.movement,
|
|
898
|
-
pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, T.properties.pressure,
|
|
899
|
-
wind: this.computeNumber(p == null ? void 0 : p.properties.wind, T.properties.wind,
|
|
898
|
+
date: M.format(),
|
|
899
|
+
format: M.format("MMM-DD/HHmm[Z]"),
|
|
900
|
+
gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, T.properties.gusts, N),
|
|
901
|
+
hour: this.computeNumber(p == null ? void 0 : p.properties.hour, T.properties.hour, N),
|
|
902
|
+
movement: this.computeNumber(p == null ? void 0 : p.properties.movement, T.properties.movement, N),
|
|
903
|
+
pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, T.properties.pressure, N),
|
|
904
|
+
wind: this.computeNumber(p == null ? void 0 : p.properties.wind, T.properties.wind, N),
|
|
900
905
|
type: "forecast",
|
|
901
906
|
showCircle: f
|
|
902
907
|
});
|
|
903
|
-
|
|
908
|
+
i.push($);
|
|
904
909
|
}
|
|
905
|
-
|
|
910
|
+
C += e * 60, M = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
906
911
|
}
|
|
907
912
|
}
|
|
908
|
-
return
|
|
913
|
+
return i;
|
|
909
914
|
}
|
|
910
915
|
/**
|
|
911
916
|
* 计算最佳绕航点
|
|
@@ -918,22 +923,22 @@ class U {
|
|
|
918
923
|
* @param speed 前进速度
|
|
919
924
|
* @param options
|
|
920
925
|
*/
|
|
921
|
-
static diversionPassageAt(
|
|
922
|
-
const { t1:
|
|
923
|
-
if (
|
|
924
|
-
const a =
|
|
926
|
+
static diversionPassageAt(t, e, n, i = {}) {
|
|
927
|
+
const { t1: o, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, i);
|
|
928
|
+
if (o && s) {
|
|
929
|
+
const a = S.calculateBearing(t, o), d = S.calculateBearing(o, s), u = Math.abs(a - d);
|
|
925
930
|
let f = 0;
|
|
926
931
|
u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
|
|
927
|
-
const h =
|
|
928
|
-
return
|
|
929
|
-
from:
|
|
930
|
-
t1:
|
|
932
|
+
const h = S.calculateCoordinate(o, f, n);
|
|
933
|
+
return P == null || P.info("[%s] the right tangent position: %j", i.requestId, {
|
|
934
|
+
from: t,
|
|
935
|
+
t1: o,
|
|
931
936
|
t2: s,
|
|
932
937
|
radius: n,
|
|
933
938
|
bearing1: a,
|
|
934
939
|
bearing2: d,
|
|
935
940
|
right: h
|
|
936
|
-
}), { at: h, t1:
|
|
941
|
+
}), { at: h, t1: o, t2: s, hr: Number(r), hours: c };
|
|
937
942
|
}
|
|
938
943
|
return {};
|
|
939
944
|
}
|
|
@@ -947,13 +952,13 @@ class U {
|
|
|
947
952
|
* @param radius 与台风中心的距离
|
|
948
953
|
* @param options
|
|
949
954
|
*/
|
|
950
|
-
static driftPassageAt(
|
|
951
|
-
const { t1:
|
|
952
|
-
if (
|
|
953
|
-
const a =
|
|
954
|
-
return { at:
|
|
955
|
+
static driftPassageAt(t, e, n, i = {}) {
|
|
956
|
+
const { t1: o, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(e, 24, i);
|
|
957
|
+
if (o && s) {
|
|
958
|
+
const a = S.calculateBearing(t, o), d = S.calculateBearing(o, s), u = S.calculateDistance(t, o);
|
|
959
|
+
return { at: S.calculateCoordinate(o, a - d + 180, n < u ? n : u), t1: o, t2: s, hr: Number(r), hours: c };
|
|
955
960
|
} else
|
|
956
|
-
return
|
|
961
|
+
return P == null || P.info("[%s] no need drift: %j", i.requestId, { from: t, t1: o, t2: s, hr: r }), {};
|
|
957
962
|
}
|
|
958
963
|
/**
|
|
959
964
|
* 获取台风中心点对
|
|
@@ -962,50 +967,50 @@ class U {
|
|
|
962
967
|
* @param options
|
|
963
968
|
* @private
|
|
964
969
|
*/
|
|
965
|
-
static tropicalCenterTwin(
|
|
966
|
-
var d, u, f, h,
|
|
967
|
-
let
|
|
968
|
-
(d =
|
|
969
|
-
|
|
970
|
+
static tropicalCenterTwin(t, e = 24, n = {}) {
|
|
971
|
+
var d, u, f, h, C;
|
|
972
|
+
let i = {};
|
|
973
|
+
(d = t.forecasts) == null || d.forEach((m) => {
|
|
974
|
+
i = { ...m.hours, ...i };
|
|
970
975
|
});
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
let s = (h = Object.keys(
|
|
974
|
-
s || (s = (
|
|
975
|
-
const r =
|
|
976
|
-
|
|
977
|
-
const c = Object.keys(
|
|
976
|
+
const o = ((u = t == null ? void 0 : t.history) == null ? void 0 : u[0]) || (i == null ? void 0 : i[(f = Object.keys(i)) == null ? void 0 : f[0]]);
|
|
977
|
+
P == null || P.info("[%s] the first tropical center: %j", n.requestId, o);
|
|
978
|
+
let s = (h = Object.keys(i || {}).filter((m) => Number(m) <= (e < 0 ? 24 : e))) == null ? void 0 : h.at(-1);
|
|
979
|
+
s || (s = (C = Object.keys(i || {}).filter((m) => Number(m) <= (e < 0 ? 24 : 2 * e))) == null ? void 0 : C.at(-1));
|
|
980
|
+
const r = i == null ? void 0 : i[s || -1];
|
|
981
|
+
P == null || P.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, s);
|
|
982
|
+
const c = Object.keys(i || {}).filter((m) => Number(m) <= Number(s)), a = { 0: o };
|
|
978
983
|
for (const m of c)
|
|
979
|
-
a[m] =
|
|
980
|
-
return { t1:
|
|
984
|
+
a[m] = i[m];
|
|
985
|
+
return { t1: o, t2: r, hr: s, hours: a };
|
|
981
986
|
}
|
|
982
|
-
static pickIndex(
|
|
987
|
+
static pickIndex(t, e) {
|
|
983
988
|
let n = 0;
|
|
984
|
-
for (const
|
|
985
|
-
if (
|
|
989
|
+
for (const i of t) {
|
|
990
|
+
if (D(i.properties.date).isAfter(e))
|
|
986
991
|
return n === 0 ? -1 : n;
|
|
987
992
|
n++;
|
|
988
993
|
}
|
|
989
994
|
return n;
|
|
990
995
|
}
|
|
991
|
-
static computeNumber(
|
|
992
|
-
if (
|
|
993
|
-
if (
|
|
994
|
-
if (isNaN(
|
|
995
|
-
const
|
|
996
|
-
for (const
|
|
997
|
-
o
|
|
998
|
-
return
|
|
996
|
+
static computeNumber(t, e, n) {
|
|
997
|
+
if (t)
|
|
998
|
+
if (e) {
|
|
999
|
+
if (isNaN(t) && isNaN(e) && typeof t != "string" && typeof e != "string") {
|
|
1000
|
+
const i = {};
|
|
1001
|
+
for (const o in t)
|
|
1002
|
+
i[o] = this.computeNumber(t[o], e[o], n);
|
|
1003
|
+
return i;
|
|
999
1004
|
}
|
|
1000
|
-
return Math.round((
|
|
1005
|
+
return Math.round((t + (e - t) * n) * 100) / 100;
|
|
1001
1006
|
} else
|
|
1002
|
-
return
|
|
1007
|
+
return t;
|
|
1003
1008
|
else
|
|
1004
|
-
return
|
|
1009
|
+
return e;
|
|
1005
1010
|
}
|
|
1006
1011
|
}
|
|
1007
1012
|
export {
|
|
1008
|
-
|
|
1013
|
+
S as LaneHelper,
|
|
1009
1014
|
l as LngLatHelper,
|
|
1010
1015
|
U as TropicalHelper
|
|
1011
1016
|
};
|