@idm-plugin/geo 1.2.7 → 1.2.8
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 +4 -4
- package/dist/index.umd.cjs +1 -1
- package/dist/tropicals/src/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -886,7 +886,7 @@ class U {
|
|
|
886
886
|
let b, C = h.clone().add(S, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
887
887
|
for (; b = this.pickIndex(m, C), b <= m.length - 1; ) {
|
|
888
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)),
|
|
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)), x = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], T.geometry.coordinates[0], M), I = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], T.geometry.coordinates[1], M), $ = g.point([x, I], {
|
|
890
890
|
name: d,
|
|
891
891
|
model: u,
|
|
892
892
|
category: T == null ? void 0 : T.properties.category,
|
|
@@ -918,7 +918,7 @@ class U {
|
|
|
918
918
|
* @param speed 前进速度
|
|
919
919
|
* @param options
|
|
920
920
|
*/
|
|
921
|
-
static diversionPassageAt(e, t, n, o = {
|
|
921
|
+
static diversionPassageAt(e, t, n, o = {}) {
|
|
922
922
|
const { t1: i, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(t, 24, o);
|
|
923
923
|
if (i && s) {
|
|
924
924
|
const a = P.calculateBearing(e, i), d = P.calculateBearing(i, s), u = Math.abs(a - d);
|
|
@@ -947,7 +947,7 @@ class U {
|
|
|
947
947
|
* @param radius 与台风中心的距离
|
|
948
948
|
* @param options
|
|
949
949
|
*/
|
|
950
|
-
static driftPassageAt(e, t, n, o = {
|
|
950
|
+
static driftPassageAt(e, t, n, o = {}) {
|
|
951
951
|
const { t1: i, t2: s, hr: r, hours: c } = this.tropicalCenterTwin(t, 24, o);
|
|
952
952
|
if (i && s) {
|
|
953
953
|
const a = P.calculateBearing(e, i), d = P.calculateBearing(i, s), u = P.calculateDistance(e, i);
|
|
@@ -962,7 +962,7 @@ class U {
|
|
|
962
962
|
* @param options
|
|
963
963
|
* @private
|
|
964
964
|
*/
|
|
965
|
-
static tropicalCenterTwin(e, t = 24, n = {
|
|
965
|
+
static tropicalCenterTwin(e, t = 24, n = {}) {
|
|
966
966
|
var d, u, f, h, S;
|
|
967
967
|
let o = {};
|
|
968
968
|
(d = e.forecasts) == null || d.forEach((m) => {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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"})});
|
|
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 x{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(P=>{x.prototype[P.toLowerCase()]=()=>{},x.prototype[`is${P}Enabled`]=()=>!1});const I=(()=>{try{return require("log4js")}catch{return null}})();var L={getLogger:I?I.getLogger:()=>new x};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={}){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={}){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={}){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"})});
|
|
@@ -44,7 +44,7 @@ export declare class TropicalHelper {
|
|
|
44
44
|
lat: number;
|
|
45
45
|
lng: number;
|
|
46
46
|
}, tropical: any, radius: number, options?: {
|
|
47
|
-
requestId
|
|
47
|
+
requestId?: string;
|
|
48
48
|
}): {
|
|
49
49
|
at: {
|
|
50
50
|
lng: number;
|
|
@@ -75,7 +75,7 @@ export declare class TropicalHelper {
|
|
|
75
75
|
lat: number;
|
|
76
76
|
lng: number;
|
|
77
77
|
}, tropical: any, radius: number, options?: {
|
|
78
|
-
requestId
|
|
78
|
+
requestId?: string;
|
|
79
79
|
}): {
|
|
80
80
|
at: {
|
|
81
81
|
lng: number;
|