@idm-plugin/geo 1.1.4 → 1.1.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/README.md +1 -1
- package/dist/index.js +2 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/tropicals/src/index.d.ts +1 -0
- package/package.json +69 -69
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
## Geo Plugin
|
|
1
|
+
## Geo Plugin
|
|
2
2
|
Geo插件
|
package/dist/index.js
CHANGED
|
@@ -897,7 +897,8 @@ class q {
|
|
|
897
897
|
movement: this.computeNumber(h == null ? void 0 : h.properties.movement, m.properties.movement, b),
|
|
898
898
|
pressure: this.computeNumber(h == null ? void 0 : h.properties.pressure, m.properties.pressure, b),
|
|
899
899
|
wind: this.computeNumber(h == null ? void 0 : h.properties.wind, m.properties.wind, b),
|
|
900
|
-
type: "forecast"
|
|
900
|
+
type: "forecast",
|
|
901
|
+
showCircle: a.showCircle
|
|
901
902
|
});
|
|
902
903
|
o.push(I);
|
|
903
904
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(M,I){typeof exports=="object"&&typeof module<"u"?I(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"],I):(M=typeof globalThis<"u"?globalThis:M||self,I(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,I,D,q,W){"use strict";function F(T){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const t in T)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(T,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>T[t]})}}return e.default=T,Object.freeze(e)}const g=F(I);function O(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(T=>{j.prototype[T.toLowerCase()]=()=>{},j.prototype[`is${T}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var E={getLogger:k?k.getLogger:()=>new j};const A=O(E);class l{static guessTimeZoneOffset(e,t){const n=W(t,e),o=D().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(3,"0"):a=l.padNumber(d,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(2,"0"):a=l.padNumber(d,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>360&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(r??0)/60,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>90&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(r??0)/60,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,i=Number(o.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${o}E`:i<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${i>0?"E":"W"}`:e=`${o}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${i}`}}class S{static calculateBearing(e,t,n=!0,o=4){const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=g.rhumbBearing(i.features[0],i.features[1]):s=g.bearing(i.features[0],i.features[1]),s<0&&(s+=360),l.roundPrecision(s,o)}static calculateDistance(e,t,n=!0,o=4,i="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(s.features[0],s.features[1],{units:i}):r=g.distance(s.features[0],s.features[1],{units:i}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,i;for(const s of e)for(let r=0;r<s.length-1;r++){const c={lng:s[r][0],lat:s[r][1]};r===0&&i&&(o+=this.calculateDistance(i,c,!0,t,n));const u={lng:s[r+1][0],lat:s[r+1][1]};o+=this.calculateDistance(c,u,!0,t,n),i=u}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",i=!0){const s=g.point([e.lng,e.lat]);let r;i?r=g.rhumbDestination(s,n,t,{units:o}):r=g.destination(s,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,i=!0,s="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),u=this.calculateDistance(e,t,!1,8,s);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<u;)d+=n,d<u&&r.push(this.calculateCoordinate(e,c,d,s,!1));return i&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let i,s;for(let r=0;r<e.length-1;r++){i=l.convertToStdLng(e[r].lng,8),s=l.convertToStdLng(e[r+1].lng,8),n.push([i,e[r].lat]);const c=i-s;if(Math.abs(c)>180){const u=l.convertToMonotonicLng2([[i,e[r].lat],[s,e[r+1].lat]]);let d,a;t?(d=g.lineString(u),a=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(u[0],u[1]),a=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(d,a);let h;if(p.features.length){const C=g.getCoord(p.features[0]);h=l.roundPrecision(C[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),o.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),o.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([s,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((i,s)=>(i.findIndex(r=>r[0]===s[0]&&r[1]===s[1])===-1&&i.push(s),i),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,i=0,s,r;return t.forEach((c,u)=>{for(let d=0;d<c.length-1;d++){const a={lng:c[d][0],lat:c[d][1]},p={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(e,a,p);n>h&&(n=h,i=d,o=u,s=this.calculateDistance(a,e),r=this.calculateDistance(p,e))}}),s!==0&&r!==0?t[o].splice(i+1,0,[e.lng,e.lat]):s===0?t[o].splice(i,1,[e.lng,e.lat]):r===0&&t[o].splice(i+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=S.convertRouteToCoordinates(t);return n.push(e),S.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=S.convertRouteToCoordinates(t);return n.unshift(e),S.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let i=0;return n.forEach(s=>{if(i===2)return;const r=[];for(const c of s){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),i===0&&r.push([e.lng,e.lat]),i=2;break}i===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(i=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const i=this.convertRouteToCoordinates(n,0),s=this.mergeCoordinatesToWaypoints([e,t,...o],i),r=s.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=s.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return s.filter((d,a)=>a>=r&&a<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,i=0;return t.forEach((s,r)=>{for(let c=0;c<s.length-1;c++){const u={lng:s[c][0],lat:s[c][1]},d={lng:s[c+1][0],lat:s[c+1][1]},a=this.calculatePointToLineDistance(e,u,d);n>a&&(n=a,o=c,i=r)}}),{minDist:n,segIndex:i,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let s=!0;for(let r=n;r<t.length;r++)if(s){const c=[];c.push([e.lng,e.lat]);for(let u=o+1;u<t[r].length;u++)e.lng===t[r][u][0]&&e.lat===t[r][u][1]||c.push(t[r][u]);i.push(c),s=!1}else i.push([...t[r]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let s=0;s<t.length-1;s++){const r=t[s],c=t[s+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,a)=>a>0);const u=this.calculatePointToLineDistance(e,r,c);n>u&&(n=u,o=s)}e.lng=l.convertToStdLng(e.lng);const i=[e];for(let s=o+1;s<t.length;s++)i.push(t[s]);return i}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const i=l.convertToMonotonicLng([t,n]);t=i[0],n=i[1];const s=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),s,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),s,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],i=e[n+1],s=this.calculateRangeRoute(o,i,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),i.distanceFromPrevious=this.calculateRouteDistance(s),i.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+i.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,i=0,s=0,r=0;for(let c=0;c<t.length-1;c++){const u={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},a=this.calculatePointToLineDistance(e,u,d);o>=a&&(o=a,i=c,s=this.calculateDistance(u,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return s!==0&&r!==0?s<o||s===o&&i===0?t.unshift(e):r<o||r===o&&i===t.length-2?t.push(e):t.splice(i+1,0,e):s===0?n&&t.splice(i,1,e):r===0&&n&&t.splice(i+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],i=e[n];if(n===1&&t.push(o),i.gcToPrevious){const s=this.interpolateCoordinates(o,i,200,!1,!0,"nauticalmiles");t.push(...s)}else t.push(i)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const u=c.map(d=>g.point(d));o.push(...u)}const i=g.featureCollection(o),s=g.nearestPoint(n,i),r=g.getCoord(s);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const i=t[o],s=t[o+1];if(this.calculateDistance(e,i)===0){n=o;break}if(this.calculateDistance(e,s)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var p;const i=e.speed||12,s=[];let r=[],c=!1,u=0,d=0,a;if(t&&n.length?(s.push(e),n.forEach((h,C)=>{if(c)r.push(h);else{const P=[];let b;for(let m=0;m<h.length;m++)if(a)P.push(h[m]);else{b={lng:h[m][0],lat:h[m][1]};const f=this.calculateDistance(e,b,!0,8,o);if(u+=f,u<t)d+=f,s.push(b),e=b;else{if(d=t,u===t)a=b,P.push([a.lng,a.lat]);else{const v=u-t,R=this.calculateBearing(b,e);a=this.calculateCoordinate(b,R,v,o),P.push([a.lng,a.lat]),P.push([b.lng,b.lat])}c=!0}}P.length&&r.push(P),C===n.length-1&&!a&&(a=b)}})):(r=n,a={...e}),a)if(s.push(a),a.distanceFromPrevious=d,a.hourFromPrevious=Math.round(d/i*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};a.bearing=this.calculateBearing(a,h)}else a.bearing=0;return{coordinate:a,nextRoute:r,prevRoute:s}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),i=g.point([o,e.lat]),s=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[s,t.lat],[r,n.lat]]),u=g.nearestPointOnLine(c,i),d=g.getCoord(u),a=l.roundPrecision(d[0],6),p=l.roundPrecision(d[1],6);return{lng:a,lat:p,inline:!(a===s&&p===t.lat)&&!(a===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,i;return e.forEach(s=>{s.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!i)n.push(c),i=c;else if(i.bearing===void 0)i.bearing=this.calculateBearing(i,c,!0);else{const u=this.calculateDistance(o,c,!0);u&&u>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),i=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e)});for(let o=1;o<t.length;o++){const i=t[o-1],s=t[o];if(s.gcToPrevious){const r=e.findIndex(u=>u.lng===i.lng&&u.lat===i.lat),c=e.findIndex(u=>u.lng===s.lng&&u.lat===s.lat);for(let u=c-1;u>r;u--)e.splice(u,1)}}let n=0;for(let o=1;o<e.length;o++){const i=e[o-1],s=e[o];s.gcToPrevious?(i.bearing=this.calculateBearing(i,s,!1),s.distanceFromPrevious=this.calculateDistance(i,s,!1)):(i.bearing=this.calculateBearing(i,s,!0),s.distanceFromPrevious=this.calculateDistance(i,s,!0)),n=l.roundPrecision(n+s.distanceFromPrevious),s.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const s=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(s[0],8),lat:l.roundPrecision(s[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const i of e)for(const s of i)t.push(s);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}const y=A.getLogger("vessel");class B{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const i=(n=o.history)==null?void 0:n[0];for(const s of o.forecasts){const r=[],c=D(s.date).utc(),u=`${o.name}-${s.model}`;if(i){const d=D(i.updated).utc(),a=g.point([i.lng,i.lat],{model:s.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?l.roundPrecision(i.pressure/100,0):l.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:u,type:"forecast"});t.features.push(a),r.push(a.geometry.coordinates)}for(const d in s==null?void 0:s.hours){const a=s.hours[d];a.wind.spd=a.wind.spd||a.wind.speed;const p=c.clone().add(Number(d),"hour"),h=g.point([a.lng,a.lat],{model:s.model,name:o.name,date:p.format(),hour:Number(d),format:p.format("MMM-DD/HHmm[Z]"),pressure:a.pressure>1e4?l.roundPrecision(a.pressure/100,0):l.roundPrecision(a.pressure,0),gusts:a.gusts,wind:a.wind||{},movement:a.movement,category:u,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:s.date,id:o.id||o.name,model:s.model,name:o.name,category:u,type:"forecast"});t.features.push(d)}}}if(o.history){const i=[];for(const r of o.history){const c=D(r.updated).utc(),u=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(u),i.push(u.geometry.coordinates)}const s=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const r=g.lineString(l.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?l.roundPrecision((s==null?void 0:s.pressure)/100,0):l.roundPrecision(s==null?void 0:s.pressure,0),spd:(s==null?void 0:s.speed)||(s==null?void 0:s.spd),kts:s==null?void 0:s.kts,source:s==null?void 0:s.source,level:s==null?void 0:s.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var i,s,r,c;const n=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(u=>u.geometry.type==="LineString"&&u.properties.type==="forecast"),o=[];for(const u of n){const d=u.properties.name,a=u.properties.model,p=D(u.properties.date).utc();let h=t*60-(p.get("hour")*60+p.get("minute"))%(t*60);const C=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${d}-${a}`);let P,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(C,b),P<=C.length-1;){if(P>0){const m=C[P],f=P===0?void 0:C[P-1],v=(h/60-((r=f==null?void 0:f.properties)==null?void 0:r.hour))/(m.properties.hour-((c=f==null?void 0:f.properties)==null?void 0:c.hour)),R=this.computeNumber(f==null?void 0:f.geometry.coordinates[0],m.geometry.coordinates[0],v),x=this.computeNumber(f==null?void 0:f.geometry.coordinates[1],m.geometry.coordinates[1],v),$=g.point([R,x],{name:d,model:a,category:m==null?void 0:m.properties.category,date:b.format(),format:b.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(f==null?void 0:f.properties.gusts,m.properties.gusts,v),hour:this.computeNumber(f==null?void 0:f.properties.hour,m.properties.hour,v),movement:this.computeNumber(f==null?void 0:f.properties.movement,m.properties.movement,v),pressure:this.computeNumber(f==null?void 0:f.properties.pressure,m.properties.pressure,v),wind:this.computeNumber(f==null?void 0:f.properties.wind,m.properties.wind,v),type:"forecast"});o.push($)}h+=t*60,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o,i={requestId:""}){var d,a,p,h,C,P,b,m,f;const s=(a=(d=t==null?void 0:t.forecasts)==null?void 0:d[0])==null?void 0:a.hours,r=((p=t==null?void 0:t.history)==null?void 0:p[0])||(s==null?void 0:s[(h=Object.keys(s))==null?void 0:h[0]]);y.info("[%s] the first evasion point: %j",i.requestId,r);const c=(C=Object.keys(s||{}).filter(v=>Number(v)<=24))==null?void 0:C.at(-1),u=s==null?void 0:s[c||-1];if(y.info("[%s] the second evasion point in %s hrs: %j",i.requestId,c,r),r&&u){const v=S.calculateBearing(e,r),R=S.calculateBearing(r,u),x=S.calculateCoordinate(r,v-R+90,n);y.info("[%s] the right tangent point: %j",i.requestId,{from:e,p1:r,p2:u,radius:n,bearing1:v,bearing2:R,right:x});const $=S.calculateBearing(e,x);let N=S.calculateCoordinate(e,$,o*Number(c));N.utc=D((b=(P=t==null?void 0:t.forecasts)==null?void 0:P[0])==null?void 0:b.date).add(Number(c),"hours").utc().format(),y.info("[%s] the temp evasion point: %j",i.requestId,N);const L=S.calculateDistance(N,u);return y.info("[%s] the distance(%d) between tmp & p2: %j - %j",i.requestId,L,N,u),L<n&&(N=S.calculateCoordinate(e,$,o*Number(c)/2),N.utc=D((f=(m=t==null?void 0:t.forecasts)==null?void 0:m[0])==null?void 0:f.date).add(Number(c)/2,"hours").utc().format(),y.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j",i.requestId,N)),N}else{y.info("[%s] no need evasion: %j",i.requestId,{from:e,p1:r,p2:u});return}}static pickIndex(e,t){let n=0;for(const o of e){if(D(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const i in e)o[i]=this.computeNumber(e[i],t[i],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}M.LaneHelper=S,M.LngLatHelper=l,M.TropicalHelper=B,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(C,I){typeof exports=="object"&&typeof module<"u"?I(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"],I):(C=typeof globalThis<"u"?globalThis:C||self,I(C["idm-plugin-rabbitmq"]={},C["@turf/turf"],C.moment,C["moment-timezone"],C["tz-lookup"]))})(this,function(C,I,D,q,W){"use strict";function F(T){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(T){for(const t in T)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(T,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>T[t]})}}return e.default=T,Object.freeze(e)}const g=F(I);function O(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(T=>{j.prototype[T.toLowerCase()]=()=>{},j.prototype[`is${T}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var E={getLogger:k?k.getLogger:()=>new j};const A=O(E);class l{static guessTimeZoneOffset(e,t){const n=W(t,e),o=D().tz(n).utcOffset();return this.roundPrecision(o/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),n=Math.round((Math.abs(e)-t)*60);return n=n>9?n:`0${n}`,t=t>9?t:`0${t}`,e>0?`+${t}:${n}`:`-${t}:${n}`}static lng2pretty(e,t=6,n="H°M′"){e=l.convertToStdLng(e,t);let o="E";e<0&&(o="W"),e=Math.abs(e),n=n.toUpperCase();let i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(3,"0"):a=l.padNumber(d,3,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let o="N";e<0&&(o="S"),e=Math.abs(e),n=n.toUpperCase();let i=e*3600,s,r,c,u,d,a;s=i%3600%60,n.indexOf("S")!==-1&&(i=i-s,r=l.padNumber(s,2,2)),c=i/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?u=l.roundPrecision(c,t).toString().padStart(2,"0"):u=l.padNumber(c,2,2),i=i-c*60),d=i/3600,n.indexOf("M")!==-1?a=l.roundPrecision(d,t).toString().padStart(2,"0"):a=l.padNumber(d,2,2);const p=`${n.replace(/S+/gi,r).replace(/M+/gi,u).replace(/H+/gi,a)}${o}`;return{direction:o,degree:l.roundPrecision(d,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(s,t),pretty:p}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>360&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(r??0)/60,o==="W"&&(n=n*-1)}else n=Number(e);return l.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LAT");const o=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[s,r]=i;if(r=r>60?r/Math.pow(10,String(r).length-2):r,s>90&&!r){const c=this.roundPrecision(s/100,0);r=s-c*100,s=c}n=s+(r??0)/60,o==="S"&&(n=n*-1)}else n=Number(e);return l.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=l.strReplace(e,n);const o=e[e.length-1].toUpperCase();return["N","S"].includes(o)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),l.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const n=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const o=e,i=Number(o.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${o}E`:i<=-90?e=`${o}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${o}${i>0?"E":"W"}`:e=`${o}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const o=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${o}.${i}`}}class S{static calculateBearing(e,t,n=!0,o=4){const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let s;return n?s=g.rhumbBearing(i.features[0],i.features[1]):s=g.bearing(i.features[0],i.features[1]),s<0&&(s+=360),l.roundPrecision(s,o)}static calculateDistance(e,t,n=!0,o=4,i="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,o),t.lng=l.convertToStdLng(t.lng,o);const s=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(s.features[0],s.features[1],{units:i}):r=g.distance(s.features[0],s.features[1],{units:i}),l.roundPrecision(r,o)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let o=0,i;for(const s of e)for(let r=0;r<s.length-1;r++){const c={lng:s[r][0],lat:s[r][1]};r===0&&i&&(o+=this.calculateDistance(i,c,!0,t,n));const u={lng:s[r+1][0],lat:s[r+1][1]};o+=this.calculateDistance(c,u,!0,t,n),i=u}return l.roundPrecision(o,t)}static calculateCoordinate(e,t,n,o="nauticalmiles",i=!0){const s=g.point([e.lng,e.lat]);let r;i?r=g.rhumbDestination(s,n,t,{units:o}):r=g.destination(s,n,t,{units:o});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,o=!0,i=!0,s="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),u=this.calculateDistance(e,t,!1,8,s);o&&r.push({lng:e.lng,lat:e.lat});let d=0;for(;d<u;)d+=n,d<u&&r.push(this.calculateCoordinate(e,c,d,s,!1));return i&&r.push({lng:t.lng,lat:t.lat}),r}static divideAccordingToLng(e,t=!1){if((e==null?void 0:e.length)<2)return[];e=this.deduplicateCoordinates(e);let n=[];const o=[];let i,s;for(let r=0;r<e.length-1;r++){i=l.convertToStdLng(e[r].lng,8),s=l.convertToStdLng(e[r+1].lng,8),n.push([i,e[r].lat]);const c=i-s;if(Math.abs(c)>180){const u=l.convertToMonotonicLng2([[i,e[r].lat],[s,e[r+1].lat]]);let d,a;t?(d=g.lineString(u),a=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(d=g.greatCircle(u[0],u[1]),a=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const p=g.lineIntersect(d,a);let h;if(p.features.length){const M=g.getCoord(p.features[0]);h=l.roundPrecision(M[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),o.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),o.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([s,e[r+1].lat])}return o.push(n),o}static deduplicateRoute(e){const t=[];for(const n of e){const o=n.reduce((i,s)=>(i.findIndex(r=>r[0]===s[0]&&r[1]===s[1])===-1&&i.push(s),i),[]);t.push(o)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(o=>o.lat===n.lat&&o.lng===n.lng)===-1&&t.push(n),t),[])}static removeCoordinateFromRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);for(const n of t)for(let o=n.length-1;o>=0;o--)l.roundPrecision(n[o][0],8)===e.lng&&l.roundPrecision(n[o][1],8)===l.roundPrecision(e.lat,8)&&n.splice(o,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=l.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)l.roundPrecision(t[n].lng,8)===e.lng&&l.roundPrecision(t[n].lat,8)===l.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,o=0,i=0,s,r;return t.forEach((c,u)=>{for(let d=0;d<c.length-1;d++){const a={lng:c[d][0],lat:c[d][1]},p={lng:c[d+1][0],lat:c[d+1][1]},h=this.calculatePointToLineDistance(e,a,p);n>h&&(n=h,i=d,o=u,s=this.calculateDistance(a,e),r=this.calculateDistance(p,e))}}),s!==0&&r!==0?t[o].splice(i+1,0,[e.lng,e.lat]):s===0?t[o].splice(i,1,[e.lng,e.lat]):r===0&&t[o].splice(i+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=S.convertRouteToCoordinates(t);return n.push(e),S.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=S.convertRouteToCoordinates(t);return n.unshift(e),S.divideAccordingToLng(n)}static mergeWaypointsToRoute(e,t){for(const n of e)t=this.mergeCoordinateToRoute(n,t);return t}static calculateRangeRoute(e,t,n){n=this.mergeWaypointsToRoute([e,t],n);const o=[];let i=0;return n.forEach(s=>{if(i===2)return;const r=[];for(const c of s){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),i===0&&r.push([e.lng,e.lat]),i=2;break}i===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(i=1,r.push(c))}r.length&&o.push(r)}),o}static calculateRangeWaypoints(e,t,n,o=[]){const i=this.convertRouteToCoordinates(n,0),s=this.mergeCoordinatesToWaypoints([e,t,...o],i),r=s.findIndex(d=>l.roundPrecision(e.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(d.lat,8)),c=s.findIndex(d=>l.roundPrecision(t.lng,8)===l.roundPrecision(d.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(d.lat,8));return s.filter((d,a)=>a>=r&&a<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,o=0,i=0;return t.forEach((s,r)=>{for(let c=0;c<s.length-1;c++){const u={lng:s[c][0],lat:s[c][1]},d={lng:s[c+1][0],lat:s[c+1][1]},a=this.calculatePointToLineDistance(e,u,d);n>a&&(n=a,o=c,i=r)}}),{minDist:n,segIndex:i,minIndex:o}}static calculateSubRoute(e,t){const{segIndex:n,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let s=!0;for(let r=n;r<t.length;r++)if(s){const c=[];c.push([e.lng,e.lat]);for(let u=o+1;u<t[r].length;u++)e.lng===t[r][u][0]&&e.lat===t[r][u][1]||c.push(t[r][u]);i.push(c),s=!1}else i.push([...t[r]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,o=0;for(let s=0;s<t.length-1;s++){const r=t[s],c=t[s+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((d,a)=>a>0);const u=this.calculatePointToLineDistance(e,r,c);n>u&&(n=u,o=s)}e.lng=l.convertToStdLng(e.lng);const i=[e];for(let s=o+1;s<t.length;s++)i.push(t[s]);return i}static calculatePointToLineDistance(e,t,n,o={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const i=l.convertToMonotonicLng([t,n]);t=i[0],n=i[1];const s=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),s,o),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),s,o);return l.roundPrecision(Math.min(r,c),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const o=e[n],i=e[n+1],s=this.calculateRangeRoute(o,i,t);n===0&&(o.distanceFromPrevious=0,o.distanceFromStart=0),i.distanceFromPrevious=this.calculateRouteDistance(s),i.distanceFromStart=l.roundPrecision((o.distanceFromStart||0)+i.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const o of e)this.mergeCoordinateToWaypoints(o,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let o=Number.MAX_VALUE,i=0,s=0,r=0;for(let c=0;c<t.length-1;c++){const u={lng:t[c].lng,lat:t[c].lat},d={lng:t[c+1].lng,lat:t[c+1].lat},a=this.calculatePointToLineDistance(e,u,d);o>=a&&(o=a,i=c,s=this.calculateDistance(u,e,!1,6),r=this.calculateDistance(d,e,!1,6))}return s!==0&&r!==0?s<o||s===o&&i===0?t.unshift(e):r<o||r===o&&i===t.length-2?t.push(e):t.splice(i+1,0,e):s===0?n&&t.splice(i,1,e):r===0&&n&&t.splice(i+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const o=e[n-1],i=e[n];if(n===1&&t.push(o),i.gcToPrevious){const s=this.interpolateCoordinates(o,i,200,!1,!0,"nauticalmiles");t.push(...s)}else t.push(i)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=[];for(const c of t){const u=c.map(d=>g.point(d));o.push(...u)}const i=g.featureCollection(o),s=g.nearestPoint(n,i),r=g.getCoord(s);return{lng:r[0],lat:r[1]}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let o=0;o<t.length-1;o++){const i=t[o],s=t[o+1];if(this.calculateDistance(e,i)===0){n=o;break}if(this.calculateDistance(e,s)===0){n=o+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,o="nauticalmiles"){var p;const i=e.speed||12,s=[];let r=[],c=!1,u=0,d=0,a;if(t&&n.length?(s.push(e),n.forEach((h,M)=>{if(c)r.push(h);else{const P=[];let b;for(let m=0;m<h.length;m++)if(a)P.push(h[m]);else{b={lng:h[m][0],lat:h[m][1]};const f=this.calculateDistance(e,b,!0,8,o);if(u+=f,u<t)d+=f,s.push(b),e=b;else{if(d=t,u===t)a=b,P.push([a.lng,a.lat]);else{const v=u-t,R=this.calculateBearing(b,e);a=this.calculateCoordinate(b,R,v,o),P.push([a.lng,a.lat]),P.push([b.lng,b.lat])}c=!0}}P.length&&r.push(P),M===n.length-1&&!a&&(a=b)}})):(r=n,a={...e}),a)if(s.push(a),a.distanceFromPrevious=d,a.hourFromPrevious=Math.round(d/i*1e4)/1e4,((p=r[0])==null?void 0:p.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};a.bearing=this.calculateBearing(a,h)}else a.bearing=0;return{coordinate:a,nextRoute:r,prevRoute:s}}static nearestCoordinateInLine(e,t,n){const o=l.convertToStdLng(e.lng,6),i=g.point([o,e.lat]),s=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[s,t.lat],[r,n.lat]]),u=g.nearestPointOnLine(c,i),d=g.getCoord(u),a=l.roundPrecision(d[0],6),p=l.roundPrecision(d[1],6);return{lng:a,lat:p,inline:!(a===s&&p===t.lat)&&!(a===r&&p===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let o,i;return e.forEach(s=>{s.forEach(r=>{const c={lng:r[0],lat:r[1]};if(!i)n.push(c),i=c;else if(i.bearing===void 0)i.bearing=this.calculateBearing(i,c,!0);else{const u=this.calculateDistance(o,c,!0);u&&u>=t&&(o.bearing=this.calculateBearing(o,c,!0),n.push(o),i=o)}o=c})}),o&&n.push(o),n}static simplifyRouteToCoordinates(e,t,n=1){let o=this.convertRouteToCoordinates(e,n);return o=this.simplifyGCCoordinates(o,t),o}static simplifyGCCoordinates(e,t){t.forEach(o=>{this.mergeCoordinateToWaypoints(o,e)});for(let o=1;o<t.length;o++){const i=t[o-1],s=t[o];if(s.gcToPrevious){const r=e.findIndex(u=>u.lng===i.lng&&u.lat===i.lat),c=e.findIndex(u=>u.lng===s.lng&&u.lat===s.lat);for(let u=c-1;u>r;u--)e.splice(u,1)}}let n=0;for(let o=1;o<e.length;o++){const i=e[o-1],s=e[o];s.gcToPrevious?(i.bearing=this.calculateBearing(i,s,!1),s.distanceFromPrevious=this.calculateDistance(i,s,!1)):(i.bearing=this.calculateBearing(i,s,!0),s.distanceFromPrevious=this.calculateDistance(i,s,!0)),n=l.roundPrecision(n+s.distanceFromPrevious),s.distanceFromStart=n}return e.map(o=>(o.lng=l.convertToStdLng(o.lng),o))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),o=l.convertToMonotonicLng2(t);for(const r of o)n.features.push(g.point(r));const s=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(s[0],8),lat:l.roundPrecision(s[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const i of e)for(const s of i)t.push(s);const n=l.convertToMonotonicLng2(t),o=g.lineString(n);return g.bbox(o)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}const y=A.getLogger("vessel");class B{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const o of e){if(o.forecasts){const i=(n=o.history)==null?void 0:n[0];for(const s of o.forecasts){const r=[],c=D(s.date).utc(),u=`${o.name}-${s.model}`;if(i){const d=D(i.updated).utc(),a=g.point([i.lng,i.lat],{model:s.model,name:o.name,date:d.format(),hour:0,format:d.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?l.roundPrecision(i.pressure/100,0):l.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:u,type:"forecast"});t.features.push(a),r.push(a.geometry.coordinates)}for(const d in s==null?void 0:s.hours){const a=s.hours[d];a.wind.spd=a.wind.spd||a.wind.speed;const p=c.clone().add(Number(d),"hour"),h=g.point([a.lng,a.lat],{model:s.model,name:o.name,date:p.format(),hour:Number(d),format:p.format("MMM-DD/HHmm[Z]"),pressure:a.pressure>1e4?l.roundPrecision(a.pressure/100,0):l.roundPrecision(a.pressure,0),gusts:a.gusts,wind:a.wind||{},movement:a.movement,category:u,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const d=g.lineString(l.convertToMonotonicLng2(r),{date:s.date,id:o.id||o.name,model:s.model,name:o.name,category:u,type:"forecast"});t.features.push(d)}}}if(o.history){const i=[];for(const r of o.history){const c=D(r.updated).utc(),u=g.point([r.lng,r.lat],{name:o.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?l.roundPrecision(r.pressure/100,0):l.roundPrecision(r.pressure,0),spd:r.speed||r.spd,kts:r.kts,source:r.source,level:r.type,type:"history",category:`${o.name}-history`});t.features.push(u),i.push(u.geometry.coordinates)}const s=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const r=g.lineString(l.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:s==null?void 0:s.updated,pressure:(s==null?void 0:s.pressure)>1e4?l.roundPrecision((s==null?void 0:s.pressure)/100,0):l.roundPrecision(s==null?void 0:s.pressure,0),spd:(s==null?void 0:s.speed)||(s==null?void 0:s.spd),kts:s==null?void 0:s.kts,source:s==null?void 0:s.source,level:s==null?void 0:s.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var i,s,r,c;const n=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(u=>u.geometry.type==="LineString"&&u.properties.type==="forecast"),o=[];for(const u of n){const d=u.properties.name,a=u.properties.model,p=D(u.properties.date).utc();let h=t*60-(p.get("hour")*60+p.get("minute"))%(t*60);const M=(s=e==null?void 0:e.data)==null?void 0:s.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${d}-${a}`);let P,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;P=this.pickIndex(M,b),P<=M.length-1;){if(P>0){const m=M[P],f=P===0?void 0:M[P-1],v=(h/60-((r=f==null?void 0:f.properties)==null?void 0:r.hour))/(m.properties.hour-((c=f==null?void 0:f.properties)==null?void 0:c.hour)),R=this.computeNumber(f==null?void 0:f.geometry.coordinates[0],m.geometry.coordinates[0],v),x=this.computeNumber(f==null?void 0:f.geometry.coordinates[1],m.geometry.coordinates[1],v),$=g.point([R,x],{name:d,model:a,category:m==null?void 0:m.properties.category,date:b.format(),format:b.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(f==null?void 0:f.properties.gusts,m.properties.gusts,v),hour:this.computeNumber(f==null?void 0:f.properties.hour,m.properties.hour,v),movement:this.computeNumber(f==null?void 0:f.properties.movement,m.properties.movement,v),pressure:this.computeNumber(f==null?void 0:f.properties.pressure,m.properties.pressure,v),wind:this.computeNumber(f==null?void 0:f.properties.wind,m.properties.wind,v),type:"forecast",showCircle:u.showCircle});o.push($)}h+=t*60,b=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return o}static diversionPassageAt(e,t,n,o,i={requestId:""}){var d,a,p,h,M,P,b,m,f;const s=(a=(d=t==null?void 0:t.forecasts)==null?void 0:d[0])==null?void 0:a.hours,r=((p=t==null?void 0:t.history)==null?void 0:p[0])||(s==null?void 0:s[(h=Object.keys(s))==null?void 0:h[0]]);y.info("[%s] the first evasion point: %j",i.requestId,r);const c=(M=Object.keys(s||{}).filter(v=>Number(v)<=24))==null?void 0:M.at(-1),u=s==null?void 0:s[c||-1];if(y.info("[%s] the second evasion point in %s hrs: %j",i.requestId,c,r),r&&u){const v=S.calculateBearing(e,r),R=S.calculateBearing(r,u),x=S.calculateCoordinate(r,v-R+90,n);y.info("[%s] the right tangent point: %j",i.requestId,{from:e,p1:r,p2:u,radius:n,bearing1:v,bearing2:R,right:x});const $=S.calculateBearing(e,x);let N=S.calculateCoordinate(e,$,o*Number(c));N.utc=D((b=(P=t==null?void 0:t.forecasts)==null?void 0:P[0])==null?void 0:b.date).add(Number(c),"hours").utc().format(),y.info("[%s] the temp evasion point: %j",i.requestId,N);const L=S.calculateDistance(N,u);return y.info("[%s] the distance(%d) between tmp & p2: %j - %j",i.requestId,L,N,u),L<n&&(N=S.calculateCoordinate(e,$,o*Number(c)/2),N.utc=D((f=(m=t==null?void 0:t.forecasts)==null?void 0:m[0])==null?void 0:f.date).add(Number(c)/2,"hours").utc().format(),y.warn("[%s] tmp is too close to p2, replace with 1/2 position: %j",i.requestId,N)),N}else{y.info("[%s] no need evasion: %j",i.requestId,{from:e,p1:r,p2:u});return}}static pickIndex(e,t){let n=0;for(const o of e){if(D(o.properties.date).isAfter(t))return n===0?-1:n;n++}return n}static computeNumber(e,t,n){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const o={};for(const i in e)o[i]=this.computeNumber(e[i],t[i],n);return o}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}C.LaneHelper=S,C.LngLatHelper=l,C.TropicalHelper=B,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@idm-plugin/geo",
|
|
3
|
-
"private": false,
|
|
4
|
-
"version": "1.1.
|
|
5
|
-
"description": "idm plugin for geo",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"idm",
|
|
9
|
-
"geo"
|
|
10
|
-
],
|
|
11
|
-
"author": "chenheng@idmwx.com",
|
|
12
|
-
"contributors": [
|
|
13
|
-
"ChenHeng"
|
|
14
|
-
],
|
|
15
|
-
"license": "GPL-3.0",
|
|
16
|
-
"files": [
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
"main": "./dist/index.umd.cjs",
|
|
20
|
-
"module": "./dist/index.js",
|
|
21
|
-
"types": "index.d.ts",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"dev": "vite --config ./build/base.config.ts",
|
|
24
|
-
"build": "vite build --config ./build/lib.config.ts",
|
|
25
|
-
"lint:fix": "eslint --fix --ext .js,.ts,.",
|
|
26
|
-
"prettier": "yarn lint:fix && prettier --write '**/*.{js,ts}'",
|
|
27
|
-
"release": "yarn build && yarn publish --access public"
|
|
28
|
-
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"@log4js-node/log4js-api": "^1.0.2",
|
|
31
|
-
"@turf/turf": "^6.5.0",
|
|
32
|
-
"moment": "^2.30.1",
|
|
33
|
-
"moment-timezone": "^0.5.45",
|
|
34
|
-
"tz-lookup": "^6.1.25"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/jest": "^25.2.2",
|
|
38
|
-
"@types/node": "^18.14.2",
|
|
39
|
-
"@types/tz-lookup": "^6.1.2",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
41
|
-
"@typescript-eslint/parser": "^5.53.0",
|
|
42
|
-
"@vitejs/plugin-vue": "^4.2.3",
|
|
43
|
-
"eslint": "^8.35.0",
|
|
44
|
-
"eslint-config-prettier": "^8.6.0",
|
|
45
|
-
"eslint-define-config": "^1.15.0",
|
|
46
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
-
"jest": "^26.6.3",
|
|
48
|
-
"lint-staged": "^13.1.2",
|
|
49
|
-
"prettier": "^2.8.4",
|
|
50
|
-
"sass": "^1.58.3",
|
|
51
|
-
"simple-git-hooks": "^2.8.1",
|
|
52
|
-
"stylelint": "^15.2.0",
|
|
53
|
-
"supertest": "^4.0.2",
|
|
54
|
-
"ts-jest": "^26.5.3",
|
|
55
|
-
"ts-node-dev": "^2.0.0-0",
|
|
56
|
-
"tsconfig-paths": "^3.12.0",
|
|
57
|
-
"typescript": "^4.9.3",
|
|
58
|
-
"vite": "^4.1.0",
|
|
59
|
-
"vite-plugin-dts": "^2.0.2",
|
|
60
|
-
"vite-plugin-static-copy": "^0.17.0"
|
|
61
|
-
},
|
|
62
|
-
"lint-staged": {
|
|
63
|
-
"*.{ts,tsx,js}": "eslint --fix",
|
|
64
|
-
"*.{ts,tsx,js,scss}": "prettier --write"
|
|
65
|
-
},
|
|
66
|
-
"simple-git-hooks": {
|
|
67
|
-
"pre-commit": "yarn exec lint-staged"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@idm-plugin/geo",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.1.5",
|
|
5
|
+
"description": "idm plugin for geo",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"idm",
|
|
9
|
+
"geo"
|
|
10
|
+
],
|
|
11
|
+
"author": "chenheng@idmwx.com",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"ChenHeng"
|
|
14
|
+
],
|
|
15
|
+
"license": "GPL-3.0",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.umd.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite --config ./build/base.config.ts",
|
|
24
|
+
"build": "vite build --config ./build/lib.config.ts",
|
|
25
|
+
"lint:fix": "eslint --fix --ext .js,.ts,.",
|
|
26
|
+
"prettier": "yarn lint:fix && prettier --write '**/*.{js,ts}'",
|
|
27
|
+
"release": "yarn build && yarn publish --access public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@log4js-node/log4js-api": "^1.0.2",
|
|
31
|
+
"@turf/turf": "^6.5.0",
|
|
32
|
+
"moment": "^2.30.1",
|
|
33
|
+
"moment-timezone": "^0.5.45",
|
|
34
|
+
"tz-lookup": "^6.1.25"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^25.2.2",
|
|
38
|
+
"@types/node": "^18.14.2",
|
|
39
|
+
"@types/tz-lookup": "^6.1.2",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
42
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
43
|
+
"eslint": "^8.35.0",
|
|
44
|
+
"eslint-config-prettier": "^8.6.0",
|
|
45
|
+
"eslint-define-config": "^1.15.0",
|
|
46
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
+
"jest": "^26.6.3",
|
|
48
|
+
"lint-staged": "^13.1.2",
|
|
49
|
+
"prettier": "^2.8.4",
|
|
50
|
+
"sass": "^1.58.3",
|
|
51
|
+
"simple-git-hooks": "^2.8.1",
|
|
52
|
+
"stylelint": "^15.2.0",
|
|
53
|
+
"supertest": "^4.0.2",
|
|
54
|
+
"ts-jest": "^26.5.3",
|
|
55
|
+
"ts-node-dev": "^2.0.0-0",
|
|
56
|
+
"tsconfig-paths": "^3.12.0",
|
|
57
|
+
"typescript": "^4.9.3",
|
|
58
|
+
"vite": "^4.1.0",
|
|
59
|
+
"vite-plugin-dts": "^2.0.2",
|
|
60
|
+
"vite-plugin-static-copy": "^0.17.0"
|
|
61
|
+
},
|
|
62
|
+
"lint-staged": {
|
|
63
|
+
"*.{ts,tsx,js}": "eslint --fix",
|
|
64
|
+
"*.{ts,tsx,js,scss}": "prettier --write"
|
|
65
|
+
},
|
|
66
|
+
"simple-git-hooks": {
|
|
67
|
+
"pre-commit": "yarn exec lint-staged"
|
|
68
|
+
}
|
|
69
|
+
}
|