@idm-plugin/geo 1.0.2 → 1.0.4
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 +151 -130
- package/dist/index.umd.cjs +1 -1
- package/dist/tropicals/src/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import y from "moment";
|
|
2
2
|
import "moment-timezone";
|
|
3
3
|
import T from "tz-lookup";
|
|
4
4
|
import * as N from "@turf/turf";
|
|
@@ -9,8 +9,8 @@ class u {
|
|
|
9
9
|
* @param lat
|
|
10
10
|
*/
|
|
11
11
|
static guessTimeZoneOffset(e, t) {
|
|
12
|
-
const
|
|
13
|
-
return this.roundPrecision(
|
|
12
|
+
const r = T(t, e), s = y().tz(r).utcOffset();
|
|
13
|
+
return this.roundPrecision(s / 60, 1);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* 将时间offset转换为时区,例如:8.5 => +08:30
|
|
@@ -18,21 +18,21 @@ class u {
|
|
|
18
18
|
* @return timezone => +08:30
|
|
19
19
|
*/
|
|
20
20
|
static prettyTimeZoneOffset(e) {
|
|
21
|
-
let t = Math.floor(Math.abs(e)),
|
|
22
|
-
return
|
|
21
|
+
let t = Math.floor(Math.abs(e)), r = Math.round((Math.abs(e) - t) * 60);
|
|
22
|
+
return r = r > 9 ? r : `0${r}`, t = t > 9 ? t : `0${t}`, e > 0 ? `+${t}:${r}` : `-${t}:${r}`;
|
|
23
23
|
}
|
|
24
|
-
static lng2pretty(e, t = 6,
|
|
24
|
+
static lng2pretty(e, t = 6, r = "H°M′") {
|
|
25
25
|
e = u.convertToStdLng(e, t);
|
|
26
|
-
let
|
|
27
|
-
e < 0 && (
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
const h = `${
|
|
26
|
+
let s = "E";
|
|
27
|
+
e < 0 && (s = "W"), e = Math.abs(e), r = r.toUpperCase();
|
|
28
|
+
let i = e * 3600, o, n, c, m, a, p;
|
|
29
|
+
o = i % 3600 % 60, r.indexOf("S") !== -1 && (i = i - o, n = u.padNumber(o, 2, 2)), c = i / 60 % 60, r.indexOf("M") !== -1 && (r.indexOf("S") !== -1 ? m = u.roundPrecision(c, t).toString().padStart(2, "0") : m = u.padNumber(c, 2, 2), i = i - c * 60), a = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(a, t).toString().padStart(3, "0") : p = u.padNumber(a, 3, 2);
|
|
30
|
+
const h = `${r.replace(/S+/gi, n).replace(/M+/gi, m).replace(/H+/gi, p)}${s}`;
|
|
31
31
|
return {
|
|
32
|
-
direction:
|
|
32
|
+
direction: s,
|
|
33
33
|
degree: u.roundPrecision(a, t),
|
|
34
|
-
minute: u.roundPrecision(
|
|
35
|
-
second: u.roundPrecision(
|
|
34
|
+
minute: u.roundPrecision(c, t),
|
|
35
|
+
second: u.roundPrecision(o, t),
|
|
36
36
|
pretty: h
|
|
37
37
|
};
|
|
38
38
|
}
|
|
@@ -42,59 +42,59 @@ class u {
|
|
|
42
42
|
* @param precision 精确度
|
|
43
43
|
* @param format 格式化
|
|
44
44
|
*/
|
|
45
|
-
static lat2pretty(e, t = 6,
|
|
45
|
+
static lat2pretty(e, t = 6, r = "H°M′") {
|
|
46
46
|
e = e % 180;
|
|
47
|
-
let
|
|
48
|
-
e < 0 && (
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
const h = `${
|
|
47
|
+
let s = "N";
|
|
48
|
+
e < 0 && (s = "S"), e = Math.abs(e), r = r.toUpperCase();
|
|
49
|
+
let i = e * 3600, o, n, c, m, a, p;
|
|
50
|
+
o = i % 3600 % 60, r.indexOf("S") !== -1 && (i = i - o, n = u.padNumber(o, 2, 2)), c = i / 60 % 60, r.indexOf("M") !== -1 && (r.indexOf("S") !== -1 ? m = u.roundPrecision(c, t).toString().padStart(2, "0") : m = u.padNumber(c, 2, 2), i = i - c * 60), a = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(a, t).toString().padStart(2, "0") : p = u.padNumber(a, 2, 2);
|
|
51
|
+
const h = `${r.replace(/S+/gi, n).replace(/M+/gi, m).replace(/H+/gi, p)}${s}`;
|
|
52
52
|
return {
|
|
53
|
-
direction:
|
|
53
|
+
direction: s,
|
|
54
54
|
degree: u.roundPrecision(a, t),
|
|
55
|
-
minute: u.roundPrecision(
|
|
56
|
-
second: u.roundPrecision(
|
|
55
|
+
minute: u.roundPrecision(c, t),
|
|
56
|
+
second: u.roundPrecision(o, t),
|
|
57
57
|
pretty: h
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
static str2Lng(e, t = 6) {
|
|
61
|
-
let
|
|
61
|
+
let r;
|
|
62
62
|
if (isNaN(e)) {
|
|
63
63
|
e = u.strReplace(e, "LNG");
|
|
64
|
-
const
|
|
64
|
+
const s = e[e.length - 1].toUpperCase();
|
|
65
65
|
e = e.substring(0, e.length - 1).trim();
|
|
66
|
-
const
|
|
67
|
-
let [
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
|
|
66
|
+
const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
|
|
67
|
+
let [o, n] = i;
|
|
68
|
+
if (o > 360 && !n) {
|
|
69
|
+
const c = this.roundPrecision(o / 100, 0);
|
|
70
|
+
n = o - c * 100, o = c;
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
r = o + (n ?? 0) / 60, s === "W" && (r = r * -1);
|
|
73
73
|
} else
|
|
74
|
-
|
|
75
|
-
return u.convertToStdLng(
|
|
74
|
+
r = Number(e);
|
|
75
|
+
return u.convertToStdLng(r, t);
|
|
76
76
|
}
|
|
77
77
|
static str2Lat(e, t = 6) {
|
|
78
|
-
let
|
|
78
|
+
let r;
|
|
79
79
|
if (isNaN(e)) {
|
|
80
80
|
e = u.strReplace(e, "LAT");
|
|
81
|
-
const
|
|
81
|
+
const s = e[e.length - 1].toUpperCase();
|
|
82
82
|
e = e.substring(0, e.length - 1).trim();
|
|
83
|
-
const
|
|
84
|
-
let [
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
|
|
83
|
+
const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
|
|
84
|
+
let [o, n] = i;
|
|
85
|
+
if (o > 90 && !n) {
|
|
86
|
+
const c = this.roundPrecision(o / 100, 0);
|
|
87
|
+
n = o - c * 100, o = c;
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
r = o + (n ?? 0) / 60, s === "S" && (r = r * -1);
|
|
90
90
|
} else
|
|
91
|
-
|
|
92
|
-
return u.roundPrecision(
|
|
91
|
+
r = Number(e);
|
|
92
|
+
return u.roundPrecision(r, t);
|
|
93
93
|
}
|
|
94
|
-
static str2LngOrLat(e, t = 6,
|
|
95
|
-
e = u.strReplace(e,
|
|
96
|
-
const
|
|
97
|
-
return ["N", "S"].includes(
|
|
94
|
+
static str2LngOrLat(e, t = 6, r = "LAT") {
|
|
95
|
+
e = u.strReplace(e, r);
|
|
96
|
+
const s = e[e.length - 1].toUpperCase();
|
|
97
|
+
return ["N", "S"].includes(s) ? {
|
|
98
98
|
lat: u.str2Lat(e, t)
|
|
99
99
|
} : {
|
|
100
100
|
lng: u.str2Lng(e, t)
|
|
@@ -105,8 +105,8 @@ class u {
|
|
|
105
105
|
}
|
|
106
106
|
static roundPrecision(e, t = 4) {
|
|
107
107
|
if (typeof e == "number") {
|
|
108
|
-
const
|
|
109
|
-
return Math.round(e *
|
|
108
|
+
const r = Number("1".padEnd(t + 1, "0"));
|
|
109
|
+
return Math.round(e * r) / r;
|
|
110
110
|
}
|
|
111
111
|
return e;
|
|
112
112
|
}
|
|
@@ -130,12 +130,12 @@ class u {
|
|
|
130
130
|
}
|
|
131
131
|
static strReplace(e, t = "LAT") {
|
|
132
132
|
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();
|
|
133
|
-
const
|
|
134
|
-
if (!["N", "S", "E", "W"].includes(
|
|
135
|
-
const
|
|
136
|
-
if (isNaN(
|
|
133
|
+
const r = e[e.length - 1].toUpperCase();
|
|
134
|
+
if (!["N", "S", "E", "W"].includes(r)) {
|
|
135
|
+
const s = e, i = Number(s.split(" ")[0]);
|
|
136
|
+
if (isNaN(i))
|
|
137
137
|
throw new Error(`invalid Lat/Lng: ${e}`);
|
|
138
|
-
|
|
138
|
+
i >= 90 ? e = `${s}E` : i <= -90 ? e = `${s}W` : ["LAN", "LNG"].includes(t == null ? void 0 : t.toUpperCase()) ? e = `${s}${i > 0 ? "E" : "W"}` : e = `${s}${i > 0 ? "N" : "S"}`;
|
|
139
139
|
}
|
|
140
140
|
return e;
|
|
141
141
|
}
|
|
@@ -146,73 +146,92 @@ class u {
|
|
|
146
146
|
* @param intPrecision 整数位数
|
|
147
147
|
* @param dcmPrecision 小数位数
|
|
148
148
|
*/
|
|
149
|
-
static padNumber(e, t = 2,
|
|
150
|
-
const
|
|
151
|
-
return `${
|
|
149
|
+
static padNumber(e, t = 2, r = 2) {
|
|
150
|
+
const s = Math.trunc(e).toString().padStart(t, "0"), i = Math.trunc(u.roundPrecision(e - Math.trunc(e), r) * Math.pow(10, r)).toString().padStart(r, "0");
|
|
151
|
+
return `${s}.${i}`;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class
|
|
154
|
+
class x {
|
|
155
155
|
static convert2Geojson(e) {
|
|
156
|
+
var r;
|
|
156
157
|
const t = N.featureCollection([]);
|
|
157
|
-
for (const
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
for (const s of e) {
|
|
159
|
+
if (s.forecasts) {
|
|
160
|
+
const i = (r = s.history) == null ? void 0 : r[0];
|
|
161
|
+
for (const o of s.forecasts) {
|
|
162
|
+
const n = [], c = y(o.date).utc(), m = `${s.name}-${o.model}`;
|
|
163
|
+
if (i) {
|
|
164
|
+
const a = y(i.updated).utc(), p = N.point([i.lng, i.lat], {
|
|
165
|
+
model: o.model,
|
|
166
|
+
name: s.name,
|
|
165
167
|
date: a.format(),
|
|
166
|
-
hour:
|
|
168
|
+
hour: 0,
|
|
167
169
|
format: a.format("MMM-DD/HHmm[Z]"),
|
|
168
|
-
pressure:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
movement: d.movement,
|
|
172
|
-
category: p,
|
|
170
|
+
pressure: i.pressure > 1e4 ? u.roundPrecision(i.pressure / 100, 0) : u.roundPrecision(i.pressure, 0),
|
|
171
|
+
wind: { kts: i.kts, spd: i.speed || i.spd },
|
|
172
|
+
category: m,
|
|
173
173
|
type: "forecast"
|
|
174
174
|
});
|
|
175
|
-
t.features.push(
|
|
175
|
+
t.features.push(p), n.push(p.geometry.coordinates);
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
177
|
+
for (const a in o == null ? void 0 : o.hours) {
|
|
178
|
+
const p = o.hours[a];
|
|
179
|
+
p.wind.spd = p.wind.spd || p.wind.speed;
|
|
180
|
+
const h = c.clone().add(Number(a), "hour"), l = N.point([p.lng, p.lat], {
|
|
181
|
+
name: s.name,
|
|
182
|
+
date: h.format(),
|
|
183
|
+
hour: Number(a),
|
|
184
|
+
format: h.format("MMM-DD/HHmm[Z]"),
|
|
185
|
+
pressure: p.pressure > 1e4 ? u.roundPrecision(p.pressure / 100, 0) : u.roundPrecision(p.pressure, 0),
|
|
186
|
+
gusts: p.gusts,
|
|
187
|
+
wind: p.wind || {},
|
|
188
|
+
movement: p.movement,
|
|
189
|
+
category: m,
|
|
184
190
|
type: "forecast"
|
|
185
191
|
});
|
|
186
|
-
t.features.push(
|
|
192
|
+
t.features.push(l), n.push(l.geometry.coordinates);
|
|
193
|
+
}
|
|
194
|
+
if ((n == null ? void 0 : n.length) > 1) {
|
|
195
|
+
const a = N.lineString(u.convertToMonotonicLng2(n), {
|
|
196
|
+
date: o.date,
|
|
197
|
+
id: s.id || s.name,
|
|
198
|
+
model: o.model,
|
|
199
|
+
name: s.name,
|
|
200
|
+
category: m,
|
|
201
|
+
type: "forecast"
|
|
202
|
+
});
|
|
203
|
+
t.features.push(a);
|
|
187
204
|
}
|
|
188
205
|
}
|
|
189
|
-
|
|
206
|
+
}
|
|
207
|
+
if (s.history) {
|
|
190
208
|
const i = [];
|
|
191
|
-
for (const n of
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
209
|
+
for (const n of s.history) {
|
|
210
|
+
const c = y(n.updated).utc(), m = N.point([n.lng, n.lat], {
|
|
211
|
+
name: s.name,
|
|
212
|
+
date: c.format(),
|
|
213
|
+
format: c.format("MMM-DD/HHmm[Z]"),
|
|
195
214
|
pressure: n.pressure > 1e4 ? u.roundPrecision(n.pressure / 100, 0) : u.roundPrecision(n.pressure, 0),
|
|
196
215
|
spd: n.speed || n.spd,
|
|
197
216
|
kts: n.kts,
|
|
198
217
|
source: n.source,
|
|
199
218
|
level: n.type,
|
|
200
219
|
type: "history",
|
|
201
|
-
category: `${
|
|
220
|
+
category: `${s.name}-history`
|
|
202
221
|
});
|
|
203
|
-
t.features.push(
|
|
222
|
+
t.features.push(m), i.push(m.geometry.coordinates);
|
|
204
223
|
}
|
|
205
|
-
const
|
|
224
|
+
const o = s.history[0];
|
|
206
225
|
if (i.length === 1 && i.push(i[0]), i.length > 1) {
|
|
207
226
|
const n = N.lineString(u.convertToMonotonicLng2(i), {
|
|
208
|
-
name:
|
|
227
|
+
name: s.name,
|
|
209
228
|
type: "history",
|
|
210
|
-
updated:
|
|
211
|
-
pressure: (
|
|
212
|
-
spd: (
|
|
213
|
-
kts:
|
|
214
|
-
source:
|
|
215
|
-
level:
|
|
229
|
+
updated: o == null ? void 0 : o.updated,
|
|
230
|
+
pressure: (o == null ? void 0 : o.pressure) > 1e4 ? u.roundPrecision((o == null ? void 0 : o.pressure) / 100, 0) : u.roundPrecision(o == null ? void 0 : o.pressure, 0),
|
|
231
|
+
spd: (o == null ? void 0 : o.speed) || (o == null ? void 0 : o.spd),
|
|
232
|
+
kts: o == null ? void 0 : o.kts,
|
|
233
|
+
source: o == null ? void 0 : o.source,
|
|
234
|
+
level: o == null ? void 0 : o.type
|
|
216
235
|
});
|
|
217
236
|
t.features.push(n);
|
|
218
237
|
}
|
|
@@ -221,54 +240,56 @@ class D {
|
|
|
221
240
|
return t;
|
|
222
241
|
}
|
|
223
242
|
static interpolate(e, t = 3) {
|
|
224
|
-
var
|
|
225
|
-
const
|
|
226
|
-
for (const
|
|
227
|
-
const a =
|
|
228
|
-
let
|
|
229
|
-
const b = (
|
|
230
|
-
(
|
|
243
|
+
var i, o, n, c;
|
|
244
|
+
const r = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((m) => m.geometry.type === "LineString" && m.properties.type === "forecast"), s = [];
|
|
245
|
+
for (const m of r) {
|
|
246
|
+
const a = m.properties.name, p = m.properties.model, h = y(m.properties.date).utc();
|
|
247
|
+
let l = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
|
|
248
|
+
const b = (o = e == null ? void 0 : e.data) == null ? void 0 : o.features.filter(
|
|
249
|
+
(f) => !f.properties.disabled && f.geometry.type === "Point" && f.properties.type === "forecast" && f.properties.category === `${a}-${p}`
|
|
231
250
|
);
|
|
232
|
-
let
|
|
233
|
-
for (;
|
|
234
|
-
if (
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
251
|
+
let M, S = h.clone().add(l, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
252
|
+
for (; M = this.pickIndex(b, S), M <= b.length - 1; ) {
|
|
253
|
+
if (M > 0) {
|
|
254
|
+
const f = b[M], d = M === 0 ? void 0 : b[M - 1], g = (l / 60 - ((n = d == null ? void 0 : d.properties) == null ? void 0 : n.hour)) / (f.properties.hour - ((c = d == null ? void 0 : d.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(d == null ? void 0 : d.geometry.coordinates[0], f.geometry.coordinates[0], g), P = this.computeNumber(d == null ? void 0 : d.geometry.coordinates[1], f.geometry.coordinates[1], g), w = N.point([$, P], {
|
|
255
|
+
name: a,
|
|
256
|
+
model: p,
|
|
257
|
+
category: f == null ? void 0 : f.properties.category,
|
|
238
258
|
date: S.format(),
|
|
239
259
|
format: S.format("MMM-DD/HHmm[Z]"),
|
|
240
|
-
gusts: this.computeNumber(
|
|
241
|
-
hour: this.computeNumber(
|
|
242
|
-
movement: this.computeNumber(
|
|
243
|
-
pressure: this.computeNumber(
|
|
244
|
-
wind: this.computeNumber(
|
|
260
|
+
gusts: this.computeNumber(d == null ? void 0 : d.properties.gusts, f.properties.gusts, g),
|
|
261
|
+
hour: this.computeNumber(d == null ? void 0 : d.properties.hour, f.properties.hour, g),
|
|
262
|
+
movement: this.computeNumber(d == null ? void 0 : d.properties.movement, f.properties.movement, g),
|
|
263
|
+
pressure: this.computeNumber(d == null ? void 0 : d.properties.pressure, f.properties.pressure, g),
|
|
264
|
+
wind: this.computeNumber(d == null ? void 0 : d.properties.wind, f.properties.wind, g),
|
|
265
|
+
type: "forecast"
|
|
245
266
|
});
|
|
246
|
-
|
|
267
|
+
s.push(w);
|
|
247
268
|
}
|
|
248
|
-
|
|
269
|
+
l += t * 60, S = h.clone().add(l, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
249
270
|
}
|
|
250
271
|
}
|
|
251
|
-
return
|
|
272
|
+
return s;
|
|
252
273
|
}
|
|
253
274
|
static pickIndex(e, t) {
|
|
254
|
-
let
|
|
255
|
-
for (const
|
|
256
|
-
if (
|
|
257
|
-
return
|
|
258
|
-
|
|
275
|
+
let r = 0;
|
|
276
|
+
for (const s of e) {
|
|
277
|
+
if (y(s.properties.date).isAfter(t))
|
|
278
|
+
return r === 0 ? -1 : r;
|
|
279
|
+
r++;
|
|
259
280
|
}
|
|
260
|
-
return
|
|
281
|
+
return r;
|
|
261
282
|
}
|
|
262
|
-
static computeNumber(e, t,
|
|
283
|
+
static computeNumber(e, t, r) {
|
|
263
284
|
if (e)
|
|
264
285
|
if (t) {
|
|
265
286
|
if (isNaN(e) && isNaN(t) && typeof e != "string" && typeof t != "string") {
|
|
266
|
-
const
|
|
267
|
-
for (const
|
|
268
|
-
i
|
|
269
|
-
return
|
|
287
|
+
const s = {};
|
|
288
|
+
for (const i in e)
|
|
289
|
+
s[i] = this.computeNumber(e[i], t[i], r);
|
|
290
|
+
return s;
|
|
270
291
|
}
|
|
271
|
-
return Math.round((e + (t - e) *
|
|
292
|
+
return Math.round((e + (t - e) * r) * 100) / 100;
|
|
272
293
|
} else
|
|
273
294
|
return e;
|
|
274
295
|
else
|
|
@@ -277,5 +298,5 @@ class D {
|
|
|
277
298
|
}
|
|
278
299
|
export {
|
|
279
300
|
u as LngLatHelper,
|
|
280
|
-
|
|
301
|
+
x as TropicalHelper
|
|
281
302
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,
|
|
1
|
+
(function(h,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("moment"),require("moment-timezone"),require("tz-lookup"),require("@turf/turf")):typeof define=="function"&&define.amd?define(["exports","moment","moment-timezone","tz-lookup","@turf/turf"],g):(h=typeof globalThis<"u"?globalThis:h||self,g(h["idm-plugin-rabbitmq"]={},h.moment,h["moment-timezone"],h["tz-lookup"],h["@turf/turf"]))})(this,function(h,g,j,T,O){"use strict";function w(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const y=w(O);class s{static guessTimeZoneOffset(e,t){const o=T(t,e),n=g().tz(o).utcOffset();return this.roundPrecision(n/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),o=Math.round((Math.abs(e)-t)*60);return o=o>9?o:`0${o}`,t=t>9?t:`0${t}`,e>0?`+${t}:${o}`:`-${t}:${o}`}static lng2pretty(e,t=6,o="H°M′"){e=s.convertToStdLng(e,t);let n="E";e<0&&(n="W"),e=Math.abs(e),o=o.toUpperCase();let i=e*3600,r,u,c,a,m,p;r=i%3600%60,o.indexOf("S")!==-1&&(i=i-r,u=s.padNumber(r,2,2)),c=i/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?a=s.roundPrecision(c,t).toString().padStart(2,"0"):a=s.padNumber(c,2,2),i=i-c*60),m=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(m,t).toString().padStart(3,"0"):p=s.padNumber(m,3,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,a).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(m,t),minute:s.roundPrecision(c,t),second:s.roundPrecision(r,t),pretty:l}}static lat2pretty(e,t=6,o="H°M′"){e=e%180;let n="N";e<0&&(n="S"),e=Math.abs(e),o=o.toUpperCase();let i=e*3600,r,u,c,a,m,p;r=i%3600%60,o.indexOf("S")!==-1&&(i=i-r,u=s.padNumber(r,2,2)),c=i/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?a=s.roundPrecision(c,t).toString().padStart(2,"0"):a=s.padNumber(c,2,2),i=i-c*60),m=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(m,t).toString().padStart(2,"0"):p=s.padNumber(m,2,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,a).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(m,t),minute:s.roundPrecision(c,t),second:s.roundPrecision(r,t),pretty:l}}static str2Lng(e,t=6){let o;if(isNaN(e)){e=s.strReplace(e,"LNG");const n=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[r,u]=i;if(r>360&&!u){const c=this.roundPrecision(r/100,0);u=r-c*100,r=c}o=r+(u??0)/60,n==="W"&&(o=o*-1)}else o=Number(e);return s.convertToStdLng(o,t)}static str2Lat(e,t=6){let o;if(isNaN(e)){e=s.strReplace(e,"LAT");const n=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[r,u]=i;if(r>90&&!u){const c=this.roundPrecision(r/100,0);u=r-c*100,r=c}o=r+(u??0)/60,n==="S"&&(o=o*-1)}else o=Number(e);return s.roundPrecision(o,t)}static str2LngOrLat(e,t=6,o="LAT"){e=s.strReplace(e,o);const n=e[e.length-1].toUpperCase();return["N","S"].includes(n)?{lat:s.str2Lat(e,t)}:{lng:s.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),s.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const o=Number("1".padEnd(t+1,"0"));return Math.round(e*o)/o}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 o=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(o)){const n=e,i=Number(n.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${n}E`:i<=-90?e=`${n}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${n}${i>0?"E":"W"}`:e=`${n}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,o=2){const n=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(s.roundPrecision(e-Math.trunc(e),o)*Math.pow(10,o)).toString().padStart(o,"0");return`${n}.${i}`}}class k{static convert2Geojson(e){var o;const t=y.featureCollection([]);for(const n of e){if(n.forecasts){const i=(o=n.history)==null?void 0:o[0];for(const r of n.forecasts){const u=[],c=g(r.date).utc(),a=`${n.name}-${r.model}`;if(i){const m=g(i.updated).utc(),p=y.point([i.lng,i.lat],{model:r.model,name:n.name,date:m.format(),hour:0,format:m.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?s.roundPrecision(i.pressure/100,0):s.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:a,type:"forecast"});t.features.push(p),u.push(p.geometry.coordinates)}for(const m in r==null?void 0:r.hours){const p=r.hours[m];p.wind.spd=p.wind.spd||p.wind.speed;const l=c.clone().add(Number(m),"hour"),M=y.point([p.lng,p.lat],{name:n.name,date:l.format(),hour:Number(m),format:l.format("MMM-DD/HHmm[Z]"),pressure:p.pressure>1e4?s.roundPrecision(p.pressure/100,0):s.roundPrecision(p.pressure,0),gusts:p.gusts,wind:p.wind||{},movement:p.movement,category:a,type:"forecast"});t.features.push(M),u.push(M.geometry.coordinates)}if((u==null?void 0:u.length)>1){const m=y.lineString(s.convertToMonotonicLng2(u),{date:r.date,id:n.id||n.name,model:r.model,name:n.name,category:a,type:"forecast"});t.features.push(m)}}}if(n.history){const i=[];for(const u of n.history){const c=g(u.updated).utc(),a=y.point([u.lng,u.lat],{name:n.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?s.roundPrecision(u.pressure/100,0):s.roundPrecision(u.pressure,0),spd:u.speed||u.spd,kts:u.kts,source:u.source,level:u.type,type:"history",category:`${n.name}-history`});t.features.push(a),i.push(a.geometry.coordinates)}const r=n.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const u=y.lineString(s.convertToMonotonicLng2(i),{name:n.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?s.roundPrecision((r==null?void 0:r.pressure)/100,0):s.roundPrecision(r==null?void 0:r.pressure,0),spd:(r==null?void 0:r.speed)||(r==null?void 0:r.spd),kts:r==null?void 0:r.kts,source:r==null?void 0:r.source,level:r==null?void 0:r.type});t.features.push(u)}}}return t}static interpolate(e,t=3){var i,r,u,c;const o=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),n=[];for(const a of o){const m=a.properties.name,p=a.properties.model,l=g(a.properties.date).utc();let M=t*60-(l.get("hour")*60+l.get("minute"))%(t*60);const P=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(f=>!f.properties.disabled&&f.geometry.type==="Point"&&f.properties.type==="forecast"&&f.properties.category===`${m}-${p}`);let S,$=l.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(P,$),S<=P.length-1;){if(S>0){const f=P[S],d=S===0?void 0:P[S-1],N=(M/60-((u=d==null?void 0:d.properties)==null?void 0:u.hour))/(f.properties.hour-((c=d==null?void 0:d.properties)==null?void 0:c.hour)),D=this.computeNumber(d==null?void 0:d.geometry.coordinates[0],f.geometry.coordinates[0],N),z=this.computeNumber(d==null?void 0:d.geometry.coordinates[1],f.geometry.coordinates[1],N),C=y.point([D,z],{name:m,model:p,category:f==null?void 0:f.properties.category,date:$.format(),format:$.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(d==null?void 0:d.properties.gusts,f.properties.gusts,N),hour:this.computeNumber(d==null?void 0:d.properties.hour,f.properties.hour,N),movement:this.computeNumber(d==null?void 0:d.properties.movement,f.properties.movement,N),pressure:this.computeNumber(d==null?void 0:d.properties.pressure,f.properties.pressure,N),wind:this.computeNumber(d==null?void 0:d.properties.wind,f.properties.wind,N),type:"forecast"});n.push(C)}M+=t*60,$=l.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return n}static pickIndex(e,t){let o=0;for(const n of e){if(g(n.properties.date).isAfter(t))return o===0?-1:o;o++}return o}static computeNumber(e,t,o){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const n={};for(const i in e)n[i]=this.computeNumber(e[i],t[i],o);return n}return Math.round((e+(t-e)*o)*100)/100}else return e;else return t}}h.LngLatHelper=s,h.TropicalHelper=k,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -7,6 +7,7 @@ export declare class TropicalHelper {
|
|
|
7
7
|
history: any[];
|
|
8
8
|
}[]): turf.helpers.FeatureCollection<turf.helpers.Geometry, turf.helpers.Properties>;
|
|
9
9
|
static interpolate(tropicals: any, step?: number): turf.helpers.Feature<turf.helpers.Point, {
|
|
10
|
+
name: any;
|
|
10
11
|
model: any;
|
|
11
12
|
category: any;
|
|
12
13
|
date: string;
|
|
@@ -16,6 +17,7 @@ export declare class TropicalHelper {
|
|
|
16
17
|
movement: any;
|
|
17
18
|
pressure: any;
|
|
18
19
|
wind: any;
|
|
20
|
+
type: string;
|
|
19
21
|
}>[];
|
|
20
22
|
private static pickIndex;
|
|
21
23
|
private static computeNumber;
|