@idm-plugin/geo 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -25,12 +25,12 @@ class u {
25
25
  e = u.convertToStdLng(e, t);
26
26
  let s = "E";
27
27
  e < 0 && (s = "W"), e = Math.abs(e), r = r.toUpperCase();
28
- let i = e * 3600, o, n, c, a, m, 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 ? a = u.roundPrecision(c, t).toString().padStart(2, "0") : a = u.padNumber(c, 2, 2), i = i - c * 60), m = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(m, t).toString().padStart(3, "0") : p = u.padNumber(m, 3, 2);
30
- const h = `${r.replace(/S+/gi, n).replace(/M+/gi, a).replace(/H+/gi, p)}${s}`;
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
32
  direction: s,
33
- degree: u.roundPrecision(m, t),
33
+ degree: u.roundPrecision(a, t),
34
34
  minute: u.roundPrecision(c, t),
35
35
  second: u.roundPrecision(o, t),
36
36
  pretty: h
@@ -46,12 +46,12 @@ class u {
46
46
  e = e % 180;
47
47
  let s = "N";
48
48
  e < 0 && (s = "S"), e = Math.abs(e), r = r.toUpperCase();
49
- let i = e * 3600, o, n, c, a, m, 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 ? a = u.roundPrecision(c, t).toString().padStart(2, "0") : a = u.padNumber(c, 2, 2), i = i - c * 60), m = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(m, t).toString().padStart(2, "0") : p = u.padNumber(m, 2, 2);
51
- const h = `${r.replace(/S+/gi, n).replace(/M+/gi, a).replace(/H+/gi, p)}${s}`;
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
53
  direction: s,
54
- degree: u.roundPrecision(m, t),
54
+ degree: u.roundPrecision(a, t),
55
55
  minute: u.roundPrecision(c, t),
56
56
  second: u.roundPrecision(o, t),
57
57
  pretty: h
@@ -159,54 +159,56 @@ class x {
159
159
  if (s.forecasts) {
160
160
  const i = (r = s.history) == null ? void 0 : r[0];
161
161
  for (const o of s.forecasts) {
162
- const n = [], c = y(o.date).utc(), a = `${s.name}-${o.model}`;
162
+ const n = [], c = y(o.date).utc(), m = `${s.name}-${o.model}`;
163
163
  if (i) {
164
- const m = y(i.updated).utc(), p = N.point([i.lng, i.lat], {
164
+ const a = y(i.updated).utc(), p = N.point([i.lng, i.lat], {
165
+ model: o.model,
165
166
  name: s.name,
166
- date: m.format(),
167
+ date: a.format(),
167
168
  hour: 0,
168
- format: m.format("MMM-DD/HHmm[Z]"),
169
+ format: a.format("MMM-DD/HHmm[Z]"),
169
170
  pressure: i.pressure > 1e4 ? u.roundPrecision(i.pressure / 100, 0) : u.roundPrecision(i.pressure, 0),
170
171
  wind: { kts: i.kts, spd: i.speed || i.spd },
171
- category: a,
172
+ category: m,
172
173
  type: "forecast"
173
174
  });
174
175
  t.features.push(p), n.push(p.geometry.coordinates);
175
176
  }
176
- for (const m in o == null ? void 0 : o.hours) {
177
- const p = o.hours[m];
177
+ for (const a in o == null ? void 0 : o.hours) {
178
+ const p = o.hours[a];
178
179
  p.wind.spd = p.wind.spd || p.wind.speed;
179
- const h = c.clone().add(Number(m), "hour"), l = N.point([p.lng, p.lat], {
180
+ const h = c.clone().add(Number(a), "hour"), l = N.point([p.lng, p.lat], {
181
+ model: o.model,
180
182
  name: s.name,
181
183
  date: h.format(),
182
- hour: Number(m),
184
+ hour: Number(a),
183
185
  format: h.format("MMM-DD/HHmm[Z]"),
184
186
  pressure: p.pressure > 1e4 ? u.roundPrecision(p.pressure / 100, 0) : u.roundPrecision(p.pressure, 0),
185
187
  gusts: p.gusts,
186
188
  wind: p.wind || {},
187
189
  movement: p.movement,
188
- category: a,
190
+ category: m,
189
191
  type: "forecast"
190
192
  });
191
193
  t.features.push(l), n.push(l.geometry.coordinates);
192
194
  }
193
195
  if ((n == null ? void 0 : n.length) > 1) {
194
- const m = N.lineString(u.convertToMonotonicLng2(n), {
196
+ const a = N.lineString(u.convertToMonotonicLng2(n), {
195
197
  date: o.date,
196
198
  id: s.id || s.name,
197
199
  model: o.model,
198
200
  name: s.name,
199
- category: a,
201
+ category: m,
200
202
  type: "forecast"
201
203
  });
202
- t.features.push(m);
204
+ t.features.push(a);
203
205
  }
204
206
  }
205
207
  }
206
208
  if (s.history) {
207
209
  const i = [];
208
210
  for (const n of s.history) {
209
- const c = y(n.updated).utc(), a = N.point([n.lng, n.lat], {
211
+ const c = y(n.updated).utc(), m = N.point([n.lng, n.lat], {
210
212
  name: s.name,
211
213
  date: c.format(),
212
214
  format: c.format("MMM-DD/HHmm[Z]"),
@@ -218,7 +220,7 @@ class x {
218
220
  type: "history",
219
221
  category: `${s.name}-history`
220
222
  });
221
- t.features.push(a), i.push(a.geometry.coordinates);
223
+ t.features.push(m), i.push(m.geometry.coordinates);
222
224
  }
223
225
  const o = s.history[0];
224
226
  if (i.length === 1 && i.push(i[0]), i.length > 1) {
@@ -240,18 +242,18 @@ class x {
240
242
  }
241
243
  static interpolate(e, t = 3) {
242
244
  var i, o, n, c;
243
- const r = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
244
- for (const a of r) {
245
- const m = a.properties.name, p = a.properties.model, h = y(a.properties.date).utc();
245
+ 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 = [];
246
+ for (const m of r) {
247
+ const a = m.properties.name, p = m.properties.model, h = y(m.properties.date).utc();
246
248
  let l = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
247
249
  const b = (o = e == null ? void 0 : e.data) == null ? void 0 : o.features.filter(
248
- (f) => f.geometry.type === "Point" && f.properties.type === "forecast" && f.properties.category === `${m}-${p}`
250
+ (f) => f.geometry.type === "Point" && f.properties.type === "forecast" && f.properties.category === `${a}-${p}`
249
251
  );
250
252
  let M, S = h.clone().add(l, "minute").set({ minute: 0, second: 0, millisecond: 0 });
251
253
  for (; M = this.pickIndex(b, S), M <= b.length - 1; ) {
252
254
  if (M > 0) {
253
255
  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], {
254
- name: m,
256
+ name: a,
255
257
  model: p,
256
258
  category: f == null ? void 0 : f.properties.category,
257
259
  date: S.format(),
@@ -260,7 +262,8 @@ class x {
260
262
  hour: this.computeNumber(d == null ? void 0 : d.properties.hour, f.properties.hour, g),
261
263
  movement: this.computeNumber(d == null ? void 0 : d.properties.movement, f.properties.movement, g),
262
264
  pressure: this.computeNumber(d == null ? void 0 : d.properties.pressure, f.properties.pressure, g),
263
- wind: this.computeNumber(d == null ? void 0 : d.properties.wind, f.properties.wind, g)
265
+ wind: this.computeNumber(d == null ? void 0 : d.properties.wind, f.properties.wind, g),
266
+ type: "forecast"
264
267
  });
265
268
  s.push(w);
266
269
  }
@@ -1 +1 @@
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],{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.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)});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"})});
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,m,a,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?m=s.roundPrecision(c,t).toString().padStart(2,"0"):m=s.padNumber(c,2,2),i=i-c*60),a=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(a,t).toString().padStart(3,"0"):p=s.padNumber(a,3,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,m).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(a,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,m,a,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?m=s.roundPrecision(c,t).toString().padStart(2,"0"):m=s.padNumber(c,2,2),i=i-c*60),a=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(a,t).toString().padStart(2,"0"):p=s.padNumber(a,2,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,m).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(a,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(),m=`${n.name}-${r.model}`;if(i){const a=g(i.updated).utc(),p=y.point([i.lng,i.lat],{model:r.model,name:n.name,date:a.format(),hour:0,format:a.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:m,type:"forecast"});t.features.push(p),u.push(p.geometry.coordinates)}for(const a in r==null?void 0:r.hours){const p=r.hours[a];p.wind.spd=p.wind.spd||p.wind.speed;const l=c.clone().add(Number(a),"hour"),M=y.point([p.lng,p.lat],{model:r.model,name:n.name,date:l.format(),hour:Number(a),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:m,type:"forecast"});t.features.push(M),u.push(M.geometry.coordinates)}if((u==null?void 0:u.length)>1){const a=y.lineString(s.convertToMonotonicLng2(u),{date:r.date,id:n.id||n.name,model:r.model,name:n.name,category:m,type:"forecast"});t.features.push(a)}}}if(n.history){const i=[];for(const u of n.history){const c=g(u.updated).utc(),m=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(m),i.push(m.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(m=>m.geometry.type==="LineString"&&m.properties.type==="forecast"),n=[];for(const m of o){const a=m.properties.name,p=m.properties.model,l=g(m.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.geometry.type==="Point"&&f.properties.type==="forecast"&&f.properties.category===`${a}-${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:a,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"})});
@@ -17,6 +17,7 @@ export declare class TropicalHelper {
17
17
  movement: any;
18
18
  pressure: any;
19
19
  wind: any;
20
+ type: string;
20
21
  }>[];
21
22
  private static pickIndex;
22
23
  private static computeNumber;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "description": "idm plugin for geo",
6
6
  "type": "module",
7
7
  "keywords": [