@idm-plugin/geo 1.2.6 → 1.2.7

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 CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as g from "@turf/turf";
2
- import D from "moment";
2
+ import N from "moment";
3
3
  import "moment-timezone";
4
4
  import W from "tz-lookup";
5
- function E(b) {
6
- return b && b.__esModule && Object.prototype.hasOwnProperty.call(b, "default") ? b.default : b;
5
+ function E(v) {
6
+ return v && v.__esModule && Object.prototype.hasOwnProperty.call(v, "default") ? v.default : v;
7
7
  }
8
8
  class R {
9
9
  log() {
@@ -18,9 +18,9 @@ class R {
18
18
  clearContext() {
19
19
  }
20
20
  }
21
- ["Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Mark"].forEach((b) => {
22
- R.prototype[b.toLowerCase()] = () => {
23
- }, R.prototype[`is${b}Enabled`] = () => !1;
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
25
  const k = () => {
26
26
  try {
@@ -40,8 +40,8 @@ class l {
40
40
  * @param lat
41
41
  */
42
42
  static guessTimeZoneOffset(e, t) {
43
- const n = W(t, e), i = D().tz(n).utcOffset();
44
- return this.roundPrecision(i / 60, 1);
43
+ const n = W(t, e), o = N().tz(n).utcOffset();
44
+ return this.roundPrecision(o / 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 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 p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${i}`;
57
+ let o = "E";
58
+ e < 0 && (o = "W"), e = Math.abs(e), n = n.toUpperCase();
59
+ let i = e * 3600, s, r, c, a, d, u;
60
+ s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), d = i / 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)}${o}`;
62
62
  return {
63
- direction: i,
63
+ direction: o,
64
64
  degree: l.roundPrecision(d, t),
65
65
  minute: l.roundPrecision(c, t),
66
66
  second: l.roundPrecision(s, t),
67
- pretty: p
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 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 p = `${n.replace(/S+/gi, r).replace(/M+/gi, a).replace(/H+/gi, u)}${i}`;
78
+ let o = "N";
79
+ e < 0 && (o = "S"), e = Math.abs(e), n = n.toUpperCase();
80
+ let i = e * 3600, s, r, c, a, d, u;
81
+ s = i % 3600 % 60, n.indexOf("S") !== -1 && (i = i - s, r = l.padNumber(s, 2, 2)), c = i / 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), i = i - c * 60), d = i / 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)}${o}`;
83
83
  return {
84
- direction: i,
84
+ direction: o,
85
85
  degree: l.roundPrecision(d, t),
86
86
  minute: l.roundPrecision(c, t),
87
87
  second: l.roundPrecision(s, t),
88
- pretty: p
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 i = e[e.length - 1].toUpperCase();
95
+ const o = e[e.length - 1].toUpperCase();
96
96
  e = e.substring(0, e.length - 1).trim();
97
- const o = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
98
- let [s, r] = o;
97
+ const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
98
+ let [s, r] = i;
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, i === "W" && (n = n * -1);
103
+ n = s + (r ?? 0) / 60, o === "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 i = e[e.length - 1].toUpperCase();
112
+ const o = e[e.length - 1].toUpperCase();
113
113
  e = e.substring(0, e.length - 1).trim();
114
- const o = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
115
- let [s, r] = o;
114
+ const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
115
+ let [s, r] = i;
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, i === "S" && (n = n * -1);
120
+ n = s + (r ?? 0) / 60, o === "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 i = e[e.length - 1].toUpperCase();
128
- return ["N", "S"].includes(i) ? {
127
+ const o = e[e.length - 1].toUpperCase();
128
+ return ["N", "S"].includes(o) ? {
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 i = e, o = Number(i.split(" ")[0]);
167
- if (isNaN(o))
166
+ const o = e, i = Number(o.split(" ")[0]);
167
+ if (isNaN(i))
168
168
  throw new Error(`invalid Lat/Lng: ${e}`);
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"}`;
169
+ i >= 90 ? e = `${o}E` : i <= -90 ? e = `${o}W` : ["LAN", "LNG"].includes(t == null ? void 0 : t.toUpperCase()) ? e = `${o}${i > 0 ? "E" : "W"}` : e = `${o}${i > 0 ? "N" : "S"}`;
170
170
  }
171
171
  return e;
172
172
  }
@@ -178,8 +178,8 @@ class l {
178
178
  * @param dcmPrecision 小数位数
179
179
  */
180
180
  static padNumber(e, t = 2, n = 2) {
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}`;
181
+ const o = Math.trunc(e).toString().padStart(t, "0"), i = Math.trunc(l.roundPrecision(e - Math.trunc(e), n) * Math.pow(10, n)).toString().padStart(n, "0");
182
+ return `${o}.${i}`;
183
183
  }
184
184
  }
185
185
  class P {
@@ -191,13 +191,13 @@ class P {
191
191
  * @param precision
192
192
  * @returns {number} 单位度
193
193
  */
194
- static calculateBearing(e, t, n = !0, i = 4) {
195
- const o = g.points([
194
+ static calculateBearing(e, t, n = !0, o = 4) {
195
+ const i = 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(o.features[0], o.features[1]) : s = g.bearing(o.features[0], o.features[1]), s < 0 && (s += 360), l.roundPrecision(s, i);
200
+ return n ? s = g.rhumbBearing(i.features[0], i.features[1]) : s = g.bearing(i.features[0], i.features[1]), s < 0 && (s += 360), l.roundPrecision(s, o);
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(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);
211
+ static calculateDistance(e, t, n = !0, o = 4, i = "nauticalmiles") {
212
+ e = { ...e }, t = { ...t }, e.lng = l.convertToStdLng(e.lng, o), t.lng = l.convertToStdLng(t.lng, o);
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: o }) : r = g.distance(s.features[0], s.features[1], { units: o }), l.roundPrecision(r, i);
218
+ return n ? r = g.rhumbDistance(s.features[0], s.features[1], { units: i }) : r = g.distance(s.features[0], s.features[1], { units: i }), l.roundPrecision(r, o);
219
219
  }
220
220
  /**
221
221
  * 计算航线距离
@@ -224,15 +224,15 @@ class P {
224
224
  * @param units
225
225
  */
226
226
  static calculateRouteDistance(e, t = 4, n = "nauticalmiles") {
227
- let i = 0, o;
227
+ let o = 0, i;
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 && o && (i += this.calculateDistance(o, c, !0, t, n));
231
+ r === 0 && i && (o += this.calculateDistance(i, c, !0, t, n));
232
232
  const a = { lng: s[r + 1][0], lat: s[r + 1][1] };
233
- i += this.calculateDistance(c, a, !0, t, n), o = a;
233
+ o += this.calculateDistance(c, a, !0, t, n), i = a;
234
234
  }
235
- return l.roundPrecision(i, t);
235
+ return l.roundPrecision(o, t);
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(e, t, n, i = "nauticalmiles", o = !0) {
245
+ static calculateCoordinate(e, t, n, o = "nauticalmiles", i = !0) {
246
246
  const s = g.point([e.lng, e.lat]);
247
247
  let r;
248
- o ? r = g.rhumbDestination(s, n, t, { units: i }) : r = g.destination(s, n, t, { units: i });
248
+ i ? r = g.rhumbDestination(s, n, t, { units: o }) : r = g.destination(s, n, t, { units: o });
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(e, t, n, i = !0, o = !0, s = "nauticalmiles") {
261
+ static interpolateCoordinates(e, t, n, o = !0, i = !0, s = "nauticalmiles") {
262
262
  const r = [], c = this.calculateBearing(e, t, !1), a = this.calculateDistance(e, t, !1, 8, s);
263
- i && r.push({ lng: e.lng, lat: e.lat });
263
+ o && r.push({ lng: e.lng, lat: e.lat });
264
264
  let d = 0;
265
265
  for (; d < a; )
266
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;
267
+ return i && r.push({ lng: t.lng, lat: t.lat }), r;
268
268
  }
269
269
  /**
270
270
  * 分组坐标(如相邻两个坐标经度差超180度,需以180为界将坐标分为两组)
@@ -282,14 +282,14 @@ class P {
282
282
  return [];
283
283
  e = this.deduplicateCoordinates(e);
284
284
  let n = [];
285
- const i = [];
286
- let o, s;
285
+ const o = [];
286
+ let i, s;
287
287
  for (let r = 0; r < e.length - 1; r++) {
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;
288
+ i = l.convertToStdLng(e[r].lng, 8), s = l.convertToStdLng(e[r + 1].lng, 8), n.push([i, e[r].lat]);
289
+ const c = i - s;
290
290
  if (Math.abs(c) > 180) {
291
291
  const a = l.convertToMonotonicLng2([
292
- [o, e[r].lat],
292
+ [i, e[r].lat],
293
293
  [s, e[r + 1].lat]
294
294
  ]);
295
295
  let d, u;
@@ -297,18 +297,18 @@ class P {
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
- const p = g.lineIntersect(d, u);
300
+ const f = g.lineIntersect(d, u);
301
301
  let h;
302
- if (p.features.length) {
303
- const C = g.getCoord(p.features[0]);
304
- h = l.roundPrecision(C[1], 8);
302
+ if (f.features.length) {
303
+ const S = g.getCoord(f.features[0]);
304
+ h = l.roundPrecision(S[1], 8);
305
305
  } else
306
306
  h = e[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]));
307
+ c > 0 ? (n.push([180 - 1e-6, h]), o.push([...n]), n = [], n.push([-(180 - 1e-6), h])) : (n.push([-(180 - 1e-6), h]), o.push([...n]), n = [], n.push([180 - 1e-6, h]));
308
308
  }
309
309
  r === e.length - 2 && n.push([s, e[r + 1].lat]);
310
310
  }
311
- return i.push(n), i;
311
+ return o.push(n), o;
312
312
  }
313
313
  /**
314
314
  * 去除重复坐标
@@ -317,8 +317,8 @@ class P {
317
317
  static deduplicateRoute(e) {
318
318
  const t = [];
319
319
  for (const n of e) {
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);
320
+ const o = n.reduce((i, s) => (i.findIndex((r) => r[0] === s[0] && r[1] === s[1]) === -1 && i.push(s), i), []);
321
+ t.push(o);
322
322
  }
323
323
  return t;
324
324
  }
@@ -327,7 +327,7 @@ class P {
327
327
  * @param coordinates
328
328
  */
329
329
  static deduplicateCoordinates(e) {
330
- return e.reduce((t, n) => (t.findIndex((i) => i.lat === n.lat && i.lng === n.lng) === -1 && t.push(n), t), []);
330
+ return e.reduce((t, n) => (t.findIndex((o) => o.lat === n.lat && o.lng === n.lng) === -1 && t.push(n), t), []);
331
331
  }
332
332
  /**
333
333
  * 移出坐标
@@ -337,8 +337,8 @@ class P {
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 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);
340
+ for (let o = n.length - 1; o >= 0; o--)
341
+ l.roundPrecision(n[o][0], 8) === e.lng && l.roundPrecision(n[o][1], 8) === l.roundPrecision(e.lat, 8) && n.splice(o, 1);
342
342
  return t;
343
343
  }
344
344
  /**
@@ -365,13 +365,13 @@ class P {
365
365
  */
366
366
  static mergeCoordinateToRoute(e, t) {
367
367
  e.lng = l.convertToStdLng(e.lng, 8);
368
- let n = Number.MAX_VALUE, i = 0, o = 0, s, r;
368
+ let n = Number.MAX_VALUE, o = 0, i = 0, s, r;
369
369
  return t.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] }, p = { lng: c[d + 1][0], lat: c[d + 1][1] }, h = this.calculatePointToLineDistance(e, u, p);
372
- n > h && (n = h, o = d, i = a, s = this.calculateDistance(u, e), r = this.calculateDistance(p, e));
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(e, u, f);
372
+ n > h && (n = h, i = d, o = a, s = this.calculateDistance(u, e), r = this.calculateDistance(f, e));
373
373
  }
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;
374
+ }), s !== 0 && r !== 0 ? t[o].splice(i + 1, 0, [e.lng, e.lat]) : s === 0 ? t[o].splice(i, 1, [e.lng, e.lat]) : r === 0 && t[o].splice(i + 1, 1, [e.lng, e.lat]), t;
375
375
  }
376
376
  /**
377
377
  * 向Route尾加1个坐标
@@ -411,21 +411,21 @@ class P {
411
411
  */
412
412
  static calculateRangeRoute(e, t, n) {
413
413
  n = this.mergeWaypointsToRoute([e, t], n);
414
- const i = [];
415
- let o = 0;
414
+ const o = [];
415
+ let i = 0;
416
416
  return n.forEach((s) => {
417
- if (o === 2)
417
+ if (i === 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), o === 0 && r.push([e.lng, e.lat]), o = 2;
422
+ r.push(c), i === 0 && r.push([e.lng, e.lat]), i = 2;
423
423
  break;
424
424
  }
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));
425
+ i === 1 ? r.push(c) : l.roundPrecision(e.lng, 8) === l.roundPrecision(c[0], 8) && l.roundPrecision(e.lat, 8) === l.roundPrecision(c[1], 8) && (i = 1, r.push(c));
426
426
  }
427
- r.length && i.push(r);
428
- }), i;
427
+ r.length && o.push(r);
428
+ }), o;
429
429
  }
430
430
  /**
431
431
  * 计算from到to之间的航线
@@ -435,8 +435,8 @@ class P {
435
435
  * @param waypoints
436
436
  * @return [{lng, lat}]
437
437
  */
438
- static calculateRangeWaypoints(e, t, n, i = []) {
439
- const o = this.convertRouteToCoordinates(n, 0), s = this.mergeCoordinatesToWaypoints([e, t, ...i], o), r = s.findIndex(
438
+ static calculateRangeWaypoints(e, t, n, o = []) {
439
+ const i = this.convertRouteToCoordinates(n, 0), s = this.mergeCoordinatesToWaypoints([e, t, ...o], i), r = s.findIndex(
440
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)
@@ -449,13 +449,13 @@ class P {
449
449
  * @param route
450
450
  */
451
451
  static calculateMinDistanceToRoute(e, t) {
452
- let n = Number.MAX_VALUE, i = 0, o = 0;
452
+ let n = Number.MAX_VALUE, o = 0, i = 0;
453
453
  return t.forEach((s, r) => {
454
454
  for (let c = 0; c < s.length - 1; c++) {
455
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);
456
+ n > u && (n = u, o = c, i = r);
457
457
  }
458
- }), { minDist: n, segIndex: o, minIndex: i };
458
+ }), { minDist: n, segIndex: i, minIndex: o };
459
459
  }
460
460
  /**
461
461
  * 计算子航线
@@ -464,20 +464,20 @@ class P {
464
464
  * @return [[[lng, lat]]]
465
465
  */
466
466
  static calculateSubRoute(e, t) {
467
- const { segIndex: n, minIndex: i } = this.calculateMinDistanceToRoute({ ...e }, t);
467
+ const { segIndex: n, minIndex: o } = this.calculateMinDistanceToRoute({ ...e }, t);
468
468
  e.lng = l.convertToStdLng(e.lng);
469
- const o = [];
469
+ const i = [];
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 = i + 1; a < t[r].length; a++)
475
+ for (let a = o + 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
- o.push(c), s = !1;
477
+ i.push(c), s = !1;
478
478
  } else
479
- o.push([...t[r]]);
480
- return o;
479
+ i.push([...t[r]]);
480
+ return i;
481
481
  }
482
482
  /**
483
483
  * 计算子途经点
@@ -486,7 +486,7 @@ class P {
486
486
  * @return [{lng, lat}]
487
487
  */
488
488
  static calculateSubWaypoints(e, t) {
489
- let n = Number.MAX_VALUE, i = 0;
489
+ let n = Number.MAX_VALUE, o = 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)
@@ -494,13 +494,13 @@ class P {
494
494
  if (this.calculateDistance(e, c) === 0)
495
495
  return t.filter((d, u) => u > 0);
496
496
  const a = this.calculatePointToLineDistance(e, r, c);
497
- n > a && (n = a, i = s);
497
+ n > a && (n = a, o = s);
498
498
  }
499
499
  e.lng = l.convertToStdLng(e.lng);
500
- const o = [e];
501
- for (let s = i + 1; s < t.length; s++)
502
- o.push(t[s]);
503
- return o;
500
+ const i = [e];
501
+ for (let s = o + 1; s < t.length; s++)
502
+ i.push(t[s]);
503
+ return i;
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(e, t, n, i = { units: "nauticalmiles", method: "geodesic" }) {
512
+ static calculatePointToLineDistance(e, t, n, o = { 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 o = l.convertToMonotonicLng([t, n]);
515
- t = o[0], n = o[1];
514
+ const i = l.convertToMonotonicLng([t, n]);
515
+ t = i[0], n = i[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, i), c = g.pointToLineDistance(g.point([e.lng > 0 ? e.lng - 360 : e.lng + 360, e.lat]), s, i);
519
+ ]), r = g.pointToLineDistance(g.point([e.lng, e.lat]), s, o), c = g.pointToLineDistance(g.point([e.lng > 0 ? e.lng - 360 : e.lng + 360, e.lat]), s, o);
520
520
  return l.roundPrecision(Math.min(r, c), 6);
521
521
  }
522
522
  /**
@@ -527,8 +527,8 @@ class P {
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 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);
530
+ const o = e[n], i = e[n + 1], s = this.calculateRangeRoute(o, i, t);
531
+ n === 0 && (o.distanceFromPrevious = 0, o.distanceFromStart = 0), i.distanceFromPrevious = this.calculateRouteDistance(s), i.distanceFromStart = l.roundPrecision((o.distanceFromStart || 0) + i.distanceFromPrevious);
532
532
  }
533
533
  return e;
534
534
  }
@@ -538,8 +538,8 @@ class P {
538
538
  * @param replace true replace the same waypoint with coordinate
539
539
  */
540
540
  static mergeCoordinatesToWaypoints(e, t, n = !0) {
541
- for (const i of e)
542
- this.mergeCoordinateToWaypoints(i, t, n);
541
+ for (const o of e)
542
+ this.mergeCoordinateToWaypoints(o, t, n);
543
543
  return t;
544
544
  }
545
545
  /**
@@ -556,12 +556,12 @@ class P {
556
556
  */
557
557
  static mergeCoordinateToWaypoints(e, t, n = !0) {
558
558
  e.lng = l.convertToStdLng(e.lng, 8);
559
- let i = Number.MAX_VALUE, o = 0, s = 0, r = 0;
559
+ let o = Number.MAX_VALUE, i = 0, s = 0, r = 0;
560
560
  for (let c = 0; c < t.length - 1; c++) {
561
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));
562
+ o >= u && (o = u, i = c, s = this.calculateDistance(a, e, !1, 6), r = this.calculateDistance(d, e, !1, 6));
563
563
  }
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));
564
+ return s !== 0 && r !== 0 ? s < o || s === o && i === 0 ? t.unshift(e) : r < o || r === o && i === t.length - 2 ? t.push(e) : t.splice(i + 1, 0, e) : s === 0 ? n && t.splice(i, 1, e) : r === 0 && n && t.splice(i + 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 P {
571
571
  static generateRouteAccordingToWaypoints(e) {
572
572
  const t = [];
573
573
  for (let n = 1; n < e.length; n++) {
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");
574
+ const o = e[n - 1], i = e[n];
575
+ if (n === 1 && t.push(o), i.gcToPrevious) {
576
+ const s = this.interpolateCoordinates(o, i, 200, !1, !0, "nauticalmiles");
577
577
  t.push(...s);
578
578
  } else
579
- t.push(o);
579
+ t.push(i);
580
580
  }
581
581
  return this.divideAccordingToLng(t, !0);
582
582
  }
@@ -586,12 +586,12 @@ class P {
586
586
  * @param route [[[lng, lat]]]
587
587
  */
588
588
  static nearestCoordinateInRoute(e, t) {
589
- const n = g.point([e.lng, e.lat]), i = [];
589
+ const n = g.point([e.lng, e.lat]), o = [];
590
590
  for (const c of t) {
591
591
  const a = c.map((d) => g.point(d));
592
- i.push(...a);
592
+ o.push(...a);
593
593
  }
594
- const o = g.featureCollection(i), s = g.nearestPoint(n, o), r = g.getCoord(s);
594
+ const i = g.featureCollection(o), s = g.nearestPoint(n, i), r = g.getCoord(s);
595
595
  return { lng: r[0], lat: r[1] };
596
596
  }
597
597
  /**
@@ -602,14 +602,14 @@ class P {
602
602
  static calculatePrevWaypoint(e, t) {
603
603
  let n = 0;
604
604
  this.mergeCoordinateToWaypoints(e, t);
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;
605
+ for (let o = 0; o < t.length - 1; o++) {
606
+ const i = t[o], s = t[o + 1];
607
+ if (this.calculateDistance(e, i) === 0) {
608
+ n = o;
609
609
  break;
610
610
  }
611
611
  if (this.calculateDistance(e, s) === 0) {
612
- n = i + 1;
612
+ n = o + 1;
613
613
  break;
614
614
  }
615
615
  }
@@ -623,38 +623,38 @@ class P {
623
623
  * @param units
624
624
  * @return { coordinate: {lng, lat}, route: [[[lng, lat]]]}
625
625
  */
626
- static calculateNextCoordinateAlongRoute(e, t, n, i = "nauticalmiles") {
627
- var p;
628
- const o = e.speed || 12, s = [];
626
+ static calculateNextCoordinateAlongRoute(e, t, n, o = "nauticalmiles") {
627
+ var f;
628
+ const i = e.speed || 12, s = [];
629
629
  let r = [], c = !1, a = 0, d = 0, u;
630
- if (t && n.length ? (s.push(e), n.forEach((h, C) => {
630
+ if (t && n.length ? (s.push(e), n.forEach((h, S) => {
631
631
  if (c)
632
632
  r.push(h);
633
633
  else {
634
- const v = [];
635
- let T;
636
- for (let S = 0; S < h.length; S++)
634
+ const m = [];
635
+ let b;
636
+ for (let C = 0; C < h.length; C++)
637
637
  if (u)
638
- v.push(h[S]);
638
+ m.push(h[C]);
639
639
  else {
640
- T = { lng: h[S][0], lat: h[S][1] };
641
- const m = this.calculateDistance(e, T, !0, 8, i);
642
- if (a += m, a < t)
643
- d += m, s.push(T), e = T;
640
+ b = { lng: h[C][0], lat: h[C][1] };
641
+ const T = this.calculateDistance(e, b, !0, 8, o);
642
+ if (a += T, a < t)
643
+ d += T, s.push(b), e = b;
644
644
  else {
645
645
  if (d = t, a === t)
646
- u = T, v.push([u.lng, u.lat]);
646
+ u = b, m.push([u.lng, u.lat]);
647
647
  else {
648
- const f = a - t, M = this.calculateBearing(T, e);
649
- u = this.calculateCoordinate(T, M, f, i), v.push([u.lng, u.lat]), v.push([T.lng, T.lat]);
648
+ const p = a - t, M = this.calculateBearing(b, e);
649
+ u = this.calculateCoordinate(b, M, p, o), m.push([u.lng, u.lat]), m.push([b.lng, b.lat]);
650
650
  }
651
651
  c = !0;
652
652
  }
653
653
  }
654
- v.length && r.push(v), C === n.length - 1 && !u && (u = T);
654
+ m.length && r.push(m), S === n.length - 1 && !u && (u = b);
655
655
  }
656
656
  })) : (r = n, u = { ...e }), u)
657
- if (s.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / o * 1e4) / 1e4, ((p = r[0]) == null ? void 0 : p.length) > 1) {
657
+ if (s.push(u), u.distanceFromPrevious = d, u.hourFromPrevious = Math.round(d / i * 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
@@ -668,11 +668,11 @@ class P {
668
668
  * @param to {lng, lat}
669
669
  */
670
670
  static nearestCoordinateInLine(e, t, n) {
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([
671
+ const o = l.convertToStdLng(e.lng, 6), i = g.point([o, 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, o), d = g.getCoord(a), u = l.roundPrecision(d[0], 6), p = l.roundPrecision(d[1], 6);
675
- return { lng: u, lat: p, inline: !(u === s && p === t.lat) && !(u === r && p === n.lat) };
674
+ ]), a = g.nearestPointOnLine(c, i), 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 P {
681
681
  */
682
682
  static convertRouteToCoordinates(e, t = 0) {
683
683
  const n = [];
684
- let i, o;
684
+ let o, i;
685
685
  return e.forEach((s) => {
686
686
  s.forEach((r) => {
687
687
  const c = { lng: r[0], lat: r[1] };
688
- if (!o)
689
- n.push(c), o = c;
690
- else if (o.bearing === void 0)
691
- o.bearing = this.calculateBearing(o, c, !0);
688
+ if (!i)
689
+ n.push(c), i = c;
690
+ else if (i.bearing === void 0)
691
+ i.bearing = this.calculateBearing(i, c, !0);
692
692
  else {
693
- const a = this.calculateDistance(i, c, !0);
694
- a && a >= t && (i.bearing = this.calculateBearing(i, c, !0), n.push(i), o = i);
693
+ const a = this.calculateDistance(o, c, !0);
694
+ a && a >= t && (o.bearing = this.calculateBearing(o, c, !0), n.push(o), i = o);
695
695
  }
696
- i = c;
696
+ o = c;
697
697
  });
698
- }), i && n.push(i), n;
698
+ }), o && n.push(o), n;
699
699
  }
700
700
  /**
701
701
  * 抽稀(基于转向点)
@@ -704,8 +704,8 @@ class P {
704
704
  * @param distance
705
705
  */
706
706
  static simplifyRouteToCoordinates(e, t, n = 1) {
707
- let i = this.convertRouteToCoordinates(e, n);
708
- return i = this.simplifyGCCoordinates(i, t), i;
707
+ let o = this.convertRouteToCoordinates(e, n);
708
+ return o = this.simplifyGCCoordinates(o, t), o;
709
709
  }
710
710
  /**
711
711
  * 基于大圆标识抽稀
@@ -713,23 +713,23 @@ class P {
713
713
  * @param waypoints
714
714
  */
715
715
  static simplifyGCCoordinates(e, t) {
716
- t.forEach((i) => {
717
- this.mergeCoordinateToWaypoints(i, e);
716
+ t.forEach((o) => {
717
+ this.mergeCoordinateToWaypoints(o, e);
718
718
  });
719
- for (let i = 1; i < t.length; i++) {
720
- const o = t[i - 1], s = t[i];
719
+ for (let o = 1; o < t.length; o++) {
720
+ const i = t[o - 1], s = t[o];
721
721
  if (s.gcToPrevious) {
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);
722
+ const r = e.findIndex((a) => a.lng === i.lng && a.lat === i.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 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;
728
+ for (let o = 1; o < e.length; o++) {
729
+ const i = e[o - 1], s = e[o];
730
+ s.gcToPrevious ? (i.bearing = this.calculateBearing(i, s, !1), s.distanceFromPrevious = this.calculateDistance(i, s, !1)) : (i.bearing = this.calculateBearing(i, s, !0), s.distanceFromPrevious = this.calculateDistance(i, s, !0)), n = l.roundPrecision(n + s.distanceFromPrevious), s.distanceFromStart = n;
731
731
  }
732
- return e.map((i) => (i.lng = l.convertToStdLng(i.lng), i));
732
+ return e.map((o) => (o.lng = l.convertToStdLng(o.lng), o));
733
733
  }
734
734
  /**
735
735
  * 计算轨迹中心点
@@ -740,8 +740,8 @@ class P {
740
740
  for (const r of e)
741
741
  for (const c of r)
742
742
  t.push(c);
743
- const n = g.featureCollection([]), i = l.convertToMonotonicLng2(t);
744
- for (const r of i)
743
+ const n = g.featureCollection([]), o = l.convertToMonotonicLng2(t);
744
+ for (const r of o)
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 P {
760
760
  */
761
761
  static calculateBBox(e) {
762
762
  const t = [];
763
- for (const o of e)
764
- for (const s of o)
763
+ for (const i of e)
764
+ for (const s of i)
765
765
  t.push(s);
766
- const n = l.convertToMonotonicLng2(t), i = g.lineString(n);
767
- return g.bbox(i);
766
+ const n = l.convertToMonotonicLng2(t), o = g.lineString(n);
767
+ return g.bbox(o);
768
768
  }
769
769
  /**
770
770
  * 计算BBox
@@ -775,7 +775,7 @@ class P {
775
775
  return this.calculateBBox(t);
776
776
  }
777
777
  }
778
- const N = L.getLogger("vessel");
778
+ const D = L.getLogger("vessel");
779
779
  class U {
780
780
  /**
781
781
  * 将原始数据转换为geojson
@@ -784,20 +784,20 @@ class U {
784
784
  static convert2Geojson(e) {
785
785
  var n;
786
786
  const t = g.featureCollection([]);
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], {
787
+ for (const o of e) {
788
+ if (o.forecasts) {
789
+ const i = (n = o.history) == null ? void 0 : n[0];
790
+ for (const s of o.forecasts) {
791
+ const r = [], c = N(s.date).utc(), a = `${o.name}-${s.model}`;
792
+ if (i) {
793
+ const d = N(i.updated).utc(), u = g.point([i.lng, i.lat], {
794
794
  model: s.model,
795
- name: i.name,
795
+ name: o.name,
796
796
  date: d.format(),
797
797
  hour: 0,
798
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 },
799
+ pressure: i.pressure > 1e4 ? l.roundPrecision(i.pressure / 100, 0) : l.roundPrecision(i.pressure, 0),
800
+ wind: { kts: i.kts, spd: i.speed || i.spd },
801
801
  category: a,
802
802
  type: "forecast"
803
803
  });
@@ -806,12 +806,12 @@ class U {
806
806
  for (const d in s == null ? void 0 : s.hours) {
807
807
  const u = s.hours[d];
808
808
  u.wind.spd = u.wind.spd || u.wind.speed;
809
- const p = c.clone().add(Number(d), "hour"), h = g.point([u.lng, u.lat], {
809
+ const f = c.clone().add(Number(d), "hour"), h = g.point([u.lng, u.lat], {
810
810
  model: s.model,
811
- name: i.name,
812
- date: p.format(),
811
+ name: o.name,
812
+ date: f.format(),
813
813
  hour: Number(d),
814
- format: p.format("MMM-DD/HHmm[Z]"),
814
+ format: f.format("MMM-DD/HHmm[Z]"),
815
815
  pressure: u.pressure > 1e4 ? l.roundPrecision(u.pressure / 100, 0) : l.roundPrecision(u.pressure, 0),
816
816
  gusts: u.gusts,
817
817
  wind: u.wind || {},
@@ -824,9 +824,9 @@ class U {
824
824
  if ((r == null ? void 0 : r.length) > 1) {
825
825
  const d = g.lineString(l.convertToMonotonicLng2(r), {
826
826
  date: s.date,
827
- id: i.id || i.name,
827
+ id: o.id || o.name,
828
828
  model: s.model,
829
- name: i.name,
829
+ name: o.name,
830
830
  category: a,
831
831
  type: "forecast"
832
832
  });
@@ -834,11 +834,11 @@ class U {
834
834
  }
835
835
  }
836
836
  }
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,
837
+ if (o.history) {
838
+ const i = [];
839
+ for (const r of o.history) {
840
+ const c = N(r.updated).utc(), a = g.point([r.lng, r.lat], {
841
+ name: o.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 U {
847
847
  source: r.source,
848
848
  level: r.type,
849
849
  type: "history",
850
- category: `${i.name}-history`
850
+ category: `${o.name}-history`
851
851
  });
852
- t.features.push(a), o.push(a.geometry.coordinates);
852
+ t.features.push(a), i.push(a.geometry.coordinates);
853
853
  }
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,
854
+ const s = o.history[0];
855
+ if (i.length === 1 && i.push(i[0]), i.length > 1) {
856
+ const r = g.lineString(l.convertToMonotonicLng2(i), {
857
+ name: o.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,37 +875,37 @@ class U {
875
875
  * @param step
876
876
  */
877
877
  static interpolate(e, t = 3) {
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 = [];
878
+ var i, s, r, c;
879
+ const n = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), o = [];
880
880
  for (const a of n) {
881
- const d = a.properties.name, u = a.properties.model, p = a.properties.showCircle, h = D(a.properties.date).utc();
882
- let C = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
883
- const v = (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}`
881
+ const d = a.properties.name, u = a.properties.model, f = a.properties.showCircle, h = N(a.properties.date).utc();
882
+ let S = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
883
+ const m = (s = e == null ? void 0 : e.data) == null ? void 0 : s.features.filter(
884
+ (T) => T.geometry.type === "Point" && T.properties.type === "forecast" && T.properties.category === `${d}-${u}`
885
885
  );
886
- let T, S = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
887
- for (; T = this.pickIndex(v, S), T <= v.length - 1; ) {
888
- if (T > 0) {
889
- const m = v[T], f = T === 0 ? void 0 : v[T - 1], M = (C / 60 - ((r = f == null ? void 0 : f.properties) == null ? void 0 : r.hour)) / (m.properties.hour - ((c = f == null ? void 0 : f.properties) == null ? void 0 : c.hour)), I = this.computeNumber(f == null ? void 0 : f.geometry.coordinates[0], m.geometry.coordinates[0], M), x = this.computeNumber(f == null ? void 0 : f.geometry.coordinates[1], m.geometry.coordinates[1], M), $ = g.point([I, x], {
886
+ let b, C = h.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
887
+ for (; b = this.pickIndex(m, C), b <= m.length - 1; ) {
888
+ if (b > 0) {
889
+ const T = m[b], p = b === 0 ? void 0 : m[b - 1], M = (S / 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)), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], T.geometry.coordinates[0], M), x = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], T.geometry.coordinates[1], M), $ = g.point([I, x], {
890
890
  name: d,
891
891
  model: u,
892
- category: m == null ? void 0 : m.properties.category,
893
- date: S.format(),
894
- format: S.format("MMM-DD/HHmm[Z]"),
895
- gusts: this.computeNumber(f == null ? void 0 : f.properties.gusts, m.properties.gusts, M),
896
- hour: this.computeNumber(f == null ? void 0 : f.properties.hour, m.properties.hour, M),
897
- movement: this.computeNumber(f == null ? void 0 : f.properties.movement, m.properties.movement, M),
898
- pressure: this.computeNumber(f == null ? void 0 : f.properties.pressure, m.properties.pressure, M),
899
- wind: this.computeNumber(f == null ? void 0 : f.properties.wind, m.properties.wind, M),
892
+ category: T == null ? void 0 : T.properties.category,
893
+ date: C.format(),
894
+ format: C.format("MMM-DD/HHmm[Z]"),
895
+ gusts: this.computeNumber(p == null ? void 0 : p.properties.gusts, T.properties.gusts, M),
896
+ hour: this.computeNumber(p == null ? void 0 : p.properties.hour, T.properties.hour, M),
897
+ movement: this.computeNumber(p == null ? void 0 : p.properties.movement, T.properties.movement, M),
898
+ pressure: this.computeNumber(p == null ? void 0 : p.properties.pressure, T.properties.pressure, M),
899
+ wind: this.computeNumber(p == null ? void 0 : p.properties.wind, T.properties.wind, M),
900
900
  type: "forecast",
901
- showCircle: p
901
+ showCircle: f
902
902
  });
903
- i.push($);
903
+ o.push($);
904
904
  }
905
- C += t * 60, S = h.clone().add(C, "minute").set({ minute: 0, second: 0, millisecond: 0 });
905
+ S += t * 60, C = h.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
906
906
  }
907
907
  }
908
- return i;
908
+ return o;
909
909
  }
910
910
  /**
911
911
  * 计算最佳绕航点
@@ -918,23 +918,24 @@ class U {
918
918
  * @param speed 前进速度
919
919
  * @param options
920
920
  */
921
- static diversionPassageAt(e, t, n, i = { requestId: "" }) {
922
- const { t1: o, t2: s, hr: r } = this.tropicalCenterTwin(t, 24, i);
923
- if (o && s) {
924
- const c = P.calculateBearing(e, o), a = P.calculateBearing(o, s), d = Math.abs(c - a);
925
- let u = 0;
926
- d < 180 ? u = d + 90 : d >= 180 && (u = d - 90);
927
- const p = P.calculateCoordinate(o, u, n);
928
- return N.info("[%s] the right tangent position: %j", i.requestId, {
921
+ static diversionPassageAt(e, t, n, o = { requestId: "" }) {
922
+ const { t1: i, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(t, 24, o);
923
+ if (i && s) {
924
+ const a = P.calculateBearing(e, i), d = P.calculateBearing(i, s), u = Math.abs(a - d);
925
+ let f = 0;
926
+ u < 180 ? f = u + 90 : u >= 180 && (f = u - 90);
927
+ const h = P.calculateCoordinate(i, f, n);
928
+ return D.info("[%s] the right tangent position: %j", o.requestId, {
929
929
  from: e,
930
- t1: o,
930
+ t1: i,
931
931
  t2: s,
932
932
  radius: n,
933
- bearing1: c,
934
- bearing2: a,
935
- right: p
936
- }), p;
933
+ bearing1: a,
934
+ bearing2: d,
935
+ right: h
936
+ }), { at: h, t1: i, t2: s, hr: Number(r), hours: c };
937
937
  }
938
+ return {};
938
939
  }
939
940
  /**
940
941
  * 计算最佳漂航点
@@ -946,15 +947,13 @@ class U {
946
947
  * @param radius 与台风中心的距离
947
948
  * @param options
948
949
  */
949
- static driftPassageAt(e, t, n, i = { requestId: "" }) {
950
- const { t1: o, t2: s, hr: r } = this.tropicalCenterTwin(t, 24, i);
951
- if (o && s) {
952
- const c = P.calculateBearing(e, o), a = P.calculateBearing(o, s), d = P.calculateDistance(e, o);
953
- return P.calculateCoordinate(o, c - a + 180, n < d ? n : d);
954
- } else {
955
- N.info("[%s] no need drift: %j", i.requestId, { from: e, t1: o, t2: s });
956
- return;
957
- }
950
+ static driftPassageAt(e, t, n, o = { requestId: "" }) {
951
+ const { t1: i, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(t, 24, o);
952
+ if (i && s) {
953
+ const a = P.calculateBearing(e, i), d = P.calculateBearing(i, s), u = P.calculateDistance(e, i);
954
+ return { at: P.calculateCoordinate(i, a - d + 180, n < u ? n : u), t1: i, t2: s, hr: Number(r), hours: c };
955
+ } else
956
+ return D.info("[%s] no need drift: %j", o.requestId, { from: e, t1: i, t2: s, hr: r }), {};
958
957
  }
959
958
  /**
960
959
  * 获取台风中心点对
@@ -964,22 +963,26 @@ class U {
964
963
  * @private
965
964
  */
966
965
  static tropicalCenterTwin(e, t = 24, n = { requestId: "" }) {
967
- var c, a, d, u, p;
968
- let i = {};
969
- (c = e.forecasts) == null || c.forEach((h) => {
970
- i = { ...h.hours, ...i };
966
+ var d, u, f, h, S;
967
+ let o = {};
968
+ (d = e.forecasts) == null || d.forEach((m) => {
969
+ o = { ...m.hours, ...o };
971
970
  });
972
- const o = ((a = e == null ? void 0 : e.history) == null ? void 0 : a[0]) || (i == null ? void 0 : i[(d = Object.keys(i)) == null ? void 0 : d[0]]);
973
- N.info("[%s] the first tropical center: %j", n.requestId, o);
974
- let s = (u = Object.keys(i || {}).filter((h) => Number(h) <= (t < 0 ? 24 : t))) == null ? void 0 : u.at(-1);
975
- s || (s = (p = Object.keys(i || {}).filter((h) => Number(h) <= (t < 0 ? 24 : 2 * t))) == null ? void 0 : p.at(-1));
976
- const r = i == null ? void 0 : i[s || -1];
977
- return N.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, s), { t1: o, t2: r, hr: s };
971
+ const i = ((u = e == null ? void 0 : e.history) == null ? void 0 : u[0]) || (o == null ? void 0 : o[(f = Object.keys(o)) == null ? void 0 : f[0]]);
972
+ D.info("[%s] the first tropical center: %j", n.requestId, i);
973
+ let s = (h = Object.keys(o || {}).filter((m) => Number(m) <= (t < 0 ? 24 : t))) == null ? void 0 : h.at(-1);
974
+ s || (s = (S = Object.keys(o || {}).filter((m) => Number(m) <= (t < 0 ? 24 : 2 * t))) == null ? void 0 : S.at(-1));
975
+ const r = o == null ? void 0 : o[s || -1];
976
+ D.info("[%s] the second tropical center: %j in %d hrs", n.requestId, r, s);
977
+ const c = Object.keys(o || {}).filter((m) => Number(m) <= Number(s)), a = { 0: i };
978
+ for (const m of c)
979
+ a[m] = o[m];
980
+ return { t1: i, t2: r, hr: s, hours: a };
978
981
  }
979
982
  static pickIndex(e, t) {
980
983
  let n = 0;
981
- for (const i of e) {
982
- if (D(i.properties.date).isAfter(t))
984
+ for (const o of e) {
985
+ if (N(o.properties.date).isAfter(t))
983
986
  return n === 0 ? -1 : n;
984
987
  n++;
985
988
  }
@@ -989,10 +992,10 @@ class U {
989
992
  if (e)
990
993
  if (t) {
991
994
  if (isNaN(e) && isNaN(t) && typeof e != "string" && typeof t != "string") {
992
- const i = {};
993
- for (const o in e)
994
- i[o] = this.computeNumber(e[o], t[o], n);
995
- return i;
995
+ const o = {};
996
+ for (const i in e)
997
+ o[i] = this.computeNumber(e[i], t[i], n);
998
+ return o;
996
999
  }
997
1000
  return Math.round((e + (t - e) * n) * 100) / 100;
998
1001
  } else
@@ -1 +1 @@
1
- (function(v,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],y):(v=typeof globalThis<"u"?globalThis:v||self,y(v["idm-plugin-rabbitmq"]={},v["@turf/turf"],v.moment,v["moment-timezone"],v["tz-lookup"]))})(this,function(v,y,N,B,$){"use strict";function k(T){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const t in T)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(T,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>T[t]})}}return e.default=T,Object.freeze(e)}const g=k(y);function L(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}class I{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(T=>{I.prototype[T.toLowerCase()]=()=>{},I.prototype[`is${T}Enabled`]=()=>!1});const x=(()=>{try{return require("log4js")}catch{return null}})();var W={getLogger:x?x.getLogger:()=>new I};const j=L(W);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),o=N().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/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),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,i,r,c,a,d,u;i=s%3600%60,n.indexOf("S")!==-1&&(s=s-i,r=l.padNumber(i,2,2)),c=s/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),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:p}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){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();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,s=Number(o.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${o}E`:s<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${s>0?"E":"W"}`:e=`${o}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${s}`}}class P{static calculateBearing(e,t,n=!0,o=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(s.features[0],s.features[1]):i=g.bearing(s.features[0],s.features[1]),i<0&&(i+=360),l.roundPrecision(i,o)}static calculateDistance(e,t,n=!0,o=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:s}):r=g.distance(i.features[0],i.features[1],{units:s}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,s;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&s&&(o+=this.calculateDistance(s,c,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};o+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",s=!0){const i=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(i,n,t,{units:o}):r=g.destination(i,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,s=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,i,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let s,i;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),n.push([s,e[r].lat]);const c=s-i;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[i,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(d,u);let f;if(p.features.length){const M=g.getCoord(p.features[0]);f=l.roundPrecision(M[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),o.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),o.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([i,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((s,i)=>(s.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&s.push(i),s),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,s=0,i,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},p={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,p);n>f&&(n=f,s=d,o=a,i=this.calculateDistance(u,e),r=this.calculateDistance(p,e))}}),i!==0&&r!==0?t[o].splice(s+1,0,[e.lng,e.lat]):i===0?t[o].splice(s,1,[e.lng,e.lat]):r===0&&t[o].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=P.convertRouteToCoordinates(t);return n.push(e),P.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=P.convertRouteToCoordinates(t);return n.unshift(e),P.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let s=0;return n.forEach(i=>{if(s===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const s=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...o],s),r=i.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=i.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return i.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,s=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const a={lng:i[c][0],lat:i[c][1]},d={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,o=c,s=r)}}),{minDist:n,segIndex:s,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let i=!0;for(let r=n;r<t.length;r++)if(i){const c=[];c.push([e.lng,e.lat]);for(let a=o+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),i=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,o=i)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let i=o+1;i<t.length;i++)s.push(t[i]);return s}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],s=e[n+1],i=this.calculateRangeRoute(o,s,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(i),s.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,s=0,i=0,r=0;for(let c=0;c<t.length-1;c++){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);o>=u&&(o=u,s=c,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return i!==0&&r!==0?i<o||i===o&&s===0?t.unshift(e):r<o||r===o&&s===t.length-2?t.push(e):t.splice(s+1,0,e):i===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],s=e[n];if(n===1&&t.push(o),s.gcToPrevious){const i=this.interpolateCoordinates(o,s,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const a=c.map(d=>g.point(d));o.push(...a)}const s=g.featureCollection(o),i=g.nearestPoint(n,s),r=g.getCoord(i);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const s=t[o],i=t[o+1];if(this.calculateDistance(e,s)===0){n=o;break}if(this.calculateDistance(e,i)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var p;const s=e.speed||12,i=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(i.push(e),n.forEach((f,M)=>{if(c)r.push(f);else{const S=[];let b;for(let C=0;C<f.length;C++)if(u)S.push(f[C]);else{b={lng:f[C][0],lat:f[C][1]};const m=this.calculateDistance(e,b,!0,8,o);if(a+=m,a<t)d+=m,i.push(b),e=b;else{if(d=t,a===t)u=b,S.push([u.lng,u.lat]);else{const h=a-t,D=this.calculateBearing(b,e);u=this.calculateCoordinate(b,D,h,o),S.push([u.lng,u.lat]),S.push([b.lng,b.lat])}c=!0}}S.length&&r.push(S),M===n.length-1&&!u&&(u=b)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),s=g.point([o,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),p=l.roundPrecision(d[1],6);return{lng:u,lat:p,inline:!(u===i&&p===t.lat)&&!(u===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,s;return e.forEach(i=>{i.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(o,c,!0);a&&a>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),s=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e)});for(let o=1;o<t.length;o++){const s=t[o-1],i=t[o];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let o=1;o<e.length;o++){const s=e[o-1],i=e[o];i.gcToPrevious?(s.bearing=this.calculateBearing(s,i,!1),i.distanceFromPrevious=this.calculateDistance(s,i,!1)):(s.bearing=this.calculateBearing(s,i,!0),i.distanceFromPrevious=this.calculateDistance(s,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const i of s)t.push(i);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}const R=j.getLogger("vessel");class O{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const s=(n=o.history)==null?void 0:n[0];for(const i of o.forecasts){const r=[],c=N(i.date).utc(),a=`${o.name}-${i.model}`;if(s){const d=N(s.updated).utc(),u=g.point([s.lng,s.lat],{model:i.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in i==null?void 0:i.hours){const u=i.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const p=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:i.model,name:o.name,date:p.format(),hour:Number(d),format:p.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:a,type:"forecast"});t.features.push(d)}}}if(o.history){const s=[];for(const r of o.history){const c=N(r.updated).utc(),a=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const i=o.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:o.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,i,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),o=[];for(const a of n){const d=a.properties.name,u=a.properties.model,p=a.properties.showCircle,f=N(a.properties.date).utc();let M=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const S=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${d}-${u}`);let b,C=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;b=this.pickIndex(S,C),b<=S.length-1;){if(b>0){const m=S[b],h=b===0?void 0:S[b-1],D=(M/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)),E=this.computeNumber(h==null?void 0:h.geometry.coordinates[0],m.geometry.coordinates[0],D),F=this.computeNumber(h==null?void 0:h.geometry.coordinates[1],m.geometry.coordinates[1],D),A=g.point([E,F],{name:d,model:u,category:m==null?void 0:m.properties.category,date:C.format(),format:C.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(h==null?void 0:h.properties.gusts,m.properties.gusts,D),hour:this.computeNumber(h==null?void 0:h.properties.hour,m.properties.hour,D),movement:this.computeNumber(h==null?void 0:h.properties.movement,m.properties.movement,D),pressure:this.computeNumber(h==null?void 0:h.properties.pressure,m.properties.pressure,D),wind:this.computeNumber(h==null?void 0:h.properties.wind,m.properties.wind,D),type:"forecast",showCircle:p});o.push(A)}M+=t*60,C=f.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o={requestId:""}){const{t1:s,t2:i,hr:r}=this.tropicalCenterTwin(t,24,o);if(s&&i){const c=P.calculateBearing(e,s),a=P.calculateBearing(s,i),d=Math.abs(c-a);let u=0;d<180?u=d+90:d>=180&&(u=d-90);const p=P.calculateCoordinate(s,u,n);return R.info("[%s] the right tangent position: %j",o.requestId,{from:e,t1:s,t2:i,radius:n,bearing1:c,bearing2:a,right:p}),p}}static driftPassageAt(e,t,n,o={requestId:""}){const{t1:s,t2:i,hr:r}=this.tropicalCenterTwin(t,24,o);if(s&&i){const c=P.calculateBearing(e,s),a=P.calculateBearing(s,i),d=P.calculateDistance(e,s);return P.calculateCoordinate(s,c-a+180,n<d?n:d)}else{R.info("[%s] no need drift: %j",o.requestId,{from:e,t1:s,t2:i});return}}static tropicalCenterTwin(e,t=24,n={requestId:""}){var c,a,d,u,p;let o={};(c=e.forecasts)==null||c.forEach(f=>{o={...f.hours,...o}});const s=((a=e==null?void 0:e.history)==null?void 0:a[0])||(o==null?void 0:o[(d=Object.keys(o))==null?void 0:d[0]]);R.info("[%s] the first tropical center: %j",n.requestId,s);let i=(u=Object.keys(o||{}).filter(f=>Number(f)<=(t<0?24:t)))==null?void 0:u.at(-1);i||(i=(p=Object.keys(o||{}).filter(f=>Number(f)<=(t<0?24:2*t)))==null?void 0:p.at(-1));const r=o==null?void 0:o[i||-1];return R.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i),{t1:s,t2:r,hr:i}}static pickIndex(e,t){let n=0;for(const o of e){if(N(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const s in e)o[s]=this.computeNumber(e[s],t[s],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}v.LaneHelper=P,v.LngLatHelper=l,v.TropicalHelper=O,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
1
+ (function(S,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("@turf/turf"),require("moment"),require("moment-timezone"),require("tz-lookup")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","moment-timezone","tz-lookup"],y):(S=typeof globalThis<"u"?globalThis:S||self,y(S["idm-plugin-rabbitmq"]={},S["@turf/turf"],S.moment,S["moment-timezone"],S["tz-lookup"]))})(this,function(S,y,N,B,$){"use strict";function k(P){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(P){for(const t in P)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(P,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>P[t]})}}return e.default=P,Object.freeze(e)}const g=k(y);function j(P){return P&&P.__esModule&&Object.prototype.hasOwnProperty.call(P,"default")?P.default:P}class I{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(P=>{I.prototype[P.toLowerCase()]=()=>{},I.prototype[`is${P}Enabled`]=()=>!1});const x=(()=>{try{return require("log4js")}catch{return null}})();var L={getLogger:x?x.getLogger:()=>new I};const O=j(L);class l{static guessTimeZoneOffset(e,t){const n=$(t,e),i=N().tz(n).utcOffset();return this.roundPrecision(i/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let i="E";e<0&&(i="W"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,o,r,c,a,d,u;o=s%3600%60,n.indexOf("S")!==-1&&(s=s-o,r=l.padNumber(o,2,2)),c=s/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),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(3,"0"):u=l.padNumber(d,3,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${i}`;return{direction:i,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(o,t),pretty:h}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let i="N";e<0&&(i="S"),e=Math.abs(e),n=n.toUpperCase();let s=e*3600,o,r,c,a,d,u;o=s%3600%60,n.indexOf("S")!==-1&&(s=s-o,r=l.padNumber(o,2,2)),c=s/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),s=s-c*60),d=s/3600,n.indexOf("M")!==-1?u=l.roundPrecision(d,t).toString().padStart(2,"0"):u=l.padNumber(d,2,2);const h=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${i}`;return{direction:i,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(o,t),pretty:h}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[o,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,o>360&&!r){const c=this.roundPrecision(o/100,0);r=o-c*100,o=c}n=o+(r??0)/60,i==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const s=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[o,r]=s;if(r=r>60?r/Math.pow(10,String(r).length-2):r,o>90&&!r){const c=this.roundPrecision(o/100,0);r=o-c*100,o=c}n=o+(r??0)/60,i==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const i=e[e.length-1].toUpperCase();return["N","S"].includes(i)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){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();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const i=e,s=Number(i.split(" ")[0]);if(isNaN(s))throw new Error(`invalid Lat/Lng: ${e}`);s>=90?e=`${i}E`:s<=-90?e=`${i}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${i}${s>0?"E":"W"}`:e=`${i}${s>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const i=Math.trunc(e).toString().padStart(t,"0"),s=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${i}.${s}`}}class v{static calculateBearing(e,t,n=!0,i=4){const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let o;return n?o=g.rhumbBearing(s.features[0],s.features[1]):o=g.bearing(s.features[0],s.features[1]),o<0&&(o+=360),l.roundPrecision(o,i)}static calculateDistance(e,t,n=!0,i=4,s="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,i),t.lng=l.convertToStdLng(t.lng,i);const o=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(o.features[0],o.features[1],{units:s}):r=g.distance(o.features[0],o.features[1],{units:s}),l.roundPrecision(r,i)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let i=0,s;for(const o of e)for(let r=0;r<o.length-1;r++){const c={lng:o[r][0],lat:o[r][1]};r===0&&s&&(i+=this.calculateDistance(s,c,!0,t,n));const a={lng:o[r+1][0],lat:o[r+1][1]};i+=this.calculateDistance(c,a,!0,t,n),s=a}return l.roundPrecision(i,t)}static calculateCoordinate(e,t,n,i="nauticalmiles",s=!0){const o=g.point([e.lng,e.lat]);let r;s?r=g.rhumbDestination(o,n,t,{units:i}):r=g.destination(o,n,t,{units:i});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,i=!0,s=!0,o="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,o);i&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<a;)d+=n,d<a&&r.push(this.calculateCoordinate(e,c,d,o,!1));return s&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const i=[];let s,o;for(let r=0;r<e.length-1;r++){s=l.convertToStdLng(e[r].lng,8),o=l.convertToStdLng(e[r+1].lng,8),n.push([s,e[r].lat]);const c=s-o;if(Math.abs(c)>180){const a=l.convertToMonotonicLng2([[s,e[r].lat],[o,e[r+1].lat]]);let d,u;t?(d=g.lineString(a),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(a[0],a[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const h=g.lineIntersect(d,u);let f;if(h.features.length){const C=g.getCoord(h.features[0]);f=l.roundPrecision(C[1],8)}else f=e[r].lat;c>0?(n.push([180-1e-6,f]),i.push([...n]),n=[],n.push([-(180-1e-6),f])):(n.push([-(180-1e-6),f]),i.push([...n]),n=[],n.push([180-1e-6,f]))}r===e.length-2&&n.push([o,e[r+1].lat])}return i.push(n),i}static deduplicateRoute(e){const t=[];for(const n of e){const i=n.reduce((s,o)=>(s.findIndex(r=>r[0]===o[0]&&r[1]===o[1])===-1&&s.push(o),s),[]);t.push(i)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(i=>i.lat===n.lat&&i.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let i=n.length-1;i>=0;i--)l.roundPrecision(n[i][0],8)===e.lng&&l.roundPrecision(n[i][1],8)===l.roundPrecision(e.lat,8)&&n.splice(i,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,i=0,s=0,o,r;return t.forEach((c,a)=>{for(let d=0;d<c.length-1;d++){const u={lng:c[d][0],lat:c[d][1]},h={lng:c[d+1][0],lat:c[d+1][1]},f=this.calculatePointToLineDistance(e,u,h);n>f&&(n=f,s=d,i=a,o=this.calculateDistance(u,e),r=this.calculateDistance(h,e))}}),o!==0&&r!==0?t[i].splice(s+1,0,[e.lng,e.lat]):o===0?t[i].splice(s,1,[e.lng,e.lat]):r===0&&t[i].splice(s+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=v.convertRouteToCoordinates(t);return n.push(e),v.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=v.convertRouteToCoordinates(t);return n.unshift(e),v.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const i=[];let s=0;return n.forEach(o=>{if(s===2)return;const r=[];for(const c of o){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),s===0&&r.push([e.lng,e.lat]),s=2;break}s===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(s=1,r.push(c))}r.length&&i.push(r)}),i}static calculateRangeWaypoints(e,t,n,i=[]){const s=this.convertRouteToCoordinates(n,0),o=this.mergeCoordinatesToWaypoints([e,t,...i],s),r=o.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=o.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return o.filter((d,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,i=0,s=0;return t.forEach((o,r)=>{for(let c=0;c<o.length-1;c++){const a={lng:o[c][0],lat:o[c][1]},d={lng:o[c+1][0],lat:o[c+1][1]},u=this.calculatePointToLineDistance(e,a,d);n>u&&(n=u,i=c,s=r)}}),{minDist:n,segIndex:s,minIndex:i}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:i}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const s=[];let o=!0;for(let r=n;r<t.length;r++)if(o){const c=[];c.push([e.lng,e.lat]);for(let a=i+1;a<t[r].length;a++)e.lng===t[r][a][0]&&e.lat===t[r][a][1]||c.push(t[r][a]);s.push(c),o=!1}else s.push([...t[r]]);return s}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,i=0;for(let o=0;o<t.length-1;o++){const r=t[o],c=t[o+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,c);n>a&&(n=a,i=o)}e.lng=l.convertToStdLng(e.lng);const s=[e];for(let o=i+1;o<t.length;o++)s.push(t[o]);return s}static calculatePointToLineDistance(e,t,n,i={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const s=l.convertToMonotonicLng([t,n]);t=s[0],n=s[1];const o=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),o,i),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),o,i);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const i=e[n],s=e[n+1],o=this.calculateRangeRoute(i,s,t);n===0&&(i.distanceFromPrevious=0,i.distanceFromStart=0),s.distanceFromPrevious=this.calculateRouteDistance(o),s.distanceFromStart=l.roundPrecision((i.distanceFromStart||0)+s.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const i of e)this.mergeCoordinateToWaypoints(i,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let i=Number.MAX_VALUE,s=0,o=0,r=0;for(let c=0;c<t.length-1;c++){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);i>=u&&(i=u,s=c,o=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return o!==0&&r!==0?o<i||o===i&&s===0?t.unshift(e):r<i||r===i&&s===t.length-2?t.push(e):t.splice(s+1,0,e):o===0?n&&t.splice(s,1,e):r===0&&n&&t.splice(s+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const i=e[n-1],s=e[n];if(n===1&&t.push(i),s.gcToPrevious){const o=this.interpolateCoordinates(i,s,200,!1,!0,"nauticalmiles");t.push(...o)}else t.push(s)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),i=[];for(const c of t){const a=c.map(d=>g.point(d));i.push(...a)}const s=g.featureCollection(i),o=g.nearestPoint(n,s),r=g.getCoord(o);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let i=0;i<t.length-1;i++){const s=t[i],o=t[i+1];if(this.calculateDistance(e,s)===0){n=i;break}if(this.calculateDistance(e,o)===0){n=i+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,i="nauticalmiles"){var h;const s=e.speed||12,o=[];let r=[],c=!1,a=0,d=0,u;if(t&&n.length?(o.push(e),n.forEach((f,C)=>{if(c)r.push(f);else{const m=[];let b;for(let M=0;M<f.length;M++)if(u)m.push(f[M]);else{b={lng:f[M][0],lat:f[M][1]};const T=this.calculateDistance(e,b,!0,8,i);if(a+=T,a<t)d+=T,o.push(b),e=b;else{if(d=t,a===t)u=b,m.push([u.lng,u.lat]);else{const p=a-t,D=this.calculateBearing(b,e);u=this.calculateCoordinate(b,D,p,i),m.push([u.lng,u.lat]),m.push([b.lng,b.lat])}c=!0}}m.length&&r.push(m),C===n.length-1&&!u&&(u=b)}})):(r=n,u={...e}),u)if(o.push(u),u.distanceFromPrevious=d,u.hourFromPrevious=Math.round(d/s*1e4)/1e4,((h=r[0])==null?void 0:h.length)>1){const f={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,f)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:o}}static nearestCoordinateInLine(e,t,n){const i=l.convertToStdLng(e.lng,6),s=g.point([i,e.lat]),o=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[o,t.lat],[r,n.lat]]),a=g.nearestPointOnLine(c,s),d=g.getCoord(a),u=l.roundPrecision(d[0],6),h=l.roundPrecision(d[1],6);return{lng:u,lat:h,inline:!(u===o&&h===t.lat)&&!(u===r&&h===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let i,s;return e.forEach(o=>{o.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!s)n.push(c),s=c;else if(s.bearing===void 0)s.bearing=this.calculateBearing(s,c,!0);else{const a=this.calculateDistance(i,c,!0);a&&a>=t&&(i.bearing=this.calculateBearing(i,c,!0),n.push(i),s=i)}i=c})}),i&&n.push(i),n}static simplifyRouteToCoordinates(e,t,n=1){let i=this.convertRouteToCoordinates(e,n);return i=this.simplifyGCCoordinates(i,t),i}static simplifyGCCoordinates(e,t){t.forEach(i=>{this.mergeCoordinateToWaypoints(i,e)});for(let i=1;i<t.length;i++){const s=t[i-1],o=t[i];if(o.gcToPrevious){const r=e.findIndex(a=>a.lng===s.lng&&a.lat===s.lat),c=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat);for(let a=c-1;a>r;a--)e.splice(a,1)}}let n=0;for(let i=1;i<e.length;i++){const s=e[i-1],o=e[i];o.gcToPrevious?(s.bearing=this.calculateBearing(s,o,!1),o.distanceFromPrevious=this.calculateDistance(s,o,!1)):(s.bearing=this.calculateBearing(s,o,!0),o.distanceFromPrevious=this.calculateDistance(s,o,!0)),n=l.roundPrecision(n+o.distanceFromPrevious),o.distanceFromStart=n}return e.map(i=>(i.lng=l.convertToStdLng(i.lng),i))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),i=l.convertToMonotonicLng2(t);for(const r of i)n.features.push(g.point(r));const o=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(o[0],8),lat:l.roundPrecision(o[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const s of e)for(const o of s)t.push(o);const n=l.convertToMonotonicLng2(t),i=g.lineString(n);return g.bbox(i)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}const R=O.getLogger("vessel");class W{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const i of e){if(i.forecasts){const s=(n=i.history)==null?void 0:n[0];for(const o of i.forecasts){const r=[],c=N(o.date).utc(),a=`${i.name}-${o.model}`;if(s){const d=N(s.updated).utc(),u=g.point([s.lng,s.lat],{model:o.model,name:i.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:s.pressure>1e4?l.roundPrecision(s.pressure/100,0):l.roundPrecision(s.pressure,0),wind:{kts:s.kts,spd:s.speed||s.spd},category:a,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const d in o==null?void 0:o.hours){const u=o.hours[d];u.wind.spd=u.wind.spd||u.wind.speed;const h=c.clone().add(Number(d),"hour"),f=g.point([u.lng,u.lat],{model:o.model,name:i.name,date:h.format(),hour:Number(d),format:h.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?l.roundPrecision(u.pressure/100,0):l.roundPrecision(u.pressure,0),gusts:u.gusts,wind:u.wind||{},movement:u.movement,category:a,type:"forecast"});t.features.push(f),r.push(f.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:o.date,id:i.id||i.name,model:o.model,name:i.name,category:a,type:"forecast"});t.features.push(d)}}}if(i.history){const s=[];for(const r of i.history){const c=N(r.updated).utc(),a=g.point([r.lng,r.lat],{name:i.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${i.name}-history`});t.features.push(a),s.push(a.geometry.coordinates)}const o=i.history[0];if(s.length===1&&s.push(s[0]),s.length>1){const r=g.lineString(l.convertToMonotonicLng2(s),{name:i.name,type:"history",updated:o==null?void 0:o.updated,pressure:(o==null?void 0:o.pressure)>1e4?l.roundPrecision((o==null?void 0:o.pressure)/100,0):l.roundPrecision(o==null?void 0:o.pressure,0),spd:(o==null?void 0:o.speed)||(o==null?void 0:o.spd),kts:o==null?void 0:o.kts,source:o==null?void 0:o.source,level:o==null?void 0:o.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var s,o,r,c;const n=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),i=[];for(const a of n){const d=a.properties.name,u=a.properties.model,h=a.properties.showCircle,f=N(a.properties.date).utc();let C=t*60-(f.get("hour")*60+f.get("minute"))%(t*60);const m=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(T=>T.geometry.type==="Point"&&T.properties.type==="forecast"&&T.properties.category===`${d}-${u}`);let b,M=f.clone().add(C,"minute").set({minute:0,second:0,millisecond:0});for(;b=this.pickIndex(m,M),b<=m.length-1;){if(b>0){const T=m[b],p=b===0?void 0:m[b-1],D=(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)),E=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],T.geometry.coordinates[0],D),F=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],T.geometry.coordinates[1],D),A=g.point([E,F],{name:d,model:u,category:T==null?void 0:T.properties.category,date:M.format(),format:M.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,T.properties.gusts,D),hour:this.computeNumber(p==null?void 0:p.properties.hour,T.properties.hour,D),movement:this.computeNumber(p==null?void 0:p.properties.movement,T.properties.movement,D),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,T.properties.pressure,D),wind:this.computeNumber(p==null?void 0:p.properties.wind,T.properties.wind,D),type:"forecast",showCircle:h});i.push(A)}C+=t*60,M=f.clone().add(C,"minute").set({minute:0,second:0,millisecond:0})}}return i}static diversionPassageAt(e,t,n,i={requestId:""}){const{t1:s,t2:o,hr:r,hours:c}=this.tropicalCenterTwin(t,24,i);if(s&&o){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,o),u=Math.abs(a-d);let h=0;u<180?h=u+90:u>=180&&(h=u-90);const f=v.calculateCoordinate(s,h,n);return R.info("[%s] the right tangent position: %j",i.requestId,{from:e,t1:s,t2:o,radius:n,bearing1:a,bearing2:d,right:f}),{at:f,t1:s,t2:o,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,i={requestId:""}){const{t1:s,t2:o,hr:r,hours:c}=this.tropicalCenterTwin(t,24,i);if(s&&o){const a=v.calculateBearing(e,s),d=v.calculateBearing(s,o),u=v.calculateDistance(e,s);return{at:v.calculateCoordinate(s,a-d+180,n<u?n:u),t1:s,t2:o,hr:Number(r),hours:c}}else return R.info("[%s] no need drift: %j",i.requestId,{from:e,t1:s,t2:o,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={requestId:""}){var d,u,h,f,C;let i={};(d=e.forecasts)==null||d.forEach(m=>{i={...m.hours,...i}});const s=((u=e==null?void 0:e.history)==null?void 0:u[0])||(i==null?void 0:i[(h=Object.keys(i))==null?void 0:h[0]]);R.info("[%s] the first tropical center: %j",n.requestId,s);let o=(f=Object.keys(i||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:f.at(-1);o||(o=(C=Object.keys(i||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:C.at(-1));const r=i==null?void 0:i[o||-1];R.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,o);const c=Object.keys(i||{}).filter(m=>Number(m)<=Number(o)),a={0:s};for(const m of c)a[m]=i[m];return{t1:s,t2:r,hr:o,hours:a}}static pickIndex(e,t){let n=0;for(const i of e){if(N(i.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const i={};for(const s in e)i[s]=this.computeNumber(e[s],t[s],n);return i}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}S.LaneHelper=v,S.LngLatHelper=l,S.TropicalHelper=W,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
@@ -46,9 +46,21 @@ export declare class TropicalHelper {
46
46
  }, tropical: any, radius: number, options?: {
47
47
  requestId: string;
48
48
  }): {
49
- lng: number;
50
- lat: number;
51
- } | undefined;
49
+ at: {
50
+ lng: number;
51
+ lat: number;
52
+ };
53
+ t1: any;
54
+ t2: any;
55
+ hr: number;
56
+ hours: any;
57
+ } | {
58
+ at?: undefined;
59
+ t1?: undefined;
60
+ t2?: undefined;
61
+ hr?: undefined;
62
+ hours?: undefined;
63
+ };
52
64
  /**
53
65
  * 计算最佳漂航点
54
66
  * 1) 确定当前船位与当前台风中心点之间的方位角,
@@ -65,9 +77,21 @@ export declare class TropicalHelper {
65
77
  }, tropical: any, radius: number, options?: {
66
78
  requestId: string;
67
79
  }): {
68
- lng: number;
69
- lat: number;
70
- } | undefined;
80
+ at: {
81
+ lng: number;
82
+ lat: number;
83
+ };
84
+ t1: any;
85
+ t2: any;
86
+ hr: number;
87
+ hours: any;
88
+ } | {
89
+ at?: undefined;
90
+ t1?: undefined;
91
+ t2?: undefined;
92
+ hr?: undefined;
93
+ hours?: undefined;
94
+ };
71
95
  /**
72
96
  * 获取台风中心点对
73
97
  * @param tropical { history: any[], forecasts: any[] }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "1.2.6",
4
+ "version": "1.2.7",
5
5
  "description": "idm plugin for geo",
6
6
  "type": "module",
7
7
  "keywords": [