@idm-plugin/geo 2.2.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ class d {
30
30
  * @param format
31
31
  */
32
32
  static lng2pretty(t, e = 6, n = "H°M′") {
33
- t = d.convertToStdLng(t, e);
33
+ t = d.convertToStdLng(t, 6);
34
34
  let s = "E";
35
35
  t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
36
36
  let o = t * 3600, r, i, c, a, l, u;
@@ -1,4 +1,4 @@
1
- (function(k,Z){typeof exports=="object"&&typeof module<"u"?Z(exports,require("@turf/turf"),require("moment"),require("@log4js-node/log4js-api"),require("moment-timezone"),require("tz-lookup"),require("shpjs")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","@log4js-node/log4js-api","moment-timezone","tz-lookup","shpjs"],Z):(k=typeof globalThis<"u"?globalThis:k||self,Z(k["idm-plugin-rabbitmq"]={},k["@turf/turf"],k.moment,k["@log4js-node/log4js-api"],k["moment-timezone"],k["tz-lookup"],k.shpjs))})(this,function(k,Z,v,J,re,Y,Q){"use strict";function _(M){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(M){for(const t in M)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(M,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>M[t]})}}return e.default=M,Object.freeze(e)}const T=_(Z);class d{static guessTimeZoneOffset(e,t){e=d.convertToStdLng(e);const n=Y(t,e),s=v().tz(n).utcOffset();return d.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=d.convertToStdLng(e,t);let s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,i,c,a,l,u;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,i=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),l=o/3600,n.indexOf("M")!==-1?u=d.roundPrecision(l,t).toString().padStart(3,"0"):u=d.padNumber(l,3,6),Number(i)>=60&&(a=Number(a)+1,i=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,i).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:d.roundPrecision(l,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:i,M:a,H:u}}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,r,i,c,a,l,u;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,i=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),l=o/3600,n.indexOf("M")!==-1?u=d.roundPrecision(l,t).toString().padStart(2,"0"):u=d.padNumber(l,2,6),Number(i)>=60&&(a=Number(a)+1,i=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,i).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:d.roundPrecision(l,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:i,M:a,H:u}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,i,c]=o;if(i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,c=c||0,c=c>60?c/Math.pow(10,String(c).length-2):c,r>360&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}n=r+i/60+c/3600,s==="W"&&(n=n*-1)}else n=Number(e);return d.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LAT");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,i,c]=o;if(c=c||0,i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,c=c>60?c/Math.pow(10,String(c).length-2):c,r>90&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}if(n=r+i/60+c/3600,n>90)throw new Error(`latitude out of range: ${e}${s}`);s==="S"&&(n=n*-1)}else n=Number(e);return d.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=d.strReplace(e,n);const s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:d.str2Lat(e,t)}:{lng:d.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),d.roundPrecision(e,t)}static roundPrecision(e,t=6){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}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(/([0-9]+)-([0-9]+\.[0-9]+)/g,"$1 $2").replace(/°/," ").replace(/(\d+)-(\d?)/g,"$1 $2").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=d.roundPrecision(e-Math.trunc(e),n),o=s>=1?Math.trunc(e+1).toString().padStart(t,"0"):Math.trunc(e).toString().padStart(t,"0");return s>=1?o:n>0?`${o}.${Math.trunc(s*Math.pow(10,n)).toString().padStart(n,"0")}`:o}}class K{static json2Str(e){const t=e.type?e.type[0].toUpperCase():"A";return`${e.lat}|${e.lng}|${e.positionTime}|${e.sog}|${e.cog}|${e.hdg}|${e.draught}|${t}|${JSON.stringify(e.meteo||{})}|${e.vendor}|${e.deleted}`}static str2Json(e){const[t,n,s,o,r,i,c,a,l,u,g]=e.split("|");return{lat:Number(t),lng:Number(n),positionTime:Number(s),sog:Number(o),cog:Number(r),hdg:Number(i),draught:isNaN(c)?null:Number(c),type:a,important:a!=="A",meteo:l?JSON.parse(l):void 0,vendor:u,deleted:g==="true"}}static inspectStoppages(e,t=1,n=!0){if(e.length<2)return e;const s=e.at(0).positionTime<e.at(-1).positionTime;s||e.sort((c,a)=>c.positionTime-a.positionTime);const o=[];let r,i;for(let c=0;c<e.length-1;c++){const a=e[c];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let l=c+1;l<e.length;l++){const u=e[l-1],g=e[l];if(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))continue;const h=g.positionTime-u.positionTime;if(b.calculateDistance(g,u,!0,4)/(h/3600)<t)r||(r=a),l===e.length-1&&(i=g,c=l);else{r&&(i=e[l-1],c=l);break}}if((i==null?void 0:i.positionTime)>(r==null?void 0:r.positionTime)&&r){const l={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:v.unix(r.positionTime).utc().format()},end:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:v.unix(i.positionTime).utc().format()},duration:i.positionTime-r.positionTime},u=e.filter(h=>h.positionTime>=l.start.positionTime&&h.positionTime<=l.end.positionTime),g=b.divideAccordingToLng(u);l.distance=b.calculateRouteDistance(g),l.hours=Math.round(l.duration/3600*10)/10,l.hours&&(l.avgSog=Math.round(l.distance/l.hours*10)/10,o.push(l))}r=void 0,i=void 0}}return s||e.sort((c,a)=>a.positionTime-c.positionTime),o}static inspectSummary(e,t,n){const s=v(t),o=v(n),r=e.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=o.unix());let i=0,c=0;if(r.length>1)for(let l=0;l<r.length-1;l++){const u=r[l],g=r[l+1];i+=b.calculateDistance(u,g,!0,4),c+=Math.abs(g.positionTime-u.positionTime)}i=Math.round(i*100)/100,c=Math.round(c/3600*100)/100;const a=c?Math.round(i/c*100)/100:0;return{distance:i,interval:c,avgSpd:a}}}let X;try{X=J.getLogger("meteo")}catch{}finally{}const H=(()=>{const M=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;M[e]=t}return M})();function ee(M){let e=4294967295;for(let t=0;t<M.length;t++)e=H[(e^M[t])&255]^e>>>8;return(e^4294967295)>>>0}function te(M){const e=new TextEncoder,t=[],n=[];let s=0;for(const h of M){const p=e.encode(h.name),f=ee(h.data),m=new Uint8Array(30+p.length),y=new DataView(m.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(8,0,!0),y.setUint32(14,f,!0),y.setUint32(18,h.data.length,!0),y.setUint32(22,h.data.length,!0),y.setUint16(26,p.length,!0),m.set(p,30),t.push({nameBytes:p,data:h.data,crc:f,offset:s}),s+=m.length+h.data.length,n.push(m,h.data)}const o=s,r=[];let i=0;for(const h of t){const p=new Uint8Array(46+h.nameBytes.length),f=new DataView(p.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(10,0,!0),f.setUint32(16,h.crc,!0),f.setUint32(20,h.data.length,!0),f.setUint32(24,h.data.length,!0),f.setUint16(28,h.nameBytes.length,!0),f.setUint32(42,h.offset,!0),p.set(h.nameBytes,46),i+=p.length,r.push(p)}const c=new Uint8Array(22),a=new DataView(c.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,i,!0),a.setUint32(16,o,!0);const l=n.reduce((h,p)=>h+p.length,0)+i+22,u=new Uint8Array(l);let g=0;for(const h of n)u.set(h,g),g+=h.length;for(const h of r)u.set(h,g),g+=h.length;return u.set(c,g),u}function V(M){let e="",t=M;for(;t>=0;)e=String.fromCharCode(65+t%26)+e,t=Math.floor(t/26)-1;return e}class b{static calculateBearing(e,t,n=!0,s=4){const o=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=T.rhumbBearing(o.features[0],o.features[1]):r=T.bearing(o.features[0],o.features[1]),r<0&&(r+=360),d.roundPrecision(r,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=d.convertToStdLng(e.lng,s),t.lng=d.convertToStdLng(t.lng,s);const r=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=T.rhumbDistance(r.features[0],r.features[1],{units:o}):i=T.distance(r.features[0],r.features[1],{units:o}),d.roundPrecision(i,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const r of e)for(let i=0;i<r.length-1;i++){const c={lng:r[i][0],lat:r[i][1]};i===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const a={lng:r[i+1][0],lat:r[i+1][1]};s+=this.calculateDistance(c,a,!0,t,n),o=a}return d.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const r=T.point([e.lng,e.lat]);let i;o?i=T.rhumbDestination(r,n,t,{units:s}):i=T.destination(r,n,t,{units:s});const c=i.geometry.coordinates;return{lng:d.convertToStdLng(c[0],8),lat:d.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,r="nauticalmiles"){const i=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,r);s&&i.push({lng:e.lng,lat:e.lat});let l=0;for(;l<a;)l+=n,l<a&&i.push(this.calculateCoordinate(e,c,l,r,!1));return o&&i.push({lng:t.lng,lat:t.lat}),i}static divideAccordingToLng(e,t=!1,n=!0){if((e==null?void 0:e.length)<2)return[];e=n?this.deduplicateCoordinates(e):e;let s=[];const o=[];let r,i;for(let c=0;c<e.length-1;c++){r=d.convertToStdLng(e[c].lng,8),i=d.convertToStdLng(e[c+1].lng,8),e[c].lat=d.roundPrecision(e[c].lat,8),e[c+1].lat=d.roundPrecision(e[c+1].lat,8),s.push([r,e[c].lat]);const a=r-i;if(Math.abs(a)>180){const l=d.convertToMonotonicLng2([[r,e[c].lat],[i,e[c+1].lat]]);let u,g;t?(u=T.lineString(l),g=T.lineString([[a>0?180:-180,89],[a>0?180:-180,-89]])):(u=T.greatCircle(l[0],l[1]),g=T.greatCircle([a>0?180:-180,89],[a>0?180:-180,-89]));const h=T.lineIntersect(u,g);let p;if(h.features.length){const f=T.getCoord(h.features[0]);p=d.roundPrecision(f[1],8)}else p=e[c].lat;a>0?(s.push([180-1e-6,p]),o.push([...s]),s=[],s.push([-(180-1e-6),p])):(s.push([-(180-1e-6),p]),o.push([...s]),s=[],s.push([180-1e-6,p]))}c===e.length-2&&s.push([i,e[c+1].lat])}return o.push(s),o}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,r)=>(o.findIndex(i=>i[0]===r[0]&&i[1]===r[1])===-1&&o.push(r),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=d.convertToStdLng(e.lng,8);for(const n of t)for(let s=n.length-1;s>=0;s--)d.roundPrecision(n[s][0],8)===e.lng&&d.roundPrecision(n[s][1],8)===d.roundPrecision(e.lat,8)&&n.splice(s,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=d.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)d.roundPrecision(t[n].lng,8)===e.lng&&d.roundPrecision(t[n].lat,8)===d.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,s=0,o=0,r,i;return t.forEach((c,a)=>{for(let l=0;l<c.length-1;l++){const u={lng:c[l][0],lat:c[l][1]},g={lng:c[l+1][0],lat:c[l+1][1]},h=this.calculatePointToLineDistance(e,u,g);n>h&&(n=h,o=l,s=a,r=this.calculateDistance(u,e),i=this.calculateDistance(g,e))}}),r!==0&&i!==0?t[s].splice(o+1,0,[e.lng,e.lat]):r===0?t[s].splice(o,1,[e.lng,e.lat]):i===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=d.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(r=>{if(o===2)return;const i=[];for(const c of r){if(d.roundPrecision(t.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(c[1],8)){i.push(c),o===0&&i.push([e.lng,e.lat]),o=2;break}o===1?i.push(c):d.roundPrecision(e.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(c[1],8)&&(o=1,i.push(c))}i.length&&s.push(i)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([e,t],o.length?o:s),i=r.findIndex(l=>d.roundPrecision(e.lng,8)===d.roundPrecision(l.lng,8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(l.lat,8)),c=r.findIndex(l=>d.roundPrecision(t.lng,8)===d.roundPrecision(l.lng,8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(l.lat,8));return r.filter((l,u)=>u>=i&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((r,i)=>{for(let c=0;c<r.length-1;c++){const a={lng:r[c][0],lat:r[c][1]},l={lng:r[c+1][0],lat:r[c+1][1]},u=this.calculatePointToLineDistance(e,a,l);n>u&&(n=u,s=c,o=i)}}),{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=d.convertToStdLng(e.lng);const r=[];let i=!0;for(let c=s;c<t.length;c++)if(i){const a=[];a.push([e.lng,e.lat]);for(let l=o+1;l<t[c].length;l++)e.lng===t[c][l][0]&&e.lat===t[c][l][1]||a.push(t[c][l]);r.push(a),i=!1}else r.push([...t[c]]);return r}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let r=0;r<t.length-1;r++){const i=t[r],c=t[r+1];if(this.calculateDistance(e,i)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(e,i,c);n>a&&(n=a,s=r)}e.lng=d.convertToStdLng(e.lng);const o=[e];for(let r=s+1;r<t.length;r++)o.push(t[r]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=d.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=d.convertToStdLng(t.lng,8),n.lng=d.convertToStdLng(n.lng,8);const o=d.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const r=T.lineString([[t.lng,t.lat],[n.lng,n.lat]]),i=T.pointToLineDistance(T.point([e.lng,e.lat]),r,s),c=T.pointToLineDistance(T.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),r,s);return d.roundPrecision(Math.min(i,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],r=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(r),o.distanceFromStart=d.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=d.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,r=0,i=0;if(t.length<2)t.push(e);else{for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},l={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,l);s>=u&&(s=u,o=c,r=this.calculateDistance(a,e,!1,6),i=this.calculateDistance(l,e,!1,6))}r!==0&&i!==0?r<=s&&o===0?t.unshift(e):i<=s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):r===0?n?t.splice(o,1,e):t.splice(o+1,0,e):i===0&&(n?t.splice(o+1,1,e):t.splice(o+1,0,e))}return t.map((c,a)=>{c.lng=d.convertToStdLng(c.lng);const l=t[a+1];if(l&&((c.bearing===null||c.bearing===void 0)&&((c.positionTime||0)>(l.positionTime||0)?c.bearing=this.calculateBearing(l,c,!0):c.bearing=this.calculateBearing(c,l,!0)),c.cog=c.cog||c.bearing,!c.sog&&c.positionTime&&l.positionTime)){const u=this.calculateDistance(c,l,!0),g=Math.abs(l.positionTime-c.positionTime)/3600;c.sog=d.roundPrecision(u/g,2)}return c})}static generateRouteAccordingToWaypoints(e,t=!0,n=!0){const s=[];for(let o=1;o<e.length;o++){const r=e[o-1],i=e[o];if(o===1&&s.push(r),i.gcToPrevious){const c=this.interpolateCoordinates(r,i,200,!1,!0,"nauticalmiles");s.push(...c)}else s.push(i)}return this.divideAccordingToLng(s,t,n)}static nearestCoordinateInRoute(e,t){const n=T.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),r=T.lineString(o),i=T.nearestPointOnLine(r,n),c=T.getCoord(i);return{lng:d.roundPrecision(c[0],8),lat:d.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],r=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,r)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var g;const o=e.speed||12,r=[];let i=[],c=!1,a=0,l=0,u;if(t&&n.length?(r.push(e),n.forEach((h,p)=>{if(c)i.push(h);else{const f=[];let m;for(let y=0;y<h.length;y++)if(u)f.push(h[y]);else{m={lng:h[y][0],lat:h[y][1]};const x=this.calculateDistance(e,m,!0,8,s);if(a+=x,a<t)l+=x,x&&r.push(m),e=m;else{if(l=t,a===t)u=m,f.push([u.lng,u.lat]);else{const P=a-t,S=this.calculateBearing(m,e);u=this.calculateCoordinate(m,S,P,s),f.push([u.lng,u.lat]),f.push([m.lng,m.lat])}c=!0}}f.length&&i.push(f),p===n.length-1&&!u&&(u=m)}})):(i=n,u={...e}),u)if(r.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/o*1e4)/1e4,((g=i[0])==null?void 0:g.length)>1){const h={lng:i[0][1][0],lat:i[0][1][1]};u.bearing=this.calculateBearing(u,h)}else u.bearing=0;return{coordinate:u,nextRoute:i,prevRoute:r}}static nearestCoordinateInLine(e,t,n){const s=d.convertToStdLng(e.lng,6),o=T.point([s,e.lat]),r=d.convertToStdLng(t.lng,6),i=d.convertToStdLng(n.lng,6),c=T.lineString([[r,t.lat],[i,n.lat]]),a=T.nearestPointOnLine(c,o),l=T.getCoord(a),u=d.roundPrecision(l[0],6),g=d.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===r&&g===t.lat)&&!(u===i&&g===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(r=>{r.forEach(i=>{const c={lng:d.roundPrecision(i[0],8),lat:d.roundPrecision(i[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0||o.bearing===null)o.bearing=this.calculateBearing(o,c,!0);else{const a=this.calculateDistance(s,c,!0);a&&a>=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],r=t[s];if(r.gcToPrevious){const i=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=e.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=c-1;a>i;a--)e.splice(a,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],r=e[s];r.gcToPrevious?(o.bearing=this.calculateBearing(o,r,!1),r.distanceFromPrevious=this.calculateDistance(o,r,!1)):(o.bearing=this.calculateBearing(o,r,!0),r.distanceFromPrevious=this.calculateDistance(o,r,!0)),n=d.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return e.map(s=>(s.lng=d.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const i of e)for(const c of i)t.push(c);const n=T.featureCollection([]),s=d.convertToMonotonicLng2(t);for(const i of s)n.features.push(T.point(i));const r=T.center(n).geometry.coordinates;return{lng:d.convertToStdLng(r[0],8),lat:d.roundPrecision(r[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 r of o)t.push(r);const n=d.convertToMonotonicLng2(t),s=T.lineString(n);return T.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}static simplifyCoordinates(e,t=1,n=180){const s=[];for(let o=1;o<e.length;o++){const r=e[o-1],i=e[o],c=e[o+1];let a=!1,l=!1;if((r.velocity||r.suspend||r.important||r.pilot||o===1)&&(a=!0,s.push(r)),i.gcToPrevious&&(a||(a=!0,s.push(r)),l=!0,s.push(i),o++),c){const u=b.calculateDistance(r,i,!0),g=b.calculateDistance(i,c,!0),h=b.calculateDistance(r,c,!0),p=(Math.pow(u,2)+Math.pow(g,2)-Math.pow(h,2))/(2*u*g);Math.round(Math.acos(p)*180/Math.PI)<n&&h>t&&!l&&(s.push(i),o++)}if(o>=e.length-1){const u=e.at(-1);u&&s.push(u)}}return s}static nearestTSPointInWaypoints(e,t,n){const s=v.unix(e),o=n.filter(r=>s.clone().subtract(t,"hour").unix()<=(r.positionTime||0)&&s.clone().add(t,"h").unix()>=(r.positionTime||0));return o.sort((r,i)=>(r.positionTime||0)-(i.positionTime||0)),o.at(-1)}static deadReckoning(e,t){var o,r,i,c;e>1e12&&(e=Math.round(e/1e3));const n=v.unix(e);let s=t.find(a=>a.positionTime===n.unix());if(!s){const a=(r=(o=t.filter(u=>(u==null?void 0:u.positionTime)<n.unix()))==null?void 0:o.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:r.at(-1),l=(c=(i=t.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:i.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:c.at(0);if(a&&l){const u=b.calculateBearing(a,l,!0),g=b.calculateDistance(a,l),h=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=b.calculateCoordinate(a,u,g*h),s.positionTime=n.unix(),s.utc=n.utc().format(),s.cog=u,s.sog=Math.round(g/((l.positionTime-a.positionTime)/3600)*100)/100}else s=a||l,s&&(s.utc=v.unix(s==null?void 0:s.positionTime).utc().format())}return s}static deadReckoningTime(e,t){t=JSON.parse(JSON.stringify(t)),t.sort((a,l)=>(a.positionTime||0)-(l.positionTime||0));let n=Number.MAX_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;for(let a=0;a<t.length-1;a++){const l=t[a],u=t[a+1],g=b.calculatePointToLineDistance(e,l,u);g<n&&(n=g,s=a)}const o=t[s],r=t[s+1],i=b.calculateDistance(o,e),c=b.calculateDistance(r,e);if(i===0)e=o;else if(c===0)e=r;else{const a=o.positionTime||0,l=r.positionTime||0,u=b.calculateDistance(o,r);e.positionTime=Math.round(a+(l-a)*(i/u))}return e.utc=e.positionTime?v.unix(e.positionTime).utc().format():void 0,e.positionTime?e:void 0}static reverseRoute(e){const t=[];for(const n of e)t.push(n.reverse());return t}static reverseCoordinates(e){return e.reverse()}static xmlEscape(e){return e==null?"":String(e).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(e,t){const s=[];return s.push('<?xml version="1.0" encoding="UTF-8"?>'),s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'),s.push(` <routeInfo routeName="${b.xmlEscape(e)}"></routeInfo>`),s.push(...b.toRTZWaypoints(t,6)),s.push("</route>"),s.join(`
1
+ (function(k,Z){typeof exports=="object"&&typeof module<"u"?Z(exports,require("@turf/turf"),require("moment"),require("@log4js-node/log4js-api"),require("moment-timezone"),require("tz-lookup"),require("shpjs")):typeof define=="function"&&define.amd?define(["exports","@turf/turf","moment","@log4js-node/log4js-api","moment-timezone","tz-lookup","shpjs"],Z):(k=typeof globalThis<"u"?globalThis:k||self,Z(k["idm-plugin-rabbitmq"]={},k["@turf/turf"],k.moment,k["@log4js-node/log4js-api"],k["moment-timezone"],k["tz-lookup"],k.shpjs))})(this,function(k,Z,v,J,re,Y,Q){"use strict";function _(M){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(M){for(const t in M)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(M,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>M[t]})}}return e.default=M,Object.freeze(e)}const T=_(Z);class d{static guessTimeZoneOffset(e,t){e=d.convertToStdLng(e);const n=Y(t,e),s=v().tz(n).utcOffset();return d.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=d.convertToStdLng(e,6);let s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let o=e*3600,r,i,c,a,l,u;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,i=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),l=o/3600,n.indexOf("M")!==-1?u=d.roundPrecision(l,t).toString().padStart(3,"0"):u=d.padNumber(l,3,6),Number(i)>=60&&(a=Number(a)+1,i=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,i).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:d.roundPrecision(l,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:i,M:a,H:u}}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,r,i,c,a,l,u;r=o%3600%60,n.indexOf("S")!==-1&&(o=o-r,i=d.padNumber(r,2,2)),c=o/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=d.roundPrecision(c,t).toString().padStart(2,"0"):a=d.padNumber(c,2,3),o=o-c*60),l=o/3600,n.indexOf("M")!==-1?u=d.roundPrecision(l,t).toString().padStart(2,"0"):u=d.padNumber(l,2,6),Number(i)>=60&&(a=Number(a)+1,i=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,i).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:d.roundPrecision(l,t),minute:d.roundPrecision(c,t),second:d.roundPrecision(r,t),pretty:g,S:i,M:a,H:u}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,i,c]=o;if(i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,c=c||0,c=c>60?c/Math.pow(10,String(c).length-2):c,r>360&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}n=r+i/60+c/3600,s==="W"&&(n=n*-1)}else n=Number(e);return d.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=d.strReplace(e,"LAT");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const o=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[r,i,c]=o;if(c=c||0,i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,c=c>60?c/Math.pow(10,String(c).length-2):c,r>90&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}if(n=r+i/60+c/3600,n>90)throw new Error(`latitude out of range: ${e}${s}`);s==="S"&&(n=n*-1)}else n=Number(e);return d.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=d.strReplace(e,n);const s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:d.str2Lat(e,t)}:{lng:d.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),d.roundPrecision(e,t)}static roundPrecision(e,t=6){const n=Number("1".padEnd(t+1,"0"));return Math.round(e*n)/n}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(/([0-9]+)-([0-9]+\.[0-9]+)/g,"$1 $2").replace(/°/," ").replace(/(\d+)-(\d?)/g,"$1 $2").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=d.roundPrecision(e-Math.trunc(e),n),o=s>=1?Math.trunc(e+1).toString().padStart(t,"0"):Math.trunc(e).toString().padStart(t,"0");return s>=1?o:n>0?`${o}.${Math.trunc(s*Math.pow(10,n)).toString().padStart(n,"0")}`:o}}class K{static json2Str(e){const t=e.type?e.type[0].toUpperCase():"A";return`${e.lat}|${e.lng}|${e.positionTime}|${e.sog}|${e.cog}|${e.hdg}|${e.draught}|${t}|${JSON.stringify(e.meteo||{})}|${e.vendor}|${e.deleted}`}static str2Json(e){const[t,n,s,o,r,i,c,a,l,u,g]=e.split("|");return{lat:Number(t),lng:Number(n),positionTime:Number(s),sog:Number(o),cog:Number(r),hdg:Number(i),draught:isNaN(c)?null:Number(c),type:a,important:a!=="A",meteo:l?JSON.parse(l):void 0,vendor:u,deleted:g==="true"}}static inspectStoppages(e,t=1,n=!0){if(e.length<2)return e;const s=e.at(0).positionTime<e.at(-1).positionTime;s||e.sort((c,a)=>c.positionTime-a.positionTime);const o=[];let r,i;for(let c=0;c<e.length-1;c++){const a=e[c];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let l=c+1;l<e.length;l++){const u=e[l-1],g=e[l];if(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))continue;const h=g.positionTime-u.positionTime;if(b.calculateDistance(g,u,!0,4)/(h/3600)<t)r||(r=a),l===e.length-1&&(i=g,c=l);else{r&&(i=e[l-1],c=l);break}}if((i==null?void 0:i.positionTime)>(r==null?void 0:r.positionTime)&&r){const l={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:v.unix(r.positionTime).utc().format()},end:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:v.unix(i.positionTime).utc().format()},duration:i.positionTime-r.positionTime},u=e.filter(h=>h.positionTime>=l.start.positionTime&&h.positionTime<=l.end.positionTime),g=b.divideAccordingToLng(u);l.distance=b.calculateRouteDistance(g),l.hours=Math.round(l.duration/3600*10)/10,l.hours&&(l.avgSog=Math.round(l.distance/l.hours*10)/10,o.push(l))}r=void 0,i=void 0}}return s||e.sort((c,a)=>a.positionTime-c.positionTime),o}static inspectSummary(e,t,n){const s=v(t),o=v(n),r=e.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=o.unix());let i=0,c=0;if(r.length>1)for(let l=0;l<r.length-1;l++){const u=r[l],g=r[l+1];i+=b.calculateDistance(u,g,!0,4),c+=Math.abs(g.positionTime-u.positionTime)}i=Math.round(i*100)/100,c=Math.round(c/3600*100)/100;const a=c?Math.round(i/c*100)/100:0;return{distance:i,interval:c,avgSpd:a}}}let X;try{X=J.getLogger("meteo")}catch{}finally{}const H=(()=>{const M=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;M[e]=t}return M})();function ee(M){let e=4294967295;for(let t=0;t<M.length;t++)e=H[(e^M[t])&255]^e>>>8;return(e^4294967295)>>>0}function te(M){const e=new TextEncoder,t=[],n=[];let s=0;for(const h of M){const p=e.encode(h.name),f=ee(h.data),m=new Uint8Array(30+p.length),y=new DataView(m.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(8,0,!0),y.setUint32(14,f,!0),y.setUint32(18,h.data.length,!0),y.setUint32(22,h.data.length,!0),y.setUint16(26,p.length,!0),m.set(p,30),t.push({nameBytes:p,data:h.data,crc:f,offset:s}),s+=m.length+h.data.length,n.push(m,h.data)}const o=s,r=[];let i=0;for(const h of t){const p=new Uint8Array(46+h.nameBytes.length),f=new DataView(p.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(10,0,!0),f.setUint32(16,h.crc,!0),f.setUint32(20,h.data.length,!0),f.setUint32(24,h.data.length,!0),f.setUint16(28,h.nameBytes.length,!0),f.setUint32(42,h.offset,!0),p.set(h.nameBytes,46),i+=p.length,r.push(p)}const c=new Uint8Array(22),a=new DataView(c.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,i,!0),a.setUint32(16,o,!0);const l=n.reduce((h,p)=>h+p.length,0)+i+22,u=new Uint8Array(l);let g=0;for(const h of n)u.set(h,g),g+=h.length;for(const h of r)u.set(h,g),g+=h.length;return u.set(c,g),u}function V(M){let e="",t=M;for(;t>=0;)e=String.fromCharCode(65+t%26)+e,t=Math.floor(t/26)-1;return e}class b{static calculateBearing(e,t,n=!0,s=4){const o=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=T.rhumbBearing(o.features[0],o.features[1]):r=T.bearing(o.features[0],o.features[1]),r<0&&(r+=360),d.roundPrecision(r,s)}static calculateDistance(e,t,n=!0,s=4,o="nauticalmiles"){e={...e},t={...t},e.lng=d.convertToStdLng(e.lng,s),t.lng=d.convertToStdLng(t.lng,s);const r=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=T.rhumbDistance(r.features[0],r.features[1],{units:o}):i=T.distance(r.features[0],r.features[1],{units:o}),d.roundPrecision(i,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,o;for(const r of e)for(let i=0;i<r.length-1;i++){const c={lng:r[i][0],lat:r[i][1]};i===0&&o&&(s+=this.calculateDistance(o,c,!0,t,n));const a={lng:r[i+1][0],lat:r[i+1][1]};s+=this.calculateDistance(c,a,!0,t,n),o=a}return d.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",o=!0){const r=T.point([e.lng,e.lat]);let i;o?i=T.rhumbDestination(r,n,t,{units:s}):i=T.destination(r,n,t,{units:s});const c=i.geometry.coordinates;return{lng:d.convertToStdLng(c[0],8),lat:d.roundPrecision(c[1],8)}}static interpolateCoordinates(e,t,n,s=!0,o=!0,r="nauticalmiles"){const i=[],c=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,r);s&&i.push({lng:e.lng,lat:e.lat});let l=0;for(;l<a;)l+=n,l<a&&i.push(this.calculateCoordinate(e,c,l,r,!1));return o&&i.push({lng:t.lng,lat:t.lat}),i}static divideAccordingToLng(e,t=!1,n=!0){if((e==null?void 0:e.length)<2)return[];e=n?this.deduplicateCoordinates(e):e;let s=[];const o=[];let r,i;for(let c=0;c<e.length-1;c++){r=d.convertToStdLng(e[c].lng,8),i=d.convertToStdLng(e[c+1].lng,8),e[c].lat=d.roundPrecision(e[c].lat,8),e[c+1].lat=d.roundPrecision(e[c+1].lat,8),s.push([r,e[c].lat]);const a=r-i;if(Math.abs(a)>180){const l=d.convertToMonotonicLng2([[r,e[c].lat],[i,e[c+1].lat]]);let u,g;t?(u=T.lineString(l),g=T.lineString([[a>0?180:-180,89],[a>0?180:-180,-89]])):(u=T.greatCircle(l[0],l[1]),g=T.greatCircle([a>0?180:-180,89],[a>0?180:-180,-89]));const h=T.lineIntersect(u,g);let p;if(h.features.length){const f=T.getCoord(h.features[0]);p=d.roundPrecision(f[1],8)}else p=e[c].lat;a>0?(s.push([180-1e-6,p]),o.push([...s]),s=[],s.push([-(180-1e-6),p])):(s.push([-(180-1e-6),p]),o.push([...s]),s=[],s.push([180-1e-6,p]))}c===e.length-2&&s.push([i,e[c+1].lat])}return o.push(s),o}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((o,r)=>(o.findIndex(i=>i[0]===r[0]&&i[1]===r[1])===-1&&o.push(r),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=d.convertToStdLng(e.lng,8);for(const n of t)for(let s=n.length-1;s>=0;s--)d.roundPrecision(n[s][0],8)===e.lng&&d.roundPrecision(n[s][1],8)===d.roundPrecision(e.lat,8)&&n.splice(s,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=d.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)d.roundPrecision(t[n].lng,8)===e.lng&&d.roundPrecision(t[n].lat,8)===d.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=d.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,s=0,o=0,r,i;return t.forEach((c,a)=>{for(let l=0;l<c.length-1;l++){const u={lng:c[l][0],lat:c[l][1]},g={lng:c[l+1][0],lat:c[l+1][1]},h=this.calculatePointToLineDistance(e,u,g);n>h&&(n=h,o=l,s=a,r=this.calculateDistance(u,e),i=this.calculateDistance(g,e))}}),r!==0&&i!==0?t[s].splice(o+1,0,[e.lng,e.lat]):r===0?t[s].splice(o,1,[e.lng,e.lat]):i===0&&t[s].splice(o+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=d.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(r=>{if(o===2)return;const i=[];for(const c of r){if(d.roundPrecision(t.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(c[1],8)){i.push(c),o===0&&i.push([e.lng,e.lat]),o=2;break}o===1?i.push(c):d.roundPrecision(e.lng,8)===d.roundPrecision(c[0],8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(c[1],8)&&(o=1,i.push(c))}i.length&&s.push(i)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const o=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([e,t],o.length?o:s),i=r.findIndex(l=>d.roundPrecision(e.lng,8)===d.roundPrecision(l.lng,8)&&d.roundPrecision(e.lat,8)===d.roundPrecision(l.lat,8)),c=r.findIndex(l=>d.roundPrecision(t.lng,8)===d.roundPrecision(l.lng,8)&&d.roundPrecision(t.lat,8)===d.roundPrecision(l.lat,8));return r.filter((l,u)=>u>=i&&u<=c)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,o=0;return t.forEach((r,i)=>{for(let c=0;c<r.length-1;c++){const a={lng:r[c][0],lat:r[c][1]},l={lng:r[c+1][0],lat:r[c+1][1]},u=this.calculatePointToLineDistance(e,a,l);n>u&&(n=u,s=c,o=i)}}),{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=d.convertToStdLng(e.lng);const r=[];let i=!0;for(let c=s;c<t.length;c++)if(i){const a=[];a.push([e.lng,e.lat]);for(let l=o+1;l<t[c].length;l++)e.lng===t[c][l][0]&&e.lat===t[c][l][1]||a.push(t[c][l]);r.push(a),i=!1}else r.push([...t[c]]);return r}static calculateSubWaypoints(e,t){let n=Number.MAX_VALUE,s=0;for(let r=0;r<t.length-1;r++){const i=t[r],c=t[r+1];if(this.calculateDistance(e,i)===0)return t;if(this.calculateDistance(e,c)===0)return t.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(e,i,c);n>a&&(n=a,s=r)}e.lng=d.convertToStdLng(e.lng);const o=[e];for(let r=s+1;r<t.length;r++)o.push(t[r]);return o}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=d.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=d.convertToStdLng(t.lng,8),n.lng=d.convertToStdLng(n.lng,8);const o=d.convertToMonotonicLng([t,n]);t=o[0],n=o[1];const r=T.lineString([[t.lng,t.lat],[n.lng,n.lat]]),i=T.pointToLineDistance(T.point([e.lng,e.lat]),r,s),c=T.pointToLineDistance(T.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),r,s);return d.roundPrecision(Math.min(i,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],r=this.calculateRangeRoute(s,o,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),o.distanceFromPrevious=this.calculateRouteDistance(r),o.distanceFromStart=d.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=d.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,o=0,r=0,i=0;if(t.length<2)t.push(e);else{for(let c=0;c<t.length-1;c++){const a={lng:t[c].lng,lat:t[c].lat},l={lng:t[c+1].lng,lat:t[c+1].lat},u=this.calculatePointToLineDistance(e,a,l);s>=u&&(s=u,o=c,r=this.calculateDistance(a,e,!1,6),i=this.calculateDistance(l,e,!1,6))}r!==0&&i!==0?r<=s&&o===0?t.unshift(e):i<=s&&o===t.length-2?t.push(e):t.splice(o+1,0,e):r===0?n?t.splice(o,1,e):t.splice(o+1,0,e):i===0&&(n?t.splice(o+1,1,e):t.splice(o+1,0,e))}return t.map((c,a)=>{c.lng=d.convertToStdLng(c.lng);const l=t[a+1];if(l&&((c.bearing===null||c.bearing===void 0)&&((c.positionTime||0)>(l.positionTime||0)?c.bearing=this.calculateBearing(l,c,!0):c.bearing=this.calculateBearing(c,l,!0)),c.cog=c.cog||c.bearing,!c.sog&&c.positionTime&&l.positionTime)){const u=this.calculateDistance(c,l,!0),g=Math.abs(l.positionTime-c.positionTime)/3600;c.sog=d.roundPrecision(u/g,2)}return c})}static generateRouteAccordingToWaypoints(e,t=!0,n=!0){const s=[];for(let o=1;o<e.length;o++){const r=e[o-1],i=e[o];if(o===1&&s.push(r),i.gcToPrevious){const c=this.interpolateCoordinates(r,i,200,!1,!0,"nauticalmiles");s.push(...c)}else s.push(i)}return this.divideAccordingToLng(s,t,n)}static nearestCoordinateInRoute(e,t){const n=T.point([e.lng,e.lat]),o=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),r=T.lineString(o),i=T.nearestPointOnLine(r,n),c=T.getCoord(i);return{lng:d.roundPrecision(c[0],8),lat:d.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],r=t[s+1];if(this.calculateDistance(e,o)===0){n=s;break}if(this.calculateDistance(e,r)===0){n=s+1;break}}return t[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(e,t,n,s="nauticalmiles"){var g;const o=e.speed||12,r=[];let i=[],c=!1,a=0,l=0,u;if(t&&n.length?(r.push(e),n.forEach((h,p)=>{if(c)i.push(h);else{const f=[];let m;for(let y=0;y<h.length;y++)if(u)f.push(h[y]);else{m={lng:h[y][0],lat:h[y][1]};const x=this.calculateDistance(e,m,!0,8,s);if(a+=x,a<t)l+=x,x&&r.push(m),e=m;else{if(l=t,a===t)u=m,f.push([u.lng,u.lat]);else{const P=a-t,S=this.calculateBearing(m,e);u=this.calculateCoordinate(m,S,P,s),f.push([u.lng,u.lat]),f.push([m.lng,m.lat])}c=!0}}f.length&&i.push(f),p===n.length-1&&!u&&(u=m)}})):(i=n,u={...e}),u)if(r.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/o*1e4)/1e4,((g=i[0])==null?void 0:g.length)>1){const h={lng:i[0][1][0],lat:i[0][1][1]};u.bearing=this.calculateBearing(u,h)}else u.bearing=0;return{coordinate:u,nextRoute:i,prevRoute:r}}static nearestCoordinateInLine(e,t,n){const s=d.convertToStdLng(e.lng,6),o=T.point([s,e.lat]),r=d.convertToStdLng(t.lng,6),i=d.convertToStdLng(n.lng,6),c=T.lineString([[r,t.lat],[i,n.lat]]),a=T.nearestPointOnLine(c,o),l=T.getCoord(a),u=d.roundPrecision(l[0],6),g=d.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===r&&g===t.lat)&&!(u===i&&g===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,o;return e.forEach(r=>{r.forEach(i=>{const c={lng:d.roundPrecision(i[0],8),lat:d.roundPrecision(i[1],8)};if(!o)n.push(c),o=c;else if(o.bearing===void 0||o.bearing===null)o.bearing=this.calculateBearing(o,c,!0);else{const a=this.calculateDistance(s,c,!0);a&&a>=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],r=t[s];if(r.gcToPrevious){const i=e.findIndex(a=>a.lng===o.lng&&a.lat===o.lat),c=e.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=c-1;a>i;a--)e.splice(a,1)}}let n=0;for(let s=1;s<e.length;s++){const o=e[s-1],r=e[s];r.gcToPrevious?(o.bearing=this.calculateBearing(o,r,!1),r.distanceFromPrevious=this.calculateDistance(o,r,!1)):(o.bearing=this.calculateBearing(o,r,!0),r.distanceFromPrevious=this.calculateDistance(o,r,!0)),n=d.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return e.map(s=>(s.lng=d.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const i of e)for(const c of i)t.push(c);const n=T.featureCollection([]),s=d.convertToMonotonicLng2(t);for(const i of s)n.features.push(T.point(i));const r=T.center(n).geometry.coordinates;return{lng:d.convertToStdLng(r[0],8),lat:d.roundPrecision(r[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 r of o)t.push(r);const n=d.convertToMonotonicLng2(t),s=T.lineString(n);return T.bbox(s)}static calculateBBox2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateBBox(t)}static simplifyCoordinates(e,t=1,n=180){const s=[];for(let o=1;o<e.length;o++){const r=e[o-1],i=e[o],c=e[o+1];let a=!1,l=!1;if((r.velocity||r.suspend||r.important||r.pilot||o===1)&&(a=!0,s.push(r)),i.gcToPrevious&&(a||(a=!0,s.push(r)),l=!0,s.push(i),o++),c){const u=b.calculateDistance(r,i,!0),g=b.calculateDistance(i,c,!0),h=b.calculateDistance(r,c,!0),p=(Math.pow(u,2)+Math.pow(g,2)-Math.pow(h,2))/(2*u*g);Math.round(Math.acos(p)*180/Math.PI)<n&&h>t&&!l&&(s.push(i),o++)}if(o>=e.length-1){const u=e.at(-1);u&&s.push(u)}}return s}static nearestTSPointInWaypoints(e,t,n){const s=v.unix(e),o=n.filter(r=>s.clone().subtract(t,"hour").unix()<=(r.positionTime||0)&&s.clone().add(t,"h").unix()>=(r.positionTime||0));return o.sort((r,i)=>(r.positionTime||0)-(i.positionTime||0)),o.at(-1)}static deadReckoning(e,t){var o,r,i,c;e>1e12&&(e=Math.round(e/1e3));const n=v.unix(e);let s=t.find(a=>a.positionTime===n.unix());if(!s){const a=(r=(o=t.filter(u=>(u==null?void 0:u.positionTime)<n.unix()))==null?void 0:o.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:r.at(-1),l=(c=(i=t.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:i.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:c.at(0);if(a&&l){const u=b.calculateBearing(a,l,!0),g=b.calculateDistance(a,l),h=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=b.calculateCoordinate(a,u,g*h),s.positionTime=n.unix(),s.utc=n.utc().format(),s.cog=u,s.sog=Math.round(g/((l.positionTime-a.positionTime)/3600)*100)/100}else s=a||l,s&&(s.utc=v.unix(s==null?void 0:s.positionTime).utc().format())}return s}static deadReckoningTime(e,t){t=JSON.parse(JSON.stringify(t)),t.sort((a,l)=>(a.positionTime||0)-(l.positionTime||0));let n=Number.MAX_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;for(let a=0;a<t.length-1;a++){const l=t[a],u=t[a+1],g=b.calculatePointToLineDistance(e,l,u);g<n&&(n=g,s=a)}const o=t[s],r=t[s+1],i=b.calculateDistance(o,e),c=b.calculateDistance(r,e);if(i===0)e=o;else if(c===0)e=r;else{const a=o.positionTime||0,l=r.positionTime||0,u=b.calculateDistance(o,r);e.positionTime=Math.round(a+(l-a)*(i/u))}return e.utc=e.positionTime?v.unix(e.positionTime).utc().format():void 0,e.positionTime?e:void 0}static reverseRoute(e){const t=[];for(const n of e)t.push(n.reverse());return t}static reverseCoordinates(e){return e.reverse()}static xmlEscape(e){return e==null?"":String(e).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(e,t){const s=[];return s.push('<?xml version="1.0" encoding="UTF-8"?>'),s.push('<route xmlns="http://www.cirm.org/RTZ/1/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">'),s.push(` <routeInfo routeName="${b.xmlEscape(e)}"></routeInfo>`),s.push(...b.toRTZWaypoints(t,6)),s.push("</route>"),s.join(`
2
2
  `)}static waypoints2RTZ10(e,t,n=!0){const o=[];return o.push('<?xml version="1.0" encoding="UTF-8"?>'),o.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'),o.push(` <routeInfo routeName="${b.xmlEscape(e)}"></routeInfo>`),o.push(...b.toRTZWaypoints(t,6,n)),o.push("</route>"),o.join(`
3
3
  `)}static toRTZWaypoints(e,t=6,n=!0){const s=[];s.push(" <waypoints>");for(let o=0;o<e.length;o++){const r=e[o],i=o+1,c=(r.lat??"").toFixed?r.lat.toFixed(t).padEnd(t+2,"0"):r.lat,a=(r.lng??"").toFixed?r.lng.toFixed(t).padEnd(t+2,"0"):r.lng,l=[`id="${i}"`,'revision="0"'];if(r.name&&l.push(`name="${b.xmlEscape(r.name)}"`),s.push(` <waypoint ${l.join(" ")}>`),s.push(` <position lat="${b.xmlEscape(c)}" lon="${b.xmlEscape(a)}" />`),o>0){const u=r.gcToPrevious?"Orthodrome":"Loxodrome";s.push(` <leg geometryType="${u}" />`)}if(n){const u=[];if(r.description&&u.push(` <description>${b.xmlEscape(r.description)}</description>`),r.utc)u.push(` <time>${b.xmlEscape(r.utc)}</time>`);else if(r.positionTime)try{u.push(` <time>${b.xmlEscape(v.unix(r.positionTime).utc().format())}</time>`)}catch{}r.cog!==void 0&&u.push(` <cog>${b.xmlEscape(r.cog)}</cog>`),r.sog!==void 0&&u.push(` <sog>${b.xmlEscape(r.sog)}</sog>`),u.length&&(s.push(" <extensions>"),s.push(...u),s.push(" </extensions>"))}s.push(" </waypoint>")}return s.push(" </waypoints>"),s}static waypoints2CSV(e,t,n){X.debug("keep name for waypoints2CSV for legacy compatibility only",e);const s=(n==null?void 0:n.precision)??6,o=t.some(m=>m.name),r=t.some(m=>m.description),i=t.some(m=>m.port!=null),c=t.some(m=>m.stbd!=null),a=t.some(m=>m.arrRad!=null),l=t.some(m=>m.speed!=null),u=t.some((m,y)=>y>0&&m.gcToPrevious!=null),g=t.some(m=>m.bearing!=null),h=t.some(m=>m.distanceFromPrevious!=null),p=["WPT No.","Latitude","Longitude"];o&&p.push("Name"),r&&p.push("Description"),u&&p.push("Leg"),g&&p.push("Bearing[deg]"),h&&p.push("Distance[NM]"),l&&p.push("Speed[kn]"),i&&p.push("PORT XTD[NM]"),c&&p.push("STBD XTD[NM]"),a&&p.push("Arr.Rad[NM]");const f=[];f.push(p.map(m=>b.csvEscapeField(m)).join(","));for(let m=0;m<t.length;m++){const y=t[m],x=[];x.push((m+1).toString()),x.push(y.lat.toFixed(s)),x.push(y.lng.toFixed(s)),o&&x.push(y.name??""),r&&x.push(y.description??""),u&&x.push(m===0?"":y.gcToPrevious?"GC":"RL"),g&&x.push(y.bearing!=null?String(y.bearing):""),h&&x.push(y.distanceFromPrevious!=null?String(y.distanceFromPrevious):""),l&&x.push(y.speed!=null?String(y.speed):""),i&&x.push(y.port!=null?String(y.port):""),c&&x.push(y.stbd!=null?String(y.stbd):""),a&&x.push(y.arrRad!=null?String(y.arrRad):""),f.push(x.map(P=>b.csvEscapeField(P)).join(","))}return f.join(`
4
4
  `)}static waypoints2JRCCSV(e,t,n){const s=(n==null?void 0:n.precision)??3,o=t.some(f=>f.name),r=t.some(f=>f.port!=null),i=t.some(f=>f.stbd!=null),c=t.some(f=>f.arrRad!=null),a=t.some(f=>f.speed!=null),l=t.some((f,m)=>m>0&&f.gcToPrevious!=null),u=t.some(f=>f.rot!=null),g=t.some(f=>f.turnRad!=null),h=["// WPT No.","LAT","","","LON","",""];r&&h.push("PORT[NM]"),i&&h.push("STBD[NM]"),c&&h.push("Arr. Rad[NM]"),a&&h.push("Speed[kn]"),l&&h.push("Sail(RL/GC)"),u&&h.push("ROT[deg/min]"),g&&h.push("Turn Rad[NM]"),o&&h.push("Name");const p=[];p.push("// ROUTE SHEET exported by JRC ECDIS."),p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."),p.push(`// ${b.xmlEscape(e)}`),p.push(h.join(","));for(let f=0;f<t.length;f++){const m=t[f],y=String(f).padStart(3,"0"),x=d.lat2pretty(m.lat,6),P=d.lng2pretty(m.lng,6),S=x.degree,C=Number(x.minute).toFixed(s),A=x.direction,B=P.degree,U=Number(P.minute).toFixed(s),j=P.direction,O=[y,String(S),C,A,String(B),U,j];r&&O.push(f===0?"***":m.port!=null?String(m.port):"***"),i&&O.push(f===0?"***":m.stbd!=null?String(m.stbd):"***"),c&&O.push(f===0?"***":m.arrRad!=null?String(m.arrRad):"***"),a&&O.push(f===0?"***":m.speed!=null?Number(m.speed).toFixed(1).padStart(5,"0"):"***"),l&&O.push(f===0?"***":m.gcToPrevious?"GC":"RL"),u&&O.push(f===0?"***":m.rot!=null?String(m.rot):"***"),g&&O.push(f===0?"***":m.turnRad!=null?String(m.turnRad):"***"),o&&O.push(m.name??""),p.push(O.join(","))}return p.join(`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "2.2.9",
4
+ "version": "2.3.0",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [