@idm-plugin/geo 1.3.7 → 1.3.9
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 +3 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -889,7 +889,9 @@ class Z {
|
|
|
889
889
|
let D, R = m.clone().add(v, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
890
890
|
for (; D = this.pickIndex(M, R), D <= M.length - 1; ) {
|
|
891
891
|
if (D > 0) {
|
|
892
|
-
const b = M[D], p = D === 0 ? y == null ? void 0 : y[0] : M[D - 1]
|
|
892
|
+
const b = M[D], p = D === 0 ? y == null ? void 0 : y[0] : M[D - 1];
|
|
893
|
+
debugger;
|
|
894
|
+
const N = (v / 60 - ((c = p == null ? void 0 : p.properties) == null ? void 0 : c.hour)) / (b.properties.hour - ((d = p == null ? void 0 : p.properties) == null ? void 0 : d.hour)), W = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[0], b.geometry.coordinates[0], N), A = this.computeNumber(p == null ? void 0 : p.geometry.coordinates[1], b.geometry.coordinates[1], N), E = g.point([W, A], {
|
|
893
895
|
name: u,
|
|
894
896
|
model: f,
|
|
895
897
|
category: b == null ? void 0 : b.properties.category,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(M,$){typeof exports=="object"&&typeof module<"u"?$(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"],$):(M=typeof globalThis<"u"?globalThis:M||self,$(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,$,R,z,O){"use strict";function W(v){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const t in v)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(v,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>v[t]})}}return e.default=v,Object.freeze(e)}const g=W($);function L(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(v=>{j.prototype[v.toLowerCase()]=()=>{},j.prototype[`is${v}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var A={getLogger:k?k.getLogger:()=>new j};const E=L(A);class l{static guessTimeZoneOffset(e,t){const n=O(t,e),s=R().tz(n).utcOffset();return this.roundPrecision(s/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 s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(3,"0"):u=l.padNumber(a,3,2);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:f}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let s="N";e<0&&(s="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(2,"0"):u=l.padNumber(a,2,2);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:f}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="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 s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="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 s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){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 s=e,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${s}E`:o<=-90?e=`${s}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${s}${o>0?"E":"W"}`:e=`${s}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const s=Math.trunc(e).toString().padStart(t,"0"),o=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class b{static calculateBearing(e,t,n=!0,s=4){const o=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(o.features[0],o.features[1]):i=g.bearing(o.features[0],o.features[1]),i<0&&(i+=360),l.roundPrecision(i,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,s),t.lng=l.convertToStdLng(t.lng,s);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:o}):r=g.distance(i.features[0],i.features[1],{units:o}),l.roundPrecision(r,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const d={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,d,!0,t,n),o=d}return l.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const i=g.point([e.lng,e.lat]);let r;o?r=g.rhumbDestination(i,n,t,{units:s}):r=g.destination(i,n,t,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),d=this.calculateDistance(e,t,!1,8,i);s&&r.push({lng:e.lng,lat:e.lat});let a=0;for(;a<d;)a+=n,a<d&&r.push(this.calculateCoordinate(e,c,a,i,!1));return o&&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 s=[];let o,i;for(let r=0;r<e.length-1;r++){o=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([o,e[r].lat]);const c=o-i;if(Math.abs(c)>180){const d=l.convertToMonotonicLng2([[o,e[r].lat],[i,e[r+1].lat]]);let a,u;t?(a=g.lineString(d),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(a=g.greatCircle(d[0],d[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const f=g.lineIntersect(a,u);let h;if(f.features.length){const C=g.getCoord(f.features[0]);h=l.roundPrecision(C[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),s.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),s.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([i,e[r+1].lat])}return s.push(n),s}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);t.push(s)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(s=>s.lat===n.lat&&s.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 s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===e.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(e.lat,8)&&n.splice(s,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,s=0,o=0,i,r;return t.forEach((c,d)=>{for(let a=0;a<c.length-1;a++){const u={lng:c[a][0],lat:c[a][1]},f={lng:c[a+1][0],lat:c[a+1][1]},h=this.calculatePointToLineDistance(e,u,f);n>h&&(n=h,o=a,s=d,i=this.calculateDistance(u,e),r=this.calculateDistance(f,e))}}),i!==0&&r!==0?t[s].splice(o+1,0,[e.lng,e.lat]):i===0?t[s].splice(o,1,[e.lng,e.lat]):r===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=b.convertRouteToCoordinates(t);return n.push(e),b.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=b.convertRouteToCoordinates(t);return n.unshift(e),b.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([e.lng,e.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...s],o),r=i.findIndex(a=>l.roundPrecision(e.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(a.lat,8)),c=i.findIndex(a=>l.roundPrecision(t.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(a.lat,8));return i.filter((a,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const d={lng:i[c][0],lat:i[c][1]},a={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,d,a);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(e,t){const n=b.convertRouteToCoordinates(t);b.mergeCoordinateToWaypoints(e,n,!0),t=b.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let r=!0;for(let c=s;c<t.length;c++)if(r){const d=[];d.push([e.lng,e.lat]);for(let a=o+1;a<t[c].length;a++)e.lng===t[c][a][0]&&e.lat===t[c][a][1]||d.push(t[c][a]);i.push(d),r=!1}else i.push([...t[c]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((a,u)=>u>0);const d=this.calculatePointToLineDistance(e,r,c);n>d&&(n=d,s=i)}e.lng=l.convertToStdLng(e.lng);const o=[e];for(let i=s+1;i<t.length;i++)o.push(t[i]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,s),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,s);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 s=e[n],o=e[n+1],i=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const s of e)this.mergeCoordinateToWaypoints(s,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const d={lng:t[c].lng,lat:t[c].lat},a={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,d,a);s>=u&&(s=u,o=c,i=this.calculateDistance(d,e,!1,6),r=this.calculateDistance(a,e,!1,6))}return i!==0&&r!==0?i<s||i===s&&o===0?t.unshift(e):r<s||r===s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):i===0?n&&t.splice(o,1,e):r===0&&n&&t.splice(o+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const s=e[n-1],o=e[n];if(n===1&&t.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(o)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(d=>[d.lng,d.lat]),i=g.lineString(o),r=g.nearestPointOnLine(i,n),c=g.getCoord(r);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let s=0;s<t.length-1;s++){const o=t[s],i=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,i)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var f;const o=e.speed||12,i=[];let r=[],c=!1,d=0,a=0,u;if(t&&n.length?(i.push(e),n.forEach((h,C)=>{if(c)r.push(h);else{const m=[];let S;for(let D=0;D<h.length;D++)if(u)m.push(h[D]);else{S={lng:h[D][0],lat:h[D][1]};const I=this.calculateDistance(e,S,!0,8,s);if(d+=I,d<t)a+=I,i.push(S),e=S;else{if(a=t,d===t)u=S,m.push([u.lng,u.lat]);else{const N=d-t,x=this.calculateBearing(S,e);u=this.calculateCoordinate(S,x,N,s),m.push([u.lng,u.lat]),m.push([S.lng,S.lat])}c=!0}}m.length&&r.push(m),C===n.length-1&&!u&&(u=S)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=a,u.hourFromPrevious=Math.round(a/o*1e4)/1e4,((f=r[0])==null?void 0:f.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,h)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const s=l.convertToStdLng(e.lng,6),o=g.point([s,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),d=g.nearestPointOnLine(c,o),a=g.getCoord(d),u=l.roundPrecision(a[0],6),f=l.roundPrecision(a[1],6);return{lng:u,lat:f,inline:!(u===i&&f===t.lat)&&!(u===r&&f===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0)o.bearing=this.calculateBearing(o,c,!0);else{const d=this.calculateDistance(s,c,!0);d&&d>=t&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(e,t,n=1){let s=this.convertRouteToCoordinates(e,n);return s=this.simplifyGCCoordinates(s,t),s}static simplifyGCCoordinates(e,t){t.forEach(s=>{this.mergeCoordinateToWaypoints(s,e,!0)});for(let s=1;s<t.length;s++){const o=t[s-1],i=t[s];if(i.gcToPrevious){const r=e.findIndex(d=>d.lng===o.lng&&d.lat===o.lat),c=e.findIndex(d=>d.lng===i.lng&&d.lat===i.lat);for(let d=c-1;d>r;d--)e.splice(d,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];i.gcToPrevious?(o.bearing=this.calculateBearing(o,i,!1),i.distanceFromPrevious=this.calculateDistance(o,i,!1)):(o.bearing=this.calculateBearing(o,i,!0),i.distanceFromPrevious=this.calculateDistance(o,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(t);for(const r of s)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const i of o)t.push(i);const n=l.convertToMonotonicLng2(t),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let T;try{T=E.getLogger("vessel")}catch{}finally{}class F{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const s of e){if(s.forecasts){const o=(n=s.history)==null?void 0:n[0];for(const i of s.forecasts){const r=[],c=R(i.date).utc(),d=`${s.name}-${i.model}`;if(o){const a=R(o.updated).utc(),u=g.point([o.lng,o.lat],{model:i.model,name:s.name,date:a.format(),hour:0,format:a.format("MMM-DD/HHmm[Z]"),pressure:o.pressure>1e4?l.roundPrecision(o.pressure/100,0):l.roundPrecision(o.pressure,0),wind:{kts:o.kts,spd:o.speed||o.spd},category:d,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const a in i==null?void 0:i.hours){const u=i.hours[a];u.wind.spd=u.wind.spd||u.wind.speed;const f=c.clone().add(Number(a),"hour"),h=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:f.format(),hour:Number(a),format:f.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:d,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const a=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:s.id||s.name,model:i.model,name:s.name,category:d,type:"forecast"});t.features.push(a)}}}if(s.history){const o=[];for(const r of s.history){const c=R(r.updated).utc(),d=g.point([r.lng,r.lat],{name:s.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:`${s.name}-history`,wind:r.wind});t.features.push(d),o.push(d.geometry.coordinates)}const i=s.history[0];if(o.length===1&&o.push(o[0]),o.length>1){const r=g.lineString(l.convertToMonotonicLng2(o),{name:s.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var o,i,r,c,d;const n=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const u=a.properties.name,f=a.properties.model,h=a.properties.showCircle,C=a.properties.disabled,m=R(a.properties.date).utc();let S=t*60-(m.get("hour")*60+m.get("minute"))%(t*60);const D=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(P=>P.geometry.type==="Point"&&P.properties.type==="forecast"&&P.properties.category===`${u}-${f}`),I=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(P=>P.geometry.type==="Point"&&P.properties.type==="history"&&P.properties.category===`${u}-history`);let N,x=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;N=this.pickIndex(D,x),N<=D.length-1;){if(N>0){const P=D[N],p=N===0?I==null?void 0:I[0]:D[N-1],y=(S/60-((c=p==null?void 0:p.properties)==null?void 0:c.hour))/(P.properties.hour-((d=p==null?void 0:p.properties)==null?void 0:d.hour)),B=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],P.geometry.coordinates[0],y),q=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],P.geometry.coordinates[1],y),U=g.point([B,q],{name:u,model:f,category:P==null?void 0:P.properties.category,date:x.format(),format:x.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,P.properties.gusts,y),hour:this.computeNumber(p==null?void 0:p.properties.hour,P.properties.hour,y),movement:this.computeNumber(p==null?void 0:p.properties.movement,P.properties.movement,y),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,P.properties.pressure,y),wind:this.computeNumber(p==null?void 0:p.properties.wind,P.properties.wind,y),type:"forecast",disabled:C,showCircle:h});s.push(U)}S+=t*60,x=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(e,t){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const C=b.calculateDistance(e,o),m=b.calculateDistance(e,i);if(C>2*n&&m>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,C,m,{from:e,t1:o,t2:i,hr:r}),{}}const d=b.calculateBearing(e,o),a=b.calculateBearing(o,i),u=Math.abs(d-a);let f=0;u<180?f=u+90:u>=180&&(f=u-90);const h=b.calculateCoordinate(o,f,n);return T==null||T.info("[%s] the right tangent position: %j",s.requestId,{from:e,t1:o,t2:i,radius:n,bearing1:d,bearing2:a,right:h}),{at:h,t1:o,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const h=b.calculateDistance(e,o),C=b.calculateDistance(e,i);if(h>2*n&&C>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,h,C,{from:e,t1:o,t2:i,hr:r}),{}}const d=b.calculateBearing(e,o),a=b.calculateBearing(o,i),u=b.calculateDistance(e,o);return{at:b.calculateCoordinate(o,d-a+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return T==null||T.info("[%s] no need drift: %j",s.requestId,{from:e,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var a,u,f,h,C;let s={};(a=e.forecasts)==null||a.forEach(m=>{s={...m.hours,...s}});const o=((u=e==null?void 0:e.history)==null?void 0:u[0])||(s==null?void 0:s[(f=Object.keys(s))==null?void 0:f[0]]);T==null||T.info("[%s] the first tropical center: %j",n.requestId,o);let i=(h=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:h.at(-1);i||(i=(C=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:C.at(-1));const r=s==null?void 0:s[i||-1];T==null||T.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(s||{}).filter(m=>Number(m)<=Number(i)),d={0:o};for(const m of c)d[m]=s[m];return{t1:o,t2:r,hr:Number(i),hours:d}}static pickIndex(e,t){let n=0;for(const s of e){if(R(s.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 s={};for(const o in e)s[o]=this.computeNumber(e[o],t[o],n);return s}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}M.LaneHelper=b,M.LngLatHelper=l,M.TropicalHelper=F,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(M,$){typeof exports=="object"&&typeof module<"u"?$(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"],$):(M=typeof globalThis<"u"?globalThis:M||self,$(M["idm-plugin-rabbitmq"]={},M["@turf/turf"],M.moment,M["moment-timezone"],M["tz-lookup"]))})(this,function(M,$,R,z,O){"use strict";function W(v){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const t in v)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(v,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>v[t]})}}return e.default=v,Object.freeze(e)}const g=W($);function L(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}class j{log(){}isLevelEnabled(){return!1}addContext(){}removeContext(){}clearContext(){}}["Trace","Debug","Info","Warn","Error","Fatal","Mark"].forEach(v=>{j.prototype[v.toLowerCase()]=()=>{},j.prototype[`is${v}Enabled`]=()=>!1});const k=(()=>{try{return require("log4js")}catch{return null}})();var A={getLogger:k?k.getLogger:()=>new j};const E=L(A);class l{static guessTimeZoneOffset(e,t){const n=O(t,e),s=R().tz(n).utcOffset();return this.roundPrecision(s/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 s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(3,"0"):u=l.padNumber(a,3,2);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:f}}static lat2pretty(e,t=6,n="H°M′"){e=e%180;let s="N";e<0&&(s="S"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,i,r,c,d,a,u;i=o%3600%60,n.indexOf("S")!==-1&&(o=o-i,r=l.padNumber(i,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?d=l.roundPrecision(c,t).toString().padStart(2,"0"):d=l.padNumber(c,2,2),o=o-c*60),a=o/3600,n.indexOf("M")!==-1?u=l.roundPrecision(a,t).toString().padStart(2,"0"):u=l.padNumber(a,2,2);const f=`${n.replace(/S+/gi,r).replace(/M+/gi,d).replace(/H+/gi,u)}${s}`;return{direction:s,degree:l.roundPrecision(a,t),minute:l.roundPrecision(c,t),second:l.roundPrecision(i,t),pretty:f}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=l.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>360&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="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 s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[i,r]=o;if(r=r>60?r/Math.pow(10,String(r).length-2):r,i>90&&!r){const c=this.roundPrecision(i/100,0);r=i-c*100,i=c}n=i+(r??0)/60,s==="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 s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:l.str2Lat(e,t)}:{lng:l.str2Lng(e,t)}}static convertToStdLng(e,t=6){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 s=e,o=Number(s.split(" ")[0]);if(isNaN(o))throw new Error(`invalid Lat/Lng: ${e}`);o>=90?e=`${s}E`:o<=-90?e=`${s}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${s}${o>0?"E":"W"}`:e=`${s}${o>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const s=Math.trunc(e).toString().padStart(t,"0"),o=Math.trunc(l.roundPrecision(e-Math.trunc(e),n)*Math.pow(10,n)).toString().padStart(n,"0");return`${s}.${o}`}}class b{static calculateBearing(e,t,n=!0,s=4){const o=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=g.rhumbBearing(o.features[0],o.features[1]):i=g.bearing(o.features[0],o.features[1]),i<0&&(i+=360),l.roundPrecision(i,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=l.convertToStdLng(e.lng,s),t.lng=l.convertToStdLng(t.lng,s);const i=g.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=g.rhumbDistance(i.features[0],i.features[1],{units:o}):r=g.distance(i.features[0],i.features[1],{units:o}),l.roundPrecision(r,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const i of e)for(let r=0;r<i.length-1;r++){const c={lng:i[r][0],lat:i[r][1]};r===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const d={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(c,d,!0,t,n),o=d}return l.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const i=g.point([e.lng,e.lat]);let r;o?r=g.rhumbDestination(i,n,t,{units:s}):r=g.destination(i,n,t,{units:s});const c=r.geometry.coordinates;return{lng:l.convertToStdLng(c[0],8),lat:l.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,i="nauticalmiles"){const r=[],c=this.calculateBearing(e,t,!1),d=this.calculateDistance(e,t,!1,8,i);s&&r.push({lng:e.lng,lat:e.lat});let a=0;for(;a<d;)a+=n,a<d&&r.push(this.calculateCoordinate(e,c,a,i,!1));return o&&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 s=[];let o,i;for(let r=0;r<e.length-1;r++){o=l.convertToStdLng(e[r].lng,8),i=l.convertToStdLng(e[r+1].lng,8),e[r].lat=l.roundPrecision(e[r].lat,8),e[r+1].lat=l.roundPrecision(e[r+1].lat,8),n.push([o,e[r].lat]);const c=o-i;if(Math.abs(c)>180){const d=l.convertToMonotonicLng2([[o,e[r].lat],[i,e[r+1].lat]]);let a,u;t?(a=g.lineString(d),u=g.lineString([[c>0?180:-180,89],[c>0?180:-180,-89]])):(a=g.greatCircle(d[0],d[1]),u=g.greatCircle([c>0?180:-180,89],[c>0?180:-180,-89]));const f=g.lineIntersect(a,u);let h;if(f.features.length){const C=g.getCoord(f.features[0]);h=l.roundPrecision(C[1],8)}else h=e[r].lat;c>0?(n.push([180-1e-6,h]),s.push([...n]),n=[],n.push([-(180-1e-6),h])):(n.push([-(180-1e-6),h]),s.push([...n]),n=[],n.push([180-1e-6,h]))}r===e.length-2&&n.push([i,e[r+1].lat])}return s.push(n),s}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,i)=>(o.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&o.push(i),o),[]);t.push(s)}return t}static deduplicateCoordinates(e){return e.reduce((t,n)=>(t.findIndex(s=>s.lat===n.lat&&s.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 s=n.length-1;s>=0;s--)l.roundPrecision(n[s][0],8)===e.lng&&l.roundPrecision(n[s][1],8)===l.roundPrecision(e.lat,8)&&n.splice(s,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,s=0,o=0,i,r;return t.forEach((c,d)=>{for(let a=0;a<c.length-1;a++){const u={lng:c[a][0],lat:c[a][1]},f={lng:c[a+1][0],lat:c[a+1][1]},h=this.calculatePointToLineDistance(e,u,f);n>h&&(n=h,o=a,s=d,i=this.calculateDistance(u,e),r=this.calculateDistance(f,e))}}),i!==0&&r!==0?t[s].splice(o+1,0,[e.lng,e.lat]):i===0?t[s].splice(o,1,[e.lng,e.lat]):r===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=l.convertToStdLng(e.lng,8);const n=b.convertRouteToCoordinates(t);return n.push(e),b.divideAccordingToLng(n)}static unshiftCoordinateToRoute(e,t){const n=b.convertRouteToCoordinates(t);return n.unshift(e),b.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 s=[];let o=0;return n.forEach(i=>{if(o===2)return;const r=[];for(const c of i){if(l.roundPrecision(t.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(c[1],8)){r.push(c),o===0&&r.push([e.lng,e.lat]),o=2;break}o===1?r.push(c):l.roundPrecision(e.lng,8)===l.roundPrecision(c[0],8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(c[1],8)&&(o=1,r.push(c))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t,...s],o),r=i.findIndex(a=>l.roundPrecision(e.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(e.lat,8)===l.roundPrecision(a.lat,8)),c=i.findIndex(a=>l.roundPrecision(t.lng,8)===l.roundPrecision(a.lng,8)&&l.roundPrecision(t.lat,8)===l.roundPrecision(a.lat,8));return i.filter((a,u)=>u>=r&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((i,r)=>{for(let c=0;c<i.length-1;c++){const d={lng:i[c][0],lat:i[c][1]},a={lng:i[c+1][0],lat:i[c+1][1]},u=this.calculatePointToLineDistance(e,d,a);n>u&&(n=u,s=c,o=r)}}),{minDist:n,segIndex:o,minIndex:s}}static calculateSubRoute(e,t){const n=b.convertRouteToCoordinates(t);b.mergeCoordinateToWaypoints(e,n,!0),t=b.divideAccordingToLng(n);const{segIndex:s,minIndex:o}=this.calculateMinDistanceToRoute({...e},t);e.lng=l.convertToStdLng(e.lng);const i=[];let r=!0;for(let c=s;c<t.length;c++)if(r){const d=[];d.push([e.lng,e.lat]);for(let a=o+1;a<t[c].length;a++)e.lng===t[c][a][0]&&e.lat===t[c][a][1]||d.push(t[c][a]);i.push(d),r=!1}else i.push([...t[c]]);return i}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let i=0;i<t.length-1;i++){const r=t[i],c=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((a,u)=>u>0);const d=this.calculatePointToLineDistance(e,r,c);n>d&&(n=d,s=i)}e.lng=l.convertToStdLng(e.lng);const o=[e];for(let i=s+1;i<t.length;i++)o.push(t[i]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=l.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=l.convertToStdLng(t.lng,8),n.lng=l.convertToStdLng(n.lng,8);const o=l.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const i=g.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=g.pointToLineDistance(g.point([e.lng,e.lat]),i,s),c=g.pointToLineDistance(g.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,s);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 s=e[n],o=e[n+1],i=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(i),o.distanceFromStart=l.roundPrecision((s.distanceFromStart||0)+o.distanceFromPrevious)}return e}static mergeCoordinatesToWaypoints(e,t,n=!0){for(const s of e)this.mergeCoordinateToWaypoints(s,t,n);return t}static mergeCoordinateToWaypoints(e,t,n=!0){e.lng=l.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,i=0,r=0;for(let c=0;c<t.length-1;c++){const d={lng:t[c].lng,lat:t[c].lat},a={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,d,a);s>=u&&(s=u,o=c,i=this.calculateDistance(d,e,!1,6),r=this.calculateDistance(a,e,!1,6))}return i!==0&&r!==0?i<s||i===s&&o===0?t.unshift(e):r<s||r===s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):i===0?n&&t.splice(o,1,e):r===0&&n&&t.splice(o+1,1,e),t.map(c=>(c.lng=l.convertToStdLng(c.lng),c))}static generateRouteAccordingToWaypoints(e){const t=[];for(let n=1;n<e.length;n++){const s=e[n-1],o=e[n];if(n===1&&t.push(s),o.gcToPrevious){const i=this.interpolateCoordinates(s,o,200,!1,!0,"nauticalmiles");t.push(...i)}else t.push(o)}return this.divideAccordingToLng(t,!0)}static nearestCoordinateInRoute(e,t){const n=g.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(d=>[d.lng,d.lat]),i=g.lineString(o),r=g.nearestPointOnLine(i,n),c=g.getCoord(r);return{lng:l.roundPrecision(c[0],8),lat:l.roundPrecision(c[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let s=0;s<t.length-1;s++){const o=t[s],i=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,i)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var f;const o=e.speed||12,i=[];let r=[],c=!1,d=0,a=0,u;if(t&&n.length?(i.push(e),n.forEach((h,C)=>{if(c)r.push(h);else{const m=[];let S;for(let D=0;D<h.length;D++)if(u)m.push(h[D]);else{S={lng:h[D][0],lat:h[D][1]};const I=this.calculateDistance(e,S,!0,8,s);if(d+=I,d<t)a+=I,i.push(S),e=S;else{if(a=t,d===t)u=S,m.push([u.lng,u.lat]);else{const N=d-t,x=this.calculateBearing(S,e);u=this.calculateCoordinate(S,x,N,s),m.push([u.lng,u.lat]),m.push([S.lng,S.lat])}c=!0}}m.length&&r.push(m),C===n.length-1&&!u&&(u=S)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=a,u.hourFromPrevious=Math.round(a/o*1e4)/1e4,((f=r[0])==null?void 0:f.length)>1){const h={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,h)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const s=l.convertToStdLng(e.lng,6),o=g.point([s,e.lat]),i=l.convertToStdLng(t.lng,6),r=l.convertToStdLng(n.lng,6),c=g.lineString([[i,t.lat],[r,n.lat]]),d=g.nearestPointOnLine(c,o),a=g.getCoord(d),u=l.roundPrecision(a[0],6),f=l.roundPrecision(a[1],6);return{lng:u,lat:f,inline:!(u===i&&f===t.lat)&&!(u===r&&f===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(i=>{i.forEach(r=>{const c={lng:l.roundPrecision(r[0],8),lat:l.roundPrecision(r[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0)o.bearing=this.calculateBearing(o,c,!0);else{const d=this.calculateDistance(s,c,!0);d&&d>=t&&(s.bearing=this.calculateBearing(s,c,!0),n.push(s),o=s)}s=c})}),s&&n.push(s),n}static simplifyRouteToCoordinates(e,t,n=1){let s=this.convertRouteToCoordinates(e,n);return s=this.simplifyGCCoordinates(s,t),s}static simplifyGCCoordinates(e,t){t.forEach(s=>{this.mergeCoordinateToWaypoints(s,e,!0)});for(let s=1;s<t.length;s++){const o=t[s-1],i=t[s];if(i.gcToPrevious){const r=e.findIndex(d=>d.lng===o.lng&&d.lat===o.lat),c=e.findIndex(d=>d.lng===i.lng&&d.lat===i.lat);for(let d=c-1;d>r;d--)e.splice(d,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],i=e[s];i.gcToPrevious?(o.bearing=this.calculateBearing(o,i,!1),i.distanceFromPrevious=this.calculateDistance(o,i,!1)):(o.bearing=this.calculateBearing(o,i,!0),i.distanceFromPrevious=this.calculateDistance(o,i,!0)),n=l.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(s=>(s.lng=l.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const r of e)for(const c of r)t.push(c);const n=g.featureCollection([]),s=l.convertToMonotonicLng2(t);for(const r of s)n.features.push(g.point(r));const i=g.center(n).geometry.coordinates;return{lng:l.convertToStdLng(i[0],8),lat:l.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const o of e)for(const i of o)t.push(i);const n=l.convertToMonotonicLng2(t),s=g.lineString(n);return g.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}}let T;try{T=E.getLogger("vessel")}catch{}finally{}class F{static convert2Geojson(e){var n;const t=g.featureCollection([]);for(const s of e){if(s.forecasts){const o=(n=s.history)==null?void 0:n[0];for(const i of s.forecasts){const r=[],c=R(i.date).utc(),d=`${s.name}-${i.model}`;if(o){const a=R(o.updated).utc(),u=g.point([o.lng,o.lat],{model:i.model,name:s.name,date:a.format(),hour:0,format:a.format("MMM-DD/HHmm[Z]"),pressure:o.pressure>1e4?l.roundPrecision(o.pressure/100,0):l.roundPrecision(o.pressure,0),wind:{kts:o.kts,spd:o.speed||o.spd},category:d,type:"forecast"});t.features.push(u),r.push(u.geometry.coordinates)}for(const a in i==null?void 0:i.hours){const u=i.hours[a];u.wind.spd=u.wind.spd||u.wind.speed;const f=c.clone().add(Number(a),"hour"),h=g.point([u.lng,u.lat],{model:i.model,name:s.name,date:f.format(),hour:Number(a),format:f.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:d,type:"forecast"});t.features.push(h),r.push(h.geometry.coordinates)}if((r==null?void 0:r.length)>1){const a=g.lineString(l.convertToMonotonicLng2(r),{date:i.date,id:s.id||s.name,model:i.model,name:s.name,category:d,type:"forecast"});t.features.push(a)}}}if(s.history){const o=[];for(const r of s.history){const c=R(r.updated).utc(),d=g.point([r.lng,r.lat],{name:s.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:`${s.name}-history`,wind:r.wind});t.features.push(d),o.push(d.geometry.coordinates)}const i=s.history[0];if(o.length===1&&o.push(o[0]),o.length>1){const r=g.lineString(l.convertToMonotonicLng2(o),{name:s.name,type:"history",updated:i==null?void 0:i.updated,pressure:(i==null?void 0:i.pressure)>1e4?l.roundPrecision((i==null?void 0:i.pressure)/100,0):l.roundPrecision(i==null?void 0:i.pressure,0),spd:(i==null?void 0:i.speed)||(i==null?void 0:i.spd),kts:i==null?void 0:i.kts,source:i==null?void 0:i.source,level:i==null?void 0:i.type});t.features.push(r)}}}return t}static interpolate(e,t=3){var o,i,r,c,d;const n=(o=e==null?void 0:e.data)==null?void 0:o.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const u=a.properties.name,f=a.properties.model,h=a.properties.showCircle,C=a.properties.disabled,m=R(a.properties.date).utc();let S=t*60-(m.get("hour")*60+m.get("minute"))%(t*60);const D=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(P=>P.geometry.type==="Point"&&P.properties.type==="forecast"&&P.properties.category===`${u}-${f}`),I=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(P=>P.geometry.type==="Point"&&P.properties.type==="history"&&P.properties.category===`${u}-history`);let N,x=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;N=this.pickIndex(D,x),N<=D.length-1;){if(N>0){const P=D[N],p=N===0?I==null?void 0:I[0]:D[N-1];debugger;const y=(S/60-((c=p==null?void 0:p.properties)==null?void 0:c.hour))/(P.properties.hour-((d=p==null?void 0:p.properties)==null?void 0:d.hour)),B=this.computeNumber(p==null?void 0:p.geometry.coordinates[0],P.geometry.coordinates[0],y),q=this.computeNumber(p==null?void 0:p.geometry.coordinates[1],P.geometry.coordinates[1],y),U=g.point([B,q],{name:u,model:f,category:P==null?void 0:P.properties.category,date:x.format(),format:x.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(p==null?void 0:p.properties.gusts,P.properties.gusts,y),hour:this.computeNumber(p==null?void 0:p.properties.hour,P.properties.hour,y),movement:this.computeNumber(p==null?void 0:p.properties.movement,P.properties.movement,y),pressure:this.computeNumber(p==null?void 0:p.properties.pressure,P.properties.pressure,y),wind:this.computeNumber(p==null?void 0:p.properties.wind,P.properties.wind,y),type:"forecast",disabled:C,showCircle:h});s.push(U)}S+=t*60,x=m.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(e,t){const{t1:n,t2:s,hr:o,hours:i}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:s,hr:o,hours:i}}static diversionPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const C=b.calculateDistance(e,o),m=b.calculateDistance(e,i);if(C>2*n&&m>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,C,m,{from:e,t1:o,t2:i,hr:r}),{}}const d=b.calculateBearing(e,o),a=b.calculateBearing(o,i),u=Math.abs(d-a);let f=0;u<180?f=u+90:u>=180&&(f=u-90);const h=b.calculateCoordinate(o,f,n);return T==null||T.info("[%s] the right tangent position: %j",s.requestId,{from:e,t1:o,t2:i,radius:n,bearing1:d,bearing2:a,right:h}),{at:h,t1:o,t2:i,hr:Number(r),hours:c}}return{}}static driftPassageAt(e,t,n,s={}){const{t1:o,t2:i,hr:r,hours:c}=this.tropicalCenterTwin(t,24,s);if(o&&i){if(!s.debug){const h=b.calculateDistance(e,o),C=b.calculateDistance(e,i);if(h>2*n&&C>2*n)return T==null||T.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,h,C,{from:e,t1:o,t2:i,hr:r}),{}}const d=b.calculateBearing(e,o),a=b.calculateBearing(o,i),u=b.calculateDistance(e,o);return{at:b.calculateCoordinate(o,d-a+180,n<u?n:u),t1:o,t2:i,hr:Number(r),hours:c}}else return T==null||T.info("[%s] no need drift: %j",s.requestId,{from:e,t1:o,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var a,u,f,h,C;let s={};(a=e.forecasts)==null||a.forEach(m=>{s={...m.hours,...s}});const o=((u=e==null?void 0:e.history)==null?void 0:u[0])||(s==null?void 0:s[(f=Object.keys(s))==null?void 0:f[0]]);T==null||T.info("[%s] the first tropical center: %j",n.requestId,o);let i=(h=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:t)))==null?void 0:h.at(-1);i||(i=(C=Object.keys(s||{}).filter(m=>Number(m)<=(t<0?24:2*t)))==null?void 0:C.at(-1));const r=s==null?void 0:s[i||-1];T==null||T.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const c=Object.keys(s||{}).filter(m=>Number(m)<=Number(i)),d={0:o};for(const m of c)d[m]=s[m];return{t1:o,t2:r,hr:Number(i),hours:d}}static pickIndex(e,t){let n=0;for(const s of e){if(R(s.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 s={};for(const o in e)s[o]=this.computeNumber(e[o],t[o],n);return s}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}M.LaneHelper=b,M.LngLatHelper=l,M.TropicalHelper=F,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|