@idm-plugin/geo 2.3.7 → 2.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.
@@ -1,9 +1,9 @@
1
- (function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,Z(w["idm-plugin-rabbitmq"]={},w["@turf/turf"],w.moment,w["@log4js-node/log4js-api"],w["moment-timezone"],w["tz-lookup"],w.shpjs))})(this,function(w,Z,x,J,ie,Y,Q){"use strict";function _(C){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(C){for(const t in C)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(C,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>C[t]})}}return e.default=C,Object.freeze(e)}const T=_(Z);class f{static guessTimeZoneOffset(e,t){e=f.convertToStdLng(e);const n=Y(t,e),s=x().tz(n).utcOffset();return f.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=f.convertToStdLng(e,6);let s="E";e<0&&(s="W"),e=Math.abs(e),n=n.toUpperCase();let c=e*3600,i,r,o,a,l,u;i=c%3600%60,n.indexOf("S")!==-1&&(c=c-i,r=f.padNumber(i,2,2)),o=c/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=f.roundPrecision(o,t).toString().padStart(2,"0"):a=f.padNumber(o,2,3),c=c-o*60),l=c/3600,n.indexOf("M")!==-1?u=f.roundPrecision(l,t).toString().padStart(3,"0"):u=f.padNumber(l,3,6),Number(r)>=60&&(a=Number(a)+1,r=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:f.roundPrecision(l,t),minute:f.roundPrecision(o,t),second:f.roundPrecision(i,t),pretty:g,S:r,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 c=e*3600,i,r,o,a,l,u;i=c%3600%60,n.indexOf("S")!==-1&&(c=c-i,r=f.padNumber(i,2,2)),o=c/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=f.roundPrecision(o,t).toString().padStart(2,"0"):a=f.padNumber(o,2,3),c=c-o*60),l=c/3600,n.indexOf("M")!==-1?u=f.roundPrecision(l,t).toString().padStart(2,"0"):u=f.padNumber(l,2,6),Number(r)>=60&&(a=Number(a)+1,r=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:f.roundPrecision(l,t),minute:f.roundPrecision(o,t),second:f.roundPrecision(i,t),pretty:g,S:r,M:a,H:u}}static str2Lng(e,t=6){let n;if(isNaN(e)){e=f.strReplace(e,"LNG");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const c=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[i,r,o]=c;if(r=r||0,r=r>60?r/Math.pow(10,String(r).length-2):r,o=o||0,o=o>60?o/Math.pow(10,String(o).length-2):o,i>360&&!r){const a=this.roundPrecision(i/100,0);r=i-a*100,i=a}n=i+r/60+o/3600,s==="W"&&(n=n*-1)}else n=Number(e);return f.convertToStdLng(n,t)}static str2Lat(e,t=6){let n;if(isNaN(e)){e=f.strReplace(e,"LAT");const s=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const c=e.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[i,r,o]=c;if(o=o||0,r=r||0,r=r>60?r/Math.pow(10,String(r).length-2):r,o=o>60?o/Math.pow(10,String(o).length-2):o,i>90&&!r){const a=this.roundPrecision(i/100,0);r=i-a*100,i=a}if(n=i+r/60+o/3600,n>90)throw new Error(`latitude out of range: ${e}${s}`);s==="S"&&(n=n*-1)}else n=Number(e);return f.roundPrecision(n,t)}static str2LngOrLat(e,t=6,n="LAT"){e=f.strReplace(e,n);const s=e[e.length-1].toUpperCase();return["N","S"].includes(s)?{lat:f.str2Lat(e,t)}:{lng:f.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),f.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,c=Number(s.split(" ")[0]);if(isNaN(c))throw new Error(`invalid Lat/Lng: ${e}`);c>=90?e=`${s}E`:c<=-90?e=`${s}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${s}${c>0?"E":"W"}`:e=`${s}${c>0?"N":"S"}`}return e}static padNumber(e,t=2,n=2){const s=f.roundPrecision(e-Math.trunc(e),n),c=s>=1?Math.trunc(e+1).toString().padStart(t,"0"):Math.trunc(e).toString().padStart(t,"0");return s>=1?c:n>0?`${c}.${Math.trunc(s*Math.pow(10,n)).toString().padStart(n,"0")}`:c}}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,c,i,r,o,a,l,u,g]=e.split("|");return{lat:Number(t),lng:Number(n),positionTime:Number(s),sog:Number(c),cog:Number(i),hdg:Number(r),draught:isNaN(o)?null:Number(o),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((o,a)=>o.positionTime-a.positionTime);const c=[];let i,r;for(let o=0;o<e.length-1;o++){const a=e[o];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let l=o+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 d=g.positionTime-u.positionTime;if(b.calculateDistance(g,u,!0,4)/(d/3600)<t)i||(i=a),l===e.length-1&&(r=g,o=l);else{i&&(r=e[l-1],o=l);break}}if((r==null?void 0:r.positionTime)>(i==null?void 0:i.positionTime)&&i){const l={start:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:x.unix(i.positionTime).utc().format()},end:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:x.unix(r.positionTime).utc().format()},duration:r.positionTime-i.positionTime},u=e.filter(d=>d.positionTime>=l.start.positionTime&&d.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,c.push(l))}i=void 0,r=void 0}}return s||e.sort((o,a)=>a.positionTime-o.positionTime),c}static inspectSummary(e,t,n){const s=x(t),c=x(n),i=e.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=c.unix());let r=0,o=0;if(i.length>1)for(let l=0;l<i.length-1;l++){const u=i[l],g=i[l+1];r+=b.calculateDistance(u,g,!0,4),o+=Math.abs(g.positionTime-u.positionTime)}r=Math.round(r*100)/100,o=Math.round(o/3600*100)/100;const a=o?Math.round(r/o*100)/100:0;return{distance:r,interval:o,avgSpd:a}}}let L;try{L=J.getLogger("meteo")}catch{}finally{}const H=(()=>{const C=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;C[e]=t}return C})();function ee(C){let e=4294967295;for(let t=0;t<C.length;t++)e=H[(e^C[t])&255]^e>>>8;return(e^4294967295)>>>0}function te(C){const e=new TextEncoder,t=[],n=[];let s=0;for(const d of C){const p=e.encode(d.name),h=ee(d.data),m=new Uint8Array(30+p.length),S=new DataView(m.buffer);S.setUint32(0,67324752,!0),S.setUint16(4,20,!0),S.setUint16(8,0,!0),S.setUint32(14,h,!0),S.setUint32(18,d.data.length,!0),S.setUint32(22,d.data.length,!0),S.setUint16(26,p.length,!0),m.set(p,30),t.push({nameBytes:p,data:d.data,crc:h,offset:s}),s+=m.length+d.data.length,n.push(m,d.data)}const c=s,i=[];let r=0;for(const d of t){const p=new Uint8Array(46+d.nameBytes.length),h=new DataView(p.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(10,0,!0),h.setUint32(16,d.crc,!0),h.setUint32(20,d.data.length,!0),h.setUint32(24,d.data.length,!0),h.setUint16(28,d.nameBytes.length,!0),h.setUint32(42,d.offset,!0),p.set(d.nameBytes,46),r+=p.length,i.push(p)}const o=new Uint8Array(22),a=new DataView(o.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,r,!0),a.setUint32(16,c,!0);const l=n.reduce((d,p)=>d+p.length,0)+r+22,u=new Uint8Array(l);let g=0;for(const d of n)u.set(d,g),g+=d.length;for(const d of i)u.set(d,g),g+=d.length;return u.set(o,g),u}function V(C){let e="",t=C;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 c=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let i;return n?i=T.rhumbBearing(c.features[0],c.features[1]):i=T.bearing(c.features[0],c.features[1]),i<0&&(i+=360),f.roundPrecision(i,s)}static calculateDistance(e,t,n=!0,s=4,c="nauticalmiles"){e={...e},t={...t},e.lng=f.convertToStdLng(e.lng,s),t.lng=f.convertToStdLng(t.lng,s);const i=T.points([[e.lng,e.lat],[t.lng,t.lat]]);let r;return n?r=T.rhumbDistance(i.features[0],i.features[1],{units:c}):r=T.distance(i.features[0],i.features[1],{units:c}),f.roundPrecision(r,s)}static calculateRouteDistance(e,t=4,n="nauticalmiles"){let s=0,c;for(const i of e)for(let r=0;r<i.length-1;r++){const o={lng:i[r][0],lat:i[r][1]};r===0&&c&&(s+=this.calculateDistance(c,o,!0,t,n));const a={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(o,a,!0,t,n),c=a}return f.roundPrecision(s,t)}static calculateCoordinate(e,t,n,s="nauticalmiles",c=!0){const i=T.point([e.lng,e.lat]);let r;c?r=T.rhumbDestination(i,n,t,{units:s}):r=T.destination(i,n,t,{units:s});const o=r.geometry.coordinates;return{lng:f.convertToStdLng(o[0],8),lat:f.roundPrecision(o[1],8)}}static interpolateCoordinates(e,t,n,s=!0,c=!0,i="nauticalmiles"){const r=[],o=this.calculateBearing(e,t,!1),a=this.calculateDistance(e,t,!1,8,i);s&&r.push({lng:e.lng,lat:e.lat});let l=0;for(;l<a;)l+=n,l<a&&r.push(this.calculateCoordinate(e,o,l,i,!1));return c&&r.push({lng:t.lng,lat:t.lat}),r}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 c=[];let i,r;for(let o=0;o<e.length-1;o++){i=f.convertToStdLng(e[o].lng,8),r=f.convertToStdLng(e[o+1].lng,8),e[o].lat=f.roundPrecision(e[o].lat,8),e[o+1].lat=f.roundPrecision(e[o+1].lat,8),s.push([i,e[o].lat]);const a=i-r;if(Math.abs(a)>180){const l=f.convertToMonotonicLng2([[i,e[o].lat],[r,e[o+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 d=T.lineIntersect(u,g);let p;if(d.features.length){const h=T.getCoord(d.features[0]);p=f.roundPrecision(h[1],8)}else p=e[o].lat;a>0?(s.push([180-1e-6,p]),c.push([...s]),s=[],s.push([-(180-1e-6),p])):(s.push([-(180-1e-6),p]),c.push([...s]),s=[],s.push([180-1e-6,p]))}o===e.length-2&&s.push([r,e[o+1].lat])}return c.push(s),c}static deduplicateRoute(e){const t=[];for(const n of e){const s=n.reduce((c,i)=>(c.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&c.push(i),c),[]);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=f.convertToStdLng(e.lng,8);for(const n of t)for(let s=n.length-1;s>=0;s--)f.roundPrecision(n[s][0],8)===e.lng&&f.roundPrecision(n[s][1],8)===f.roundPrecision(e.lat,8)&&n.splice(s,1);return t}static removeCoordinateFromWaypoints(e,t){e.lng=f.convertToStdLng(e.lng,8);for(let n=t.length-1;n>=0;n--)f.roundPrecision(t[n].lng,8)===e.lng&&f.roundPrecision(t[n].lat,8)===f.roundPrecision(e.lat,8)&&t.splice(n,1);return t}static mergeCoordinateToRoute(e,t){e.lng=f.convertToStdLng(e.lng,8);let n=Number.MAX_VALUE,s=0,c=0,i,r;return t.forEach((o,a)=>{for(let l=0;l<o.length-1;l++){const u={lng:o[l][0],lat:o[l][1]},g={lng:o[l+1][0],lat:o[l+1][1]},d=this.calculatePointToLineDistance(e,u,g);n>d&&(n=d,c=l,s=a,i=this.calculateDistance(u,e),r=this.calculateDistance(g,e))}}),i!==0&&r!==0?t[s].splice(c+1,0,[e.lng,e.lat]):i===0?t[s].splice(c,1,[e.lng,e.lat]):r===0&&t[s].splice(c+1,1,[e.lng,e.lat]),t}static appendCoordinateToRoute(e,t){e.lng=f.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 c=0;return n.forEach(i=>{if(c===2)return;const r=[];for(const o of i){if(f.roundPrecision(t.lng,8)===f.roundPrecision(o[0],8)&&f.roundPrecision(t.lat,8)===f.roundPrecision(o[1],8)){r.push(o),c===0&&r.push([e.lng,e.lat]),c=2;break}c===1?r.push(o):f.roundPrecision(e.lng,8)===f.roundPrecision(o[0],8)&&f.roundPrecision(e.lat,8)===f.roundPrecision(o[1],8)&&(c=1,r.push(o))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(e,t,n,s=[]){const c=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([e,t],c.length?c:s),r=i.findIndex(l=>f.roundPrecision(e.lng,8)===f.roundPrecision(l.lng,8)&&f.roundPrecision(e.lat,8)===f.roundPrecision(l.lat,8)),o=i.findIndex(l=>f.roundPrecision(t.lng,8)===f.roundPrecision(l.lng,8)&&f.roundPrecision(t.lat,8)===f.roundPrecision(l.lat,8));return i.filter((l,u)=>u>=r&&u<=o)}static calculateMinDistanceToRoute(e,t){let n=Number.MAX_VALUE,s=0,c=0;return t.forEach((i,r)=>{for(let o=0;o<i.length-1;o++){const a={lng:i[o][0],lat:i[o][1]},l={lng:i[o+1][0],lat:i[o+1][1]},u=this.calculatePointToLineDistance(e,a,l);n>u&&(n=u,s=o,c=r)}}),{minDist:n,segIndex:c,minIndex:s}}static calculateSubRoute(e,t){const n=b.convertRouteToCoordinates(t);b.mergeCoordinateToWaypoints(e,n,!0),t=b.divideAccordingToLng(n);const{segIndex:s,minIndex:c}=this.calculateMinDistanceToRoute({...e},t);e.lng=f.convertToStdLng(e.lng);const i=[];let r=!0;for(let o=s;o<t.length;o++)if(r){const a=[];a.push([e.lng,e.lat]);for(let l=c+1;l<t[o].length;l++)e.lng===t[o][l][0]&&e.lat===t[o][l][1]||a.push(t[o][l]);i.push(a),r=!1}else i.push([...t[o]]);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],o=t[i+1];if(this.calculateDistance(e,r)===0)return t;if(this.calculateDistance(e,o)===0)return t.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(e,r,o);n>a&&(n=a,s=i)}e.lng=f.convertToStdLng(e.lng);const c=[e];for(let i=s+1;i<t.length;i++)c.push(t[i]);return c}static calculatePointToLineDistance(e,t,n,s={units:"nauticalmiles",method:"geodesic"}){e.lng=f.convertToStdLng(e.lng,8),t={...t},n={...n},t.lng=f.convertToStdLng(t.lng,8),n.lng=f.convertToStdLng(n.lng,8);const c=f.convertToMonotonicLng([t,n]);t=c[0],n=c[1];const i=T.lineString([[t.lng,t.lat],[n.lng,n.lat]]),r=T.pointToLineDistance(T.point([e.lng,e.lat]),i,s),o=T.pointToLineDistance(T.point([e.lng>0?e.lng-360:e.lng+360,e.lat]),i,s);return f.roundPrecision(Math.min(r,o),6)}static calculateWaypointsPropInRoute(e,t){t=this.mergeWaypointsToRoute(e,t);for(let n=0;n<e.length-1;n++){const s=e[n],c=e[n+1],i=this.calculateRangeRoute(s,c,t);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),c.distanceFromPrevious=this.calculateRouteDistance(i),c.distanceFromStart=f.roundPrecision((s.distanceFromStart||0)+c.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=f.convertToStdLng(e.lng,8);let s=Number.MAX_VALUE,c=0,i=0,r=0;if(t.length<2)t.push(e);else{for(let o=0;o<t.length-1;o++){const a={lng:t[o].lng,lat:t[o].lat},l={lng:t[o+1].lng,lat:t[o+1].lat},u=this.calculatePointToLineDistance(e,a,l);s>=u&&(s=u,c=o,i=this.calculateDistance(a,e,!1,6),r=this.calculateDistance(l,e,!1,6))}i!==0&&r!==0?i<=s&&c===0?t.unshift(e):r<=s&&c===t.length-2?t.push(e):t.splice(c+1,0,e):i===0?n?t.splice(c,1,e):t.splice(c+1,0,e):r===0&&(n?t.splice(c+1,1,e):t.splice(c+1,0,e))}return t.map((o,a)=>{o.lng=f.convertToStdLng(o.lng);const l=t[a+1];if(l&&((o.bearing===null||o.bearing===void 0)&&((o.positionTime||0)>(l.positionTime||0)?o.bearing=this.calculateBearing(l,o,!0):o.bearing=this.calculateBearing(o,l,!0)),o.cog=o.cog||o.bearing,!o.sog&&o.positionTime&&l.positionTime)){const u=this.calculateDistance(o,l,!0),g=Math.abs(l.positionTime-o.positionTime)/3600;o.sog=f.roundPrecision(u/g,2)}return o})}static generateRouteAccordingToWaypoints(e,t=!0,n=!0){const s=[];for(let c=1;c<e.length;c++){const i=e[c-1],r=e[c];if(c===1&&s.push(i),r.gcToPrevious){const o=this.interpolateCoordinates(i,r,200,!1,!0,"nauticalmiles");s.push(...o)}else s.push(r)}return this.divideAccordingToLng(s,t,n)}static nearestCoordinateInRoute(e,t){const n=T.point([e.lng,e.lat]),c=this.convertRouteToCoordinates(t).map(a=>[a.lng,a.lat]),i=T.lineString(c),r=T.nearestPointOnLine(i,n),o=T.getCoord(r);return{lng:f.roundPrecision(o[0],8),lat:f.roundPrecision(o[1],8)}}static calculatePrevWaypoint(e,t){let n=0;this.mergeCoordinateToWaypoints(e,t);for(let s=0;s<t.length-1;s++){const c=t[s],i=t[s+1];if(this.calculateDistance(e,c)===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 g;const c=e.speed||12,i=[];let r=[],o=!1,a=0,l=0,u;if(t&&n.length?(i.push(e),n.forEach((d,p)=>{if(o)r.push(d);else{const h=[];let m;for(let S=0;S<d.length;S++)if(u)h.push(d[S]);else{m={lng:d[S][0],lat:d[S][1]};const v=this.calculateDistance(e,m,!0,8,s);if(a+=v,a<t)l+=v,v&&i.push(m),e=m;else{if(l=t,a===t)u=m,h.push([u.lng,u.lat]);else{const P=a-t,y=this.calculateBearing(m,e);u=this.calculateCoordinate(m,y,P,s),h.push([u.lng,u.lat]),h.push([m.lng,m.lat])}o=!0}}h.length&&r.push(h),p===n.length-1&&!u&&(u=m)}})):(r=n,u={...e}),u)if(i.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/c*1e4)/1e4,((g=r[0])==null?void 0:g.length)>1){const d={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,d)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(e,t,n){const s=f.convertToStdLng(e.lng,6),c=T.point([s,e.lat]),i=f.convertToStdLng(t.lng,6),r=f.convertToStdLng(n.lng,6),o=T.lineString([[i,t.lat],[r,n.lat]]),a=T.nearestPointOnLine(o,c),l=T.getCoord(a),u=f.roundPrecision(l[0],6),g=f.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===i&&g===t.lat)&&!(u===r&&g===n.lat)}}static convertRouteToCoordinates(e,t=0){const n=[];let s,c;return e.forEach(i=>{i.forEach(r=>{const o={lng:f.roundPrecision(r[0],8),lat:f.roundPrecision(r[1],8)};if(!c)n.push(o),c=o;else if(c.bearing===void 0||c.bearing===null)c.bearing=this.calculateBearing(c,o,!0);else{const a=this.calculateDistance(s,o,!0);a&&a>=t&&(s.bearing=this.calculateBearing(s,o,!0),n.push(s),c=s)}s=o})}),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 c=t[s-1],i=t[s];if(i.gcToPrevious){const r=e.findIndex(a=>a.lng===c.lng&&a.lat===c.lat),o=e.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=o-1;a>r;a--)e.splice(a,1)}}let n=0;for(let s=1;s<e.length;s++){const c=e[s-1],i=e[s];i.gcToPrevious?(c.bearing=this.calculateBearing(c,i,!1),i.distanceFromPrevious=this.calculateDistance(c,i,!1)):(c.bearing=this.calculateBearing(c,i,!0),i.distanceFromPrevious=this.calculateDistance(c,i,!0)),n=f.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return e.map(s=>(s.lng=f.convertToStdLng(s.lng),s))}static calculateCenter(e){const t=[];for(const r of e)for(const o of r)t.push(o);const n=T.featureCollection([]),s=f.convertToMonotonicLng2(t);for(const r of s)n.features.push(T.point(r));const i=T.center(n).geometry.coordinates;return{lng:f.convertToStdLng(i[0],8),lat:f.roundPrecision(i[1],8)}}static calculateCenter2(e){const t=this.generateRouteAccordingToWaypoints(e);return this.calculateCenter(t)}static calculateBBox(e){const t=[];for(const c of e)for(const i of c)t.push(i);const n=f.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){if(e.length<=2)return[...e];const s=[e[0]];let c=0;for(let i=1;i<e.length-1;i++){const r=e[i],o=e[i+1],a=e[c];if(r.important||r.pilot||r.suspend||r.velocity||r.gcToPrevious){s.push(r),c=i;continue}const l=b.calculateDistance(a,r,!0),u=b.calculateDistance(r,o,!0),g=b.calculateDistance(a,o,!0);let d=(l*l+u*u-g*g)/(2*l*u);d=Math.max(-1,Math.min(1,d));const p=Math.acos(d)*(180/Math.PI);if(p>=180||p>=n&&g<=t){L.warn("simplify: skip point %d (angle=%d°, dist=%d): %j",i,p,g,r);continue}s.push(r),c=i}return s.push(e[e.length-1]),s}static nearestTSPointInWaypoints(e,t,n){const s=x.unix(e),c=n.filter(i=>s.clone().subtract(t,"hour").unix()<=(i.positionTime||0)&&s.clone().add(t,"h").unix()>=(i.positionTime||0));return c.sort((i,r)=>(i.positionTime||0)-(r.positionTime||0)),c.at(-1)}static deadReckoning(e,t){var c,i,r,o;e>1e12&&(e=Math.round(e/1e3));const n=x.unix(e);let s=t.find(a=>a.positionTime===n.unix());if(!s){const a=(i=(c=t.filter(u=>(u==null?void 0:u.positionTime)<n.unix()))==null?void 0:c.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:i.at(-1),l=(o=(r=t.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:r.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:o.at(0);if(a&&l){const u=b.calculateBearing(a,l,!0),g=b.calculateDistance(a,l),d=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=b.calculateCoordinate(a,u,g*d),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=x.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 c=t[s],i=t[s+1],r=b.calculateDistance(c,e),o=b.calculateDistance(i,e);if(r===0)e=c;else if(o===0)e=i;else{const a=c.positionTime||0,l=i.positionTime||0,u=b.calculateDistance(c,i);e.positionTime=Math.round(a+(l-a)*(r/u))}return e.utc=e.positionTime?x.unix(e.positionTime).utc().format():void 0,e.positionTime?e:void 0}static reverseRoute(e){const t=[];for(let n=e.length-1;n>=0;n--)t.push(e[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(w,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):(w=typeof globalThis<"u"?globalThis:w||self,Z(w["idm-plugin-rabbitmq"]={},w["@turf/turf"],w.moment,w["@log4js-node/log4js-api"],w["moment-timezone"],w["tz-lookup"],w.shpjs))})(this,function(w,Z,P,V,it,Y,Q){"use strict";function _(C){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(C){for(const e in C)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(C,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>C[e]})}}return t.default=C,Object.freeze(t)}const T=_(Z);class f{static guessTimeZoneOffset(t,e){t=f.convertToStdLng(t);const n=Y(e,t),s=P().tz(n).utcOffset();return f.roundPrecision(s/60,1)}static prettyTimeZoneOffset(t){let e=Math.floor(Math.abs(t)),n=Math.round((Math.abs(t)-e)*60);return n=n>9?n:`0${n}`,e=e>9?e:`0${e}`,t>0?`+${e}:${n}`:`-${e}:${n}`}static lng2pretty(t,e=6,n="H°M′"){t=f.convertToStdLng(t,6);let s="E";t<0&&(s="W"),t=Math.abs(t),n=n.toUpperCase();let c=t*3600,i,r,o,a,l,u;i=c%3600%60,n.indexOf("S")!==-1&&(c=c-i,r=f.padNumber(i,2,2)),o=c/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=f.roundPrecision(o,e).toString().padStart(2,"0"):a=f.padNumber(o,2,3),c=c-o*60),l=c/3600,n.indexOf("M")!==-1?u=f.roundPrecision(l,e).toString().padStart(3,"0"):u=f.padNumber(l,3,6),Number(r)>=60&&(a=Number(a)+1,r=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:f.roundPrecision(l,e),minute:f.roundPrecision(o,e),second:f.roundPrecision(i,e),pretty:g,S:r,M:a,H:u}}static lat2pretty(t,e=6,n="H°M′"){t=t%180;let s="N";t<0&&(s="S"),t=Math.abs(t),n=n.toUpperCase();let c=t*3600,i,r,o,a,l,u;i=c%3600%60,n.indexOf("S")!==-1&&(c=c-i,r=f.padNumber(i,2,2)),o=c/60%60,n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?a=f.roundPrecision(o,e).toString().padStart(2,"0"):a=f.padNumber(o,2,3),c=c-o*60),l=c/3600,n.indexOf("M")!==-1?u=f.roundPrecision(l,e).toString().padStart(2,"0"):u=f.padNumber(l,2,6),Number(r)>=60&&(a=Number(a)+1,r=0),Number(a)>=60&&(u=Number(u)+1,a=0);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,a).replace(/H+/gi,u)}${s}`;return{direction:s,degree:f.roundPrecision(l,e),minute:f.roundPrecision(o,e),second:f.roundPrecision(i,e),pretty:g,S:r,M:a,H:u}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=f.strReplace(t,"LNG");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const c=t.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[i,r,o]=c;if(r=r||0,r=r>60?r/Math.pow(10,String(r).length-2):r,o=o||0,o=o>60?o/Math.pow(10,String(o).length-2):o,i>360&&!r){const a=this.roundPrecision(i/100,0);r=i-a*100,i=a}n=i+r/60+o/3600,s==="W"&&(n=n*-1)}else n=Number(t);return f.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=f.strReplace(t,"LAT");const s=t[t.length-1].toUpperCase();t=t.substring(0,t.length-1).trim();const c=t.split(" ").filter(a=>a!=="").map(a=>Math.abs(Number(a)));let[i,r,o]=c;if(o=o||0,r=r||0,r=r>60?r/Math.pow(10,String(r).length-2):r,o=o>60?o/Math.pow(10,String(o).length-2):o,i>90&&!r){const a=this.roundPrecision(i/100,0);r=i-a*100,i=a}if(n=i+r/60+o/3600,n>90)throw new Error(`latitude out of range: ${t}${s}`);s==="S"&&(n=n*-1)}else n=Number(t);return f.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=f.strReplace(t,n);const s=t[t.length-1].toUpperCase();return["N","S"].includes(s)?{lat:f.str2Lat(t,e)}:{lng:f.str2Lng(t,e)}}static convertToStdLng(t,e=6){return t>180?(t=t%360,t=t>180?t-360:t):t<-180&&(t=t%360,t=t<-180?t+360:t),f.roundPrecision(t,e)}static roundPrecision(t,e=6){const n=Number("1".padEnd(e+1,"0"));return Math.round(t*n)/n}static convertToMonotonicLng2(t){for(let e=1;e<t.length;e++)t[e][0]+=Math.round((t[e-1][0]-t[e][0])/360)*360;return t}static convertToMonotonicLng(t){for(let e=1;e<t.length;e++)t[e].lng+=Math.round((t[e-1].lng-t[e].lng)/360)*360;return t}static strReplace(t,e="LAT"){t=t.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=t[t.length-1].toUpperCase();if(!["N","S","E","W"].includes(n)){const s=t,c=Number(s.split(" ")[0]);if(isNaN(c))throw new Error(`invalid Lat/Lng: ${t}`);c>=90?t=`${s}E`:c<=-90?t=`${s}W`:["LAN","LNG"].includes(e==null?void 0:e.toUpperCase())?t=`${s}${c>0?"E":"W"}`:t=`${s}${c>0?"N":"S"}`}return t}static padNumber(t,e=2,n=2){const s=f.roundPrecision(t-Math.trunc(t),n),c=s>=1?Math.trunc(t+1).toString().padStart(e,"0"):Math.trunc(t).toString().padStart(e,"0");return s>=1?c:n>0?`${c}.${Math.trunc(s*Math.pow(10,n)).toString().padStart(n,"0")}`:c}}class K{static json2Str(t){const e=t.type?t.type[0].toUpperCase():"A";return`${t.lat}|${t.lng}|${t.positionTime}|${t.sog}|${t.cog}|${t.hdg}|${t.draught}|${e}|${JSON.stringify(t.meteo||{})}|${t.vendor}|${t.deleted}`}static str2Json(t){const[e,n,s,c,i,r,o,a,l,u,g]=t.split("|");return{lat:Number(e),lng:Number(n),positionTime:Number(s),sog:Number(c),cog:Number(i),hdg:Number(r),draught:isNaN(o)?null:Number(o),type:a,important:a!=="A",meteo:l?JSON.parse(l):void 0,vendor:u,deleted:g==="true"}}static inspectStoppages(t,e=1,n=!0){if(t.length<2)return t;const s=t.at(0).positionTime<t.at(-1).positionTime;s||t.sort((o,a)=>o.positionTime-a.positionTime);const c=[];let i,r;for(let o=0;o<t.length-1;o++){const a=t[o];if(!(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))){for(let l=o+1;l<t.length;l++){const u=t[l-1],g=t[l];if(n&&["N","B","E","NOON","BOSP","EOSP"].includes(a.type))continue;const d=g.positionTime-u.positionTime;if(b.calculateDistance(g,u,!0,4)/(d/3600)<e)i||(i=a),l===t.length-1&&(r=g,o=l);else{i&&(r=t[l-1],o=l);break}}if((r==null?void 0:r.positionTime)>(i==null?void 0:i.positionTime)&&i){const l={start:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:P.unix(i.positionTime).utc().format()},end:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:P.unix(r.positionTime).utc().format()},duration:r.positionTime-i.positionTime},u=t.filter(d=>d.positionTime>=l.start.positionTime&&d.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,c.push(l))}i=void 0,r=void 0}}return s||t.sort((o,a)=>a.positionTime-o.positionTime),c}static inspectSummary(t,e,n){const s=P(e),c=P(n),i=t.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=c.unix());let r=0,o=0;if(i.length>1)for(let l=0;l<i.length-1;l++){const u=i[l],g=i[l+1];r+=b.calculateDistance(u,g,!0,4),o+=Math.abs(g.positionTime-u.positionTime)}r=Math.round(r*100)/100,o=Math.round(o/3600*100)/100;const a=o?Math.round(r/o*100)/100:0;return{distance:r,interval:o,avgSpd:a}}}let L;try{L=V.getLogger("meteo")}catch{}finally{}const H=(()=>{const C=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;C[t]=e}return C})();function tt(C){let t=4294967295;for(let e=0;e<C.length;e++)t=H[(t^C[e])&255]^t>>>8;return(t^4294967295)>>>0}function et(C){const t=new TextEncoder,e=[],n=[];let s=0;for(const d of C){const p=t.encode(d.name),h=tt(d.data),m=new Uint8Array(30+p.length),S=new DataView(m.buffer);S.setUint32(0,67324752,!0),S.setUint16(4,20,!0),S.setUint16(8,0,!0),S.setUint32(14,h,!0),S.setUint32(18,d.data.length,!0),S.setUint32(22,d.data.length,!0),S.setUint16(26,p.length,!0),m.set(p,30),e.push({nameBytes:p,data:d.data,crc:h,offset:s}),s+=m.length+d.data.length,n.push(m,d.data)}const c=s,i=[];let r=0;for(const d of e){const p=new Uint8Array(46+d.nameBytes.length),h=new DataView(p.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(10,0,!0),h.setUint32(16,d.crc,!0),h.setUint32(20,d.data.length,!0),h.setUint32(24,d.data.length,!0),h.setUint16(28,d.nameBytes.length,!0),h.setUint32(42,d.offset,!0),p.set(d.nameBytes,46),r+=p.length,i.push(p)}const o=new Uint8Array(22),a=new DataView(o.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,e.length,!0),a.setUint16(10,e.length,!0),a.setUint32(12,r,!0),a.setUint32(16,c,!0);const l=n.reduce((d,p)=>d+p.length,0)+r+22,u=new Uint8Array(l);let g=0;for(const d of n)u.set(d,g),g+=d.length;for(const d of i)u.set(d,g),g+=d.length;return u.set(o,g),u}function J(C){let t="",e=C;for(;e>=0;)t=String.fromCharCode(65+e%26)+t,e=Math.floor(e/26)-1;return t}class b{static calculateBearing(t,e,n=!0,s=4){const c=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let i;return n?i=T.rhumbBearing(c.features[0],c.features[1]):i=T.bearing(c.features[0],c.features[1]),i<0&&(i+=360),f.roundPrecision(i,s)}static calculateDistance(t,e,n=!0,s=4,c="nauticalmiles"){t={...t},e={...e},t.lng=f.convertToStdLng(t.lng,s),e.lng=f.convertToStdLng(e.lng,s);const i=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let r;return n?r=T.rhumbDistance(i.features[0],i.features[1],{units:c}):r=T.distance(i.features[0],i.features[1],{units:c}),f.roundPrecision(r,s)}static calculateRouteDistance(t,e=4,n="nauticalmiles"){let s=0,c;for(const i of t)for(let r=0;r<i.length-1;r++){const o={lng:i[r][0],lat:i[r][1]};r===0&&c&&(s+=this.calculateDistance(c,o,!0,e,n));const a={lng:i[r+1][0],lat:i[r+1][1]};s+=this.calculateDistance(o,a,!0,e,n),c=a}return f.roundPrecision(s,e)}static calculateCoordinate(t,e,n,s="nauticalmiles",c=!0){const i=T.point([t.lng,t.lat]);let r;c?r=T.rhumbDestination(i,n,e,{units:s}):r=T.destination(i,n,e,{units:s});const o=r.geometry.coordinates;return{lng:f.convertToStdLng(o[0],8),lat:f.roundPrecision(o[1],8)}}static interpolateCoordinates(t,e,n,s=!0,c=!0,i="nauticalmiles"){const r=[],o=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,i);s&&r.push({lng:t.lng,lat:t.lat});let l=0;for(;l<a;)l+=n,l<a&&r.push(this.calculateCoordinate(t,o,l,i,!1));return c&&r.push({lng:e.lng,lat:e.lat}),r}static divideAccordingToLng(t,e=!1,n=!0){if((t==null?void 0:t.length)<2)return[];t=n?this.deduplicateCoordinates(t):t;let s=[];const c=[];let i,r;for(let o=0;o<t.length-1;o++){i=f.convertToStdLng(t[o].lng,8),r=f.convertToStdLng(t[o+1].lng,8),t[o].lat=f.roundPrecision(t[o].lat,8),t[o+1].lat=f.roundPrecision(t[o+1].lat,8),s.push([i,t[o].lat]);const a=i-r;if(Math.abs(a)>180){const l=f.convertToMonotonicLng2([[i,t[o].lat],[r,t[o+1].lat]]);let u,g;e?(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 d=T.lineIntersect(u,g);let p;if(d.features.length){const h=T.getCoord(d.features[0]);p=f.roundPrecision(h[1],8)}else p=t[o].lat;a>0?(s.push([180-1e-6,p]),c.push([...s]),s=[],s.push([-(180-1e-6),p])):(s.push([-(180-1e-6),p]),c.push([...s]),s=[],s.push([180-1e-6,p]))}o===t.length-2&&s.push([r,t[o+1].lat])}return c.push(s),c}static deduplicateRoute(t){const e=[];for(const n of t){const s=n.reduce((c,i)=>(c.findIndex(r=>r[0]===i[0]&&r[1]===i[1])===-1&&c.push(i),c),[]);e.push(s)}return e}static deduplicateCoordinates(t){return t.reduce((e,n)=>(e.findIndex(s=>s.lat===n.lat&&s.lng===n.lng)===-1&&e.push(n),e),[])}static removeCoordinateFromRoute(t,e){t.lng=f.convertToStdLng(t.lng,8);for(const n of e)for(let s=n.length-1;s>=0;s--)f.roundPrecision(n[s][0],8)===t.lng&&f.roundPrecision(n[s][1],8)===f.roundPrecision(t.lat,8)&&n.splice(s,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=f.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)f.roundPrecision(e[n].lng,8)===t.lng&&f.roundPrecision(e[n].lat,8)===f.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=f.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,s=0,c=0,i,r;return e.forEach((o,a)=>{for(let l=0;l<o.length-1;l++){const u={lng:o[l][0],lat:o[l][1]},g={lng:o[l+1][0],lat:o[l+1][1]},d=this.calculatePointToLineDistance(t,u,g);n>d&&(n=d,c=l,s=a,i=this.calculateDistance(u,t),r=this.calculateDistance(g,t))}}),i!==0&&r!==0?e[s].splice(c+1,0,[t.lng,t.lat]):i===0?e[s].splice(c,1,[t.lng,t.lat]):r===0&&e[s].splice(c+1,1,[t.lng,t.lat]),e}static appendCoordinateToRoute(t,e){t.lng=f.convertToStdLng(t.lng,8);const n=b.convertRouteToCoordinates(e);return n.push(t),b.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=b.convertRouteToCoordinates(e);return n.unshift(t),b.divideAccordingToLng(n)}static mergeWaypointsToRoute(t,e){for(const n of t)e=this.mergeCoordinateToRoute(n,e);return e}static calculateRangeRoute(t,e,n){n=this.mergeWaypointsToRoute([t,e],n);const s=[];let c=0;return n.forEach(i=>{if(c===2)return;const r=[];for(const o of i){if(f.roundPrecision(e.lng,8)===f.roundPrecision(o[0],8)&&f.roundPrecision(e.lat,8)===f.roundPrecision(o[1],8)){r.push(o),c===0&&r.push([t.lng,t.lat]),c=2;break}c===1?r.push(o):f.roundPrecision(t.lng,8)===f.roundPrecision(o[0],8)&&f.roundPrecision(t.lat,8)===f.roundPrecision(o[1],8)&&(c=1,r.push(o))}r.length&&s.push(r)}),s}static calculateRangeWaypoints(t,e,n,s=[]){const c=this.convertRouteToCoordinates(n,0),i=this.mergeCoordinatesToWaypoints([t,e],c.length?c:s),r=i.findIndex(l=>f.roundPrecision(t.lng,8)===f.roundPrecision(l.lng,8)&&f.roundPrecision(t.lat,8)===f.roundPrecision(l.lat,8)),o=i.findIndex(l=>f.roundPrecision(e.lng,8)===f.roundPrecision(l.lng,8)&&f.roundPrecision(e.lat,8)===f.roundPrecision(l.lat,8));return i.filter((l,u)=>u>=r&&u<=o)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,s=0,c=0;return e.forEach((i,r)=>{for(let o=0;o<i.length-1;o++){const a={lng:i[o][0],lat:i[o][1]},l={lng:i[o+1][0],lat:i[o+1][1]},u=this.calculatePointToLineDistance(t,a,l);n>u&&(n=u,s=o,c=r)}}),{minDist:n,segIndex:c,minIndex:s}}static calculateSubRoute(t,e){const n=b.convertRouteToCoordinates(e);b.mergeCoordinateToWaypoints(t,n,!0),e=b.divideAccordingToLng(n);const{segIndex:s,minIndex:c}=this.calculateMinDistanceToRoute({...t},e);t.lng=f.convertToStdLng(t.lng);const i=[];let r=!0;for(let o=s;o<e.length;o++)if(r){const a=[];a.push([t.lng,t.lat]);for(let l=c+1;l<e[o].length;l++)t.lng===e[o][l][0]&&t.lat===e[o][l][1]||a.push(e[o][l]);i.push(a),r=!1}else i.push([...e[o]]);return i}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,s=0;for(let i=0;i<e.length-1;i++){const r=e[i],o=e[i+1];if(this.calculateDistance(t,r)===0)return e;if(this.calculateDistance(t,o)===0)return e.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(t,r,o);n>a&&(n=a,s=i)}t.lng=f.convertToStdLng(t.lng);const c=[t];for(let i=s+1;i<e.length;i++)c.push(e[i]);return c}static calculatePointToLineDistance(t,e,n,s={units:"nauticalmiles",method:"geodesic"}){t.lng=f.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=f.convertToStdLng(e.lng,8),n.lng=f.convertToStdLng(n.lng,8);const c=f.convertToMonotonicLng([e,n]);e=c[0],n=c[1];const i=T.lineString([[e.lng,e.lat],[n.lng,n.lat]]),r=T.pointToLineDistance(T.point([t.lng,t.lat]),i,s),o=T.pointToLineDistance(T.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),i,s);return f.roundPrecision(Math.min(r,o),6)}static calculateWaypointsPropInRoute(t,e){e=this.mergeWaypointsToRoute(t,e);for(let n=0;n<t.length-1;n++){const s=t[n],c=t[n+1],i=this.calculateRangeRoute(s,c,e);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),c.distanceFromPrevious=this.calculateRouteDistance(i),c.distanceFromStart=f.roundPrecision((s.distanceFromStart||0)+c.distanceFromPrevious)}return t}static mergeCoordinatesToWaypoints(t,e,n=!0){for(const s of t)this.mergeCoordinateToWaypoints(s,e,n);return e}static mergeCoordinateToWaypoints(t,e,n=!0){t.lng=f.convertToStdLng(t.lng,8);let s=Number.MAX_VALUE,c=0,i=0,r=0;if(e.length<2)e.push(t);else{for(let o=0;o<e.length-1;o++){const a={lng:e[o].lng,lat:e[o].lat},l={lng:e[o+1].lng,lat:e[o+1].lat},u=this.calculatePointToLineDistance(t,a,l);s>=u&&(s=u,c=o,i=this.calculateDistance(a,t,!1,6),r=this.calculateDistance(l,t,!1,6))}i!==0&&r!==0?i<=s&&c===0?e.unshift(t):r<=s&&c===e.length-2?e.push(t):e.splice(c+1,0,t):i===0?n?e.splice(c,1,t):e.splice(c+1,0,t):r===0&&(n?e.splice(c+1,1,t):e.splice(c+1,0,t))}return e.map((o,a)=>{o.lng=f.convertToStdLng(o.lng);const l=e[a+1];if(l&&((o.bearing===null||o.bearing===void 0)&&((o.positionTime||0)>(l.positionTime||0)?o.bearing=this.calculateBearing(l,o,!0):o.bearing=this.calculateBearing(o,l,!0)),o.cog=o.cog||o.bearing,!o.sog&&o.positionTime&&l.positionTime)){const u=this.calculateDistance(o,l,!0),g=Math.abs(l.positionTime-o.positionTime)/3600;o.sog=f.roundPrecision(u/g,2)}return o})}static generateRouteAccordingToWaypoints(t,e=!0,n=!0){const s=[];for(let c=1;c<t.length;c++){const i=t[c-1],r=t[c];if(c===1&&s.push(i),r.gcToPrevious){const o=this.interpolateCoordinates(i,r,200,!1,!0,"nauticalmiles");s.push(...o)}else s.push(r)}return this.divideAccordingToLng(s,e,n)}static nearestCoordinateInRoute(t,e){const n=T.point([t.lng,t.lat]),c=this.convertRouteToCoordinates(e).map(a=>[a.lng,a.lat]),i=T.lineString(c),r=T.nearestPointOnLine(i,n),o=T.getCoord(r);return{lng:f.roundPrecision(o[0],8),lat:f.roundPrecision(o[1],8)}}static calculatePrevWaypoint(t,e){let n=0;this.mergeCoordinateToWaypoints(t,e);for(let s=0;s<e.length-1;s++){const c=e[s],i=e[s+1];if(this.calculateDistance(t,c)===0){n=s;break}if(this.calculateDistance(t,i)===0){n=s+1;break}}return e[n===0?0:n-1]}static calculateNextCoordinateAlongRoute(t,e,n,s="nauticalmiles"){var g;const c=t.speed||12,i=[];let r=[],o=!1,a=0,l=0,u;if(e&&n.length?(i.push(t),n.forEach((d,p)=>{if(o)r.push(d);else{const h=[];let m;for(let S=0;S<d.length;S++)if(u)h.push(d[S]);else{m={lng:d[S][0],lat:d[S][1]};const v=this.calculateDistance(t,m,!0,8,s);if(a+=v,a<e)l+=v,v&&i.push(m),t=m;else{if(l=e,a===e)u=m,h.push([u.lng,u.lat]);else{const x=a-e,y=this.calculateBearing(m,t);u=this.calculateCoordinate(m,y,x,s),h.push([u.lng,u.lat]),h.push([m.lng,m.lat])}o=!0}}h.length&&r.push(h),p===n.length-1&&!u&&(u=m)}})):(r=n,u={...t}),u)if(i.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/c*1e4)/1e4,((g=r[0])==null?void 0:g.length)>1){const d={lng:r[0][1][0],lat:r[0][1][1]};u.bearing=this.calculateBearing(u,d)}else u.bearing=0;return{coordinate:u,nextRoute:r,prevRoute:i}}static nearestCoordinateInLine(t,e,n){const s=f.convertToStdLng(t.lng,6),c=T.point([s,t.lat]),i=f.convertToStdLng(e.lng,6),r=f.convertToStdLng(n.lng,6),o=T.lineString([[i,e.lat],[r,n.lat]]),a=T.nearestPointOnLine(o,c),l=T.getCoord(a),u=f.roundPrecision(l[0],6),g=f.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===i&&g===e.lat)&&!(u===r&&g===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let s,c;return t.forEach(i=>{i.forEach(r=>{const o={lng:f.roundPrecision(r[0],8),lat:f.roundPrecision(r[1],8)};if(!c)n.push(o),c=o;else if(c.bearing===void 0||c.bearing===null)c.bearing=this.calculateBearing(c,o,!0);else{const a=this.calculateDistance(s,o,!0);a&&a>=e&&(s.bearing=this.calculateBearing(s,o,!0),n.push(s),c=s)}s=o})}),s&&n.push(s),n}static simplifyRouteToCoordinates(t,e,n=1){let s=this.convertRouteToCoordinates(t,n);return s=this.simplifyGCCoordinates(s,e),s}static simplifyGCCoordinates(t,e){e.forEach(s=>{this.mergeCoordinateToWaypoints(s,t,!0)});for(let s=1;s<e.length;s++){const c=e[s-1],i=e[s];if(i.gcToPrevious){const r=t.findIndex(a=>a.lng===c.lng&&a.lat===c.lat),o=t.findIndex(a=>a.lng===i.lng&&a.lat===i.lat);for(let a=o-1;a>r;a--)t.splice(a,1)}}let n=0;for(let s=1;s<t.length;s++){const c=t[s-1],i=t[s];i.gcToPrevious?(c.bearing=this.calculateBearing(c,i,!1),i.distanceFromPrevious=this.calculateDistance(c,i,!1)):(c.bearing=this.calculateBearing(c,i,!0),i.distanceFromPrevious=this.calculateDistance(c,i,!0)),n=f.roundPrecision(n+i.distanceFromPrevious),i.distanceFromStart=n}return t.map(s=>(s.lng=f.convertToStdLng(s.lng),s))}static calculateCenter(t){const e=[];for(const r of t)for(const o of r)e.push(o);const n=T.featureCollection([]),s=f.convertToMonotonicLng2(e);for(const r of s)n.features.push(T.point(r));const i=T.center(n).geometry.coordinates;return{lng:f.convertToStdLng(i[0],8),lat:f.roundPrecision(i[1],8)}}static calculateCenter2(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateCenter(e)}static calculateBBox(t){const e=[];for(const c of t)for(const i of c)e.push(i);const n=f.convertToMonotonicLng2(e),s=T.lineString(n);return T.bbox(s)}static calculateBBox2(t){const e=this.generateRouteAccordingToWaypoints(t);return this.calculateBBox(e)}static simplifyCoordinates(t,e=1,n=0){if(t.length<=2)return[...t];const s=b.rdpSimplify(t,e),i=(n>0?b.splitLongLegs(t,s,n):s).map(r=>t[r]);return L.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)",t.length,i.length,e,n),i}static rdpSimplify(t,e){const n=new Array(t.length).fill(!1);n[0]=!0,n[t.length-1]=!0;const s=[0];for(let o=1;o<t.length-1;o++){const a=t[o];(a.important||a.pilot||a.suspend||a.velocity||a.gcToPrevious)&&(n[o]=!0,s.push(o))}s.push(t.length-1);const c=t.map(o=>b.toUnitVector(o)),i=T.convertLength(1,"radians","nauticalmiles");for(let o=0;o<s.length-1;o++){const a=[[s[o],s[o+1]]];for(;a.length;){const[l,u]=a.pop(),g=c[l],d=c[u];let p=g[1]*d[2]-g[2]*d[1],h=g[2]*d[0]-g[0]*d[2],m=g[0]*d[1]-g[1]*d[0];const S=Math.sqrt(p*p+h*h+m*m),v=S<1e-12;v||(p/=S,h/=S,m/=S);let x=0,y=-1;for(let M=l+1;M<u;M++){const D=v?b.calculateDistance(t[M],t[l]):Math.asin(Math.min(1,Math.abs(c[M][0]*p+c[M][1]*h+c[M][2]*m)))*i;D>x&&(x=D,y=M)}x>e&&(n[y]=!0,a.push([l,y],[y,u]))}}const r=[];for(let o=0;o<n.length;o++)n[o]&&r.push(o);return r}static splitLongLegs(t,e,n){const s=[e[0]];for(let c=1;c<e.length;c++){const i=s[s.length-1],r=e[c],o=b.calculateDistance(t[i],t[r]);if(o>n&&r-i>=2){const a=Math.ceil(o/n),l=[0];for(let u=i+1;u<=r;u++)l.push(l[l.length-1]+b.calculateDistance(t[u-1],t[u]));for(let u=1;u<a;u++){const g=o/a*u;let d=i+1;for(;d<r-1&&l[d-i]<g;)d++;d>i&&d<r&&s[s.length-1]!==d&&s.push(d)}}s.push(r)}return s}static toUnitVector(t){const e=t.lat*Math.PI/180,n=t.lng*Math.PI/180;return[Math.cos(e)*Math.cos(n),Math.cos(e)*Math.sin(n),Math.sin(e)]}static perpendicularDeviation(t,e,n){const s=b.toUnitVector(e),c=b.toUnitVector(n),i=b.toUnitVector(t);let r=s[1]*c[2]-s[2]*c[1],o=s[2]*c[0]-s[0]*c[2],a=s[0]*c[1]-s[1]*c[0];const l=Math.sqrt(r*r+o*o+a*a);if(l<1e-12)return b.calculateDistance(t,e);r/=l,o/=l,a/=l;const u=T.convertLength(1,"radians","nauticalmiles");return Math.asin(Math.min(1,Math.abs(i[0]*r+i[1]*o+i[2]*a)))*u}static nearestTSPointInWaypoints(t,e,n){const s=P.unix(t),c=n.filter(i=>s.clone().subtract(e,"hour").unix()<=(i.positionTime||0)&&s.clone().add(e,"h").unix()>=(i.positionTime||0));return c.sort((i,r)=>(i.positionTime||0)-(r.positionTime||0)),c.at(-1)}static deadReckoning(t,e){var c,i,r,o;t>1e12&&(t=Math.round(t/1e3));const n=P.unix(t);let s=e.find(a=>a.positionTime===n.unix());if(!s){const a=(i=(c=e.filter(u=>(u==null?void 0:u.positionTime)<n.unix()))==null?void 0:c.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:i.at(-1),l=(o=(r=e.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:r.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:o.at(0);if(a&&l){const u=b.calculateBearing(a,l,!0),g=b.calculateDistance(a,l),d=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=b.calculateCoordinate(a,u,g*d),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=P.unix(s==null?void 0:s.positionTime).utc().format())}return s}static deadReckoningTime(t,e){e=JSON.parse(JSON.stringify(e)),e.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<e.length-1;a++){const l=e[a],u=e[a+1],g=b.calculatePointToLineDistance(t,l,u);g<n&&(n=g,s=a)}const c=e[s],i=e[s+1],r=b.calculateDistance(c,t),o=b.calculateDistance(i,t);if(r===0)t=c;else if(o===0)t=i;else{const a=c.positionTime||0,l=i.positionTime||0,u=b.calculateDistance(c,i);t.positionTime=Math.round(a+(l-a)*(r/u))}return t.utc=t.positionTime?P.unix(t.positionTime).utc().format():void 0,t.positionTime?t:void 0}static reverseRoute(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n].reverse());return e}static reverseCoordinates(t){return t.reverse()}static xmlEscape(t){return t==null?"":String(t).trim().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static waypoints2RTZ(t,e){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(t)}"></routeInfo>`),s.push(...b.toRTZWaypoints(e,6)),s.push("</route>"),s.join(`
2
2
  `)+`
3
- `}static waypoints2RTZ10(e,t,n=!0){const c=[];return c.push('<?xml version="1.0" encoding="UTF-8"?>'),c.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'),c.push(` <routeInfo routeName="${b.xmlEscape(e)}"></routeInfo>`),c.push(...b.toRTZWaypoints(t,6,n)),c.push("</route>"),c.join(`
3
+ `}static waypoints2RTZ10(t,e,n=!0){const c=[];return c.push('<?xml version="1.0" encoding="UTF-8"?>'),c.push('<route xmlns="http://www.cirm.org/RTZ/1/0" version="1.0">'),c.push(` <routeInfo routeName="${b.xmlEscape(t)}"></routeInfo>`),c.push(...b.toRTZWaypoints(e,6,n)),c.push("</route>"),c.join(`
4
4
  `)+`
5
- `}static toRTZWaypoints(e,t=6,n=!0){const s=[];s.push(" <waypoints>");for(let c=0;c<e.length;c++){const i=e[c],r=c+1,o=(i.lat??"").toFixed?i.lat.toFixed(t).padEnd(t+2,"0"):i.lat,a=(i.lng??"").toFixed?i.lng.toFixed(t).padEnd(t+2,"0"):i.lng,l=[`id="${r}"`,'revision="0"'];if(i.name&&l.push(`name="${b.xmlEscape(i.name)}"`),s.push(` <waypoint ${l.join(" ")}>`),s.push(` <position lat="${b.xmlEscape(o)}" lon="${b.xmlEscape(a)}" />`),c>0){const u=i.gcToPrevious?"Orthodrome":"Loxodrome";s.push(` <leg geometryType="${u}" />`)}if(n){const u=[];if(i.description&&u.push(` <description>${b.xmlEscape(i.description)}</description>`),i.utc)u.push(` <time>${b.xmlEscape(i.utc)}</time>`);else if(i.positionTime)try{u.push(` <time>${b.xmlEscape(x.unix(i.positionTime).utc().format())}</time>`)}catch{}i.cog!==void 0&&u.push(` <cog>${b.xmlEscape(i.cog)}</cog>`),i.sog!==void 0&&u.push(` <sog>${b.xmlEscape(i.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){L.debug("keep name for waypoints2CSV for legacy compatibility only",e);const s=(n==null?void 0:n.precision)??6,c=t.some(m=>m.name),i=t.some(m=>m.description),r=t.some(m=>m.port!=null),o=t.some(m=>m.stbd!=null),a=t.some(m=>m.arrRad!=null),l=t.some(m=>m.speed!=null),u=t.some((m,S)=>S>0&&m.gcToPrevious!=null),g=t.some(m=>m.bearing!=null),d=t.some(m=>m.distanceFromPrevious!=null),p=["WPT No.","Latitude","Longitude"];c&&p.push("Name"),i&&p.push("Description"),u&&p.push("Leg"),g&&p.push("Bearing[deg]"),d&&p.push("Distance[NM]"),l&&p.push("Speed[kn]"),r&&p.push("PORT XTD[NM]"),o&&p.push("STBD XTD[NM]"),a&&p.push("Arr.Rad[NM]");const h=[];h.push(p.map(m=>b.csvEscapeField(m)).join(","));for(let m=0;m<t.length;m++){const S=t[m],v=[];v.push((m+1).toString()),v.push(S.lat.toFixed(s)),v.push(S.lng.toFixed(s)),c&&v.push(S.name??""),i&&v.push(S.description??""),u&&v.push(m===0?"":S.gcToPrevious?"GC":"RL"),g&&v.push(S.bearing!=null?String(S.bearing):""),d&&v.push(S.distanceFromPrevious!=null?String(S.distanceFromPrevious):""),l&&v.push(S.speed!=null?String(S.speed):""),r&&v.push(S.port!=null?String(S.port):""),o&&v.push(S.stbd!=null?String(S.stbd):""),a&&v.push(S.arrRad!=null?String(S.arrRad):""),h.push(v.map(P=>b.csvEscapeField(P)).join(","))}return h.join(`
6
- `)}static waypoints2JRCCSV(e,t,n){const s=(n==null?void 0:n.precision)??3,c=t.some(h=>h.name),i=t.some(h=>h.port!=null),r=t.some(h=>h.stbd!=null),o=t.some(h=>h.arrRad!=null),a=t.some(h=>h.speed!=null),l=t.some((h,m)=>m>0&&h.gcToPrevious!=null),u=t.some(h=>h.rot!=null),g=t.some(h=>h.turnRad!=null),d=["// WPT No.","LAT","","","LON","",""];i&&d.push("PORT[NM]"),r&&d.push("STBD[NM]"),o&&d.push("Arr. Rad[NM]"),a&&d.push("Speed[kn]"),l&&d.push("Sail(RL/GC)"),u&&d.push("ROT[deg/min]"),g&&d.push("Turn Rad[NM]"),c&&d.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(d.join(","));for(let h=0;h<t.length;h++){const m=t[h],S=String(h).padStart(3,"0"),v=f.lat2pretty(m.lat,6),P=f.lng2pretty(m.lng,6),y=v.degree,N=Number(v.minute).toFixed(s),I=v.direction,B=P.degree,U=Number(P.minute).toFixed(s),R=P.direction,D=[S,String(y),N,I,String(B),U,R];i&&D.push(h===0?"***":m.port!=null?String(m.port):"***"),r&&D.push(h===0?"***":m.stbd!=null?String(m.stbd):"***"),o&&D.push(h===0?"***":m.arrRad!=null?String(m.arrRad):"***"),a&&D.push(h===0?"***":m.speed!=null?Number(m.speed).toFixed(1).padStart(5,"0"):"***"),l&&D.push(h===0?"***":m.gcToPrevious?"GC":"RL"),u&&D.push(h===0?"***":m.rot!=null?String(m.rot):"***"),g&&D.push(h===0?"***":m.turnRad!=null?String(m.turnRad):"***"),c&&D.push(m.name??""),p.push(D.join(","))}return p.join(`
7
- `)}static waypoints2XLSX(e,t,n){const s=(n==null?void 0:n.precision)??6,c=e||"Route",i=t.some(M=>M.name),r=t.some(M=>M.description),o=t.some(M=>M.port!=null),a=t.some(M=>M.stbd!=null),l=t.some(M=>M.arrRad!=null),u=t.some(M=>M.speed!=null),g=t.some((M,A)=>A>0&&M.gcToPrevious!=null),d=t.some(M=>M.bearing!=null),p=t.some(M=>M.distanceFromPrevious!=null),h=["WPT No.","Latitude","Longitude"];i&&h.push("Name"),r&&h.push("Description"),g&&h.push("Leg"),d&&h.push("Bearing[deg]"),p&&h.push("Distance[NM]"),u&&h.push("Speed[kn]"),o&&h.push("PORT XTD[NM]"),a&&h.push("STBD XTD[NM]"),l&&h.push("Arr.Rad[NM]");const m=M=>M==null?"":String(M).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");let v=`<row r="1">${h.map((M,A)=>`<c r="${V(A)}1" s="1" t="inlineStr"><is><t>${m(M)}</t></is></c>`).join("")}</row>`;for(let M=0;M<t.length;M++){const A=t[M],q=M+2,j=[],G=(z,X)=>j.push(`<c r="${V(z)}${q}"><v>${X}</v></c>`),W=(z,X)=>j.push(`<c r="${V(z)}${q}" t="inlineStr"><is><t>${m(X)}</t></is></c>`),F=(z,X)=>{X!=null?G(z,X):W(z,"")};G(0,M+1),W(1,f.lat2pretty(A.lat,s).pretty),W(2,f.lng2pretty(A.lng,s).pretty);let O=3;i&&(W(O,A.name??""),O++),r&&(W(O,A.description??""),O++),g&&(W(O,M===0?"":A.gcToPrevious?"GC":"RL"),O++),d&&(F(O,A.bearing),O++),p&&(F(O,A.distanceFromPrevious),O++),u&&(F(O,A.speed),O++),o&&(F(O,A.port),O++),a&&(F(O,A.stbd),O++),l&&(F(O,A.arrRad),O++),v+=`<row r="${q}">${j.join("")}</row>`}const P="0."+"0".repeat(s),y='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>'+v+"</sheetData></worksheet>",N='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>',I='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>',B='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="'+m(c)+'" sheetId="1" r:id="rId1"/></sheets></workbook>',U='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>',R='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><numFmts count="1"><numFmt numFmtId="164" formatCode="'+P+'"/></numFmts><fonts count="2"><font><sz val="11"/><name val="Arial"/></font><font><b/><sz val="11"/><name val="Arial"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="2"><border><left/><right/><top/><bottom/><diagonal/></border><border><bottom style="thin"><color auto="1"/></bottom></border></borders><cellStyleXfs count="1"><xf/></cellStyleXfs><cellXfs count="3"><xf/><xf fontId="1" fillId="0" borderId="1" applyFont="1" applyBorder="1"/><xf numFmtId="164" fontId="0" applyNumberFormat="1"/></cellXfs></styleSheet>',D=new TextEncoder;return te([{name:"[Content_Types].xml",data:D.encode(N)},{name:"_rels/.rels",data:D.encode(I)},{name:"xl/workbook.xml",data:D.encode(B)},{name:"xl/_rels/workbook.xml.rels",data:D.encode(U)},{name:"xl/worksheets/sheet1.xml",data:D.encode(y)},{name:"xl/styles.xml",data:D.encode(R)}])}static csvEscapeField(e){if(e==null)return"";const t=String(e);return t.includes(",")||t.includes('"')||t.includes(`
8
- `)||t.includes("\r")?`"${t.replace(/"/g,'""')}"`:t}static decimalToNmeaDm(e,t){const n=Math.abs(e),s=Math.floor(n),c=(n-s)*60,i=t?`${s.toString().padStart(2,"0")}${c.toFixed(2).padStart(5,"0")}`:`${s.toString().padStart(3,"0")}${c.toFixed(2).padStart(5,"0")}`,r=t?e>=0?"N":"S":e>=0?"E":"W";return{dm:i,dir:r}}static nmeaChecksum(e){let t=0;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n);return t.toString(16).toUpperCase().padStart(2,"0")}static waypoints2NMEA(e){const t=[];for(let n=0;n<e.length;n++){const s=e[n],c=b.decimalToNmeaDm(s.lat,!0),i=b.decimalToNmeaDm(s.lng,!1),r=s.name?String(s.name).slice(0,6):`WPT${(n+1).toString().padStart(3,"0")}`,o=`GPWPL,${c.dm},${c.dir},${i.dm},${i.dir},${r}`,a=b.nmeaChecksum(o);t.push(`$${o}*${a}`)}return t.join(`\r
9
- `)}static coordinatesSummary(e,t=3){if(e.length>1){const n=e[0],s=e[e.length-1],c=(n==null?void 0:n.positionTime)<(s==null?void 0:s.positionTime)?x.unix(n==null?void 0:n.positionTime):x.unix(s==null?void 0:s.positionTime),i=(n==null?void 0:n.positionTime)>(s==null?void 0:s.positionTime)?x.unix(n==null?void 0:n.positionTime):x.unix(s==null?void 0:s.positionTime),r=Math.round(i.diff(c,"hours",!0)*100)/100,o=this.generateRouteAccordingToWaypoints(e,!0,!0),a=this.calculateRouteDistance(o),u=K.inspectStoppages(e,t).reduce((d,p)=>(d.duration+=p.duration,d.distance+=p.distance,d),{hours:0,distance:0,spd:0,duration:0});u.hours=Math.round(u.duration/3600*100)/100,u.distance=Math.round(u.distance*100)/100,u.spd=u.hours?Math.round(u.distance/u.hours*100)/100:0;const g=r?Math.round((a-u.distance)/(r-u.hours)*100)/100:0;return{begin:c.utc().format(),end:i.utc().format(),distance:Math.round((a-u.distance)*100)/100,hours:Math.round((r-u.hours)*100)/100,avgSpeed:g,stoppage:u}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(e,t){var l,u,g;if(!((u=(l=t==null?void 0:t.sample)==null?void 0:l.hours)!=null&&u.length))return{routes:[],hour:void 0};const n=t.sample.hours.at(0),s=x.utc(e),c=x.utc(t.eta),i=s.isAfter(c)?c:s;let r=t.sample.all.find(d=>d.eta===i.format());if(!r){const d=t.sample.all.filter(N=>x.utc(N.eta).isBefore(i)).at(-1),p=this.calculateSubRoute(d,t.route);r=(g=this.calculateNextCoordinateAlongRoute(d,d.speed*i.diff(x(d.etd),"hours",!0),p))==null?void 0:g.coordinate;const{cFactor:h,cog:m,wxFactor:S,meteo:v}=d,P=Math.round(r.distanceFromPrevious*1e4)/1e4,y=Math.round((P+d.distanceFromStart)*1e4)/1e4;r={...r,cFactor:h,cog:m,speed:d.speed,wxFactor:S,distanceFromStart:y,distanceFromPrevious:P,meteo:v,eta:i.format(),etd:i.format()}}r.distanceToGo=Math.round((t.distance-r.distanceFromStart)*100)/100,r.timeToGo=Math.round(c.diff(r.etd,"hours",!0)*100)/100;const o=this.calculateRangeWaypoints(n,r,t.route);return{routes:this.generateRouteAccordingToWaypoints(o),hour:r}}static pickUTCSampleFromRoute(e,t,n){var d;const s=this.calculateSubRoute(t,n),c=this.calculateRouteDistance(s),i=c/t.speed,r=x.utc(e),o=x(t.etd),a=(d=this.calculateNextCoordinateAlongRoute(t,t.speed*r.diff(x(t.etd),"hours",!0),s))==null?void 0:d.coordinate;a.speed=t.speed;const l=o.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(l.diff(r,"second"))<2?r.format():l.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((c-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(o.clone().add(i,"hour").diff(x(a.etd),"hour")*100)/100;const u=this.calculateRangeWaypoints(t,a,n);return{routes:this.generateRouteAccordingToWaypoints(u),hour:a}}static includedAngle(e,t){L==null||L.debug("calculate bearing via: %j",{bearing:e,degree:t});let n=Math.abs(e%360-(t%360||0));return n=n>180?360-n:n,n}static async intersectInECA(e,t){var c,i;const s=(t instanceof Array?t:t.features).filter(r=>{var o,a;return((o=r.geometry)==null?void 0:o.type)==="Polygon"&&!((a=r.properties)!=null&&a.disabled)});if(e!=null&&e.length){let r=e;e.some(u=>u instanceof Array)?e=this.convertRouteToCoordinates(e):r=this.divideAccordingToLng(e);const o=r.map(u=>T.lineString(u)),a=[],l=s.map(u=>({polygon:u,bbox:T.bbox(u)}));for(const u of o){const g=u.geometry.coordinates,d=this.convertRouteToCoordinates([g]),p=T.bbox(u);for(const{polygon:h,bbox:m}of l){if(p[0]>m[2]||p[2]<m[0]||p[1]>m[3]||p[3]<m[1])continue;let S=[];const v=T.lineIntersect(u,h);(c=v==null?void 0:v.features)!=null&&c.length&&(S=T.getCoords(v.features).map(N=>{const I=T.getCoord(N);return{lng:I[0],lat:I[1]}}));const P=[...d];if(S.length>0)for(const y of S)this.mergeCoordinateToWaypoints(y,P,!0);for(let y=0;y<P.length-1;y++){const N=P[y],I=P[y+1],B=this.calculateRangeWaypoints(N,I,[],P),U=this.divideAccordingToLng(B);for(const R of U){const D=[Math.min(R[0][0],R[R.length-1][0]),Math.min(R[0][1],R[R.length-1][1]),Math.max(R[0][0],R[R.length-1][0]),Math.max(R[0][1],R[R.length-1][1])];if(D[0]>m[2]||D[2]<m[0]||D[1]>m[3]||D[3]<m[1])continue;const M=T.lineString(R);if(T.booleanContains(h,M)){const A=R.map(j=>({lng:j[0],lat:j[1]})),q=this.calculateRouteDistance([R]);a.push({distance:q,waypoints:A,eca:(i=h==null?void 0:h.properties)==null?void 0:i.name})}}}}}return a}return[]}}let k;try{k=J.getLogger("vessel")}catch{}finally{}class ne{static convert2Geojson(e){var n,s,c;const t=T.featureCollection([]);for(const i of e){const r=(n=i.history)==null?void 0:n[0];if(i.forecasts){r&&r.wind&&(r.wind.kts=r.kts);for(const o of i.forecasts){let a;const l=[],u=[],g=x(o.date).utc(),d=`${i.name}-${o.model}`;for(const h in o==null?void 0:o.hours){const m=o.hours[h];a=a||m;const S=g.clone().add(Number(h),"hour"),v=T.point([m.lng,m.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:S.format(),hour:Number(h),format:S.format("MMM-DD/HHmm[Z]"),pressure:m.pressure>1e4?f.roundPrecision(m.pressure/100,0):f.roundPrecision(m.pressure,0),gusts:m.gusts,wind:m.wind||{},movement:m.movement,category:d,type:"forecast"});u.push(v),l.push(v.geometry.coordinates)}const p={kts:void 0,deg:void 0};if(r){const h=x(r.updated).utc();if(a){const S=b.calculateDistance(r,a),v=x(a.utc||a.updated).diff(h,"h",!0);p.kts=Math.round(S/v*100)/100,p.deg=b.calculateBearing(r,a,!0,0)}const m=T.point([r.lng,r.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:h.format(),hour:0,format:h.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r.pressure,0),wind:r.wind,movement:p,category:d,type:"forecast",important:!0});u.unshift(m),l.unshift(m.geometry.coordinates)}if(t.features.push(...u),(l==null?void 0:l.length)>1){const h=T.lineString(f.convertToMonotonicLng2(l),{date:(r==null?void 0:r.updated)||(g==null?void 0:g.format()),id:i.id||i.name,model:o.model,name:i.name,category:d,type:"forecast",movement:p});t.features.push(h)}}}if(t.features.sort((o,a)=>o.properties.type==="forecast"&&a.properties.type==="forecast"&&o.geometry.type==="Point"&&a.geometry.type==="Point"?x(o.properties.date).valueOf()-x(a.properties.date).valueOf():0),(s=i.history)!=null&&s.length){const o=[],a=x(r==null?void 0:r.updated).utc(),l=x((c=i.history)==null?void 0:c.at(-1).updated).utc(),u=a.diff(l,"h")%24>2?24:12;for(const g of i.history){const d=x(g.updated).utc(),p=d.isSameOrBefore(a)||d.isSame(l);p&&a.add(-u,"h");const h=T.point([g.lng,g.lat],{name:i.name,nameCn:i.nameCn,date:d.format(),format:d.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?f.roundPrecision(g.pressure/100,0):f.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${i.name}-history`,wind:g.wind,movement:g.movement,important:p});t.features.push(h),o.push(h.geometry.coordinates)}if(o.length===1&&o.push(o[0]),o.length>1){const g=T.lineString(f.convertToMonotonicLng2(o),{name:i.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r==null?void 0:r.pressure,0),kts:r==null?void 0:r.kts,level:r==null?void 0:r.type});t.features.push(g)}}}return t}static interpolate(e,t=3){var c,i,r,o;const n=(c=e==null?void 0:e.data)==null?void 0:c.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const l=a.properties.name,u=a.properties.model,g=a.properties.showCircle,d=a.properties.disabled,p=x(a.properties.date).utc();let h=t*60;const m=(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===`${l}-${u}`);let S,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(m,v),S<=m.length-1;){if(S>0){const P=m[S],y=S===0?void 0:m[S-1],N=(h/60-((r=y==null?void 0:y.properties)==null?void 0:r.hour))/(P.properties.hour-((o=y==null?void 0:y.properties)==null?void 0:o.hour)),I=this.computeNumber(y==null?void 0:y.geometry.coordinates[0],P.geometry.coordinates[0],N),B=this.computeNumber(y==null?void 0:y.geometry.coordinates[1],P.geometry.coordinates[1],N),U=T.point([I,B],{name:l,model:u,category:P==null?void 0:P.properties.category,date:v.format(),format:v.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(y==null?void 0:y.properties.gusts,P.properties.gusts,N),hour:this.computeNumber(y==null?void 0:y.properties.hour,P.properties.hour,N),movement:this.computeNumber(y==null?void 0:y.properties.movement,P.properties.movement,N),pressure:this.computeNumber(y==null?void 0:y.properties.pressure,P.properties.pressure,N),wind:this.computeNumber(y==null?void 0:y.properties.wind,P.properties.wind,N),type:"forecast",disabled:d,showCircle:g});s.push(U)}h+=t*60,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(e,t){const{t1:n,t2:s,hr:c,hours:i}=this.tropicalCenterTwin(e,24,t);return{t1:n,t2:s,hr:c,hours:i}}static diversionPassageAt(e,t,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(t,24,s);if(c&&i){if(!s.debug){const p=b.calculateDistance(e,c),h=b.calculateDistance(e,i);if(p>2*n&&h>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,p,h,{from:e,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(e,c),l=b.calculateBearing(c,i),u=Math.abs(a-l);let g=0;u<180?g=u+90:u>=180&&(g=u-90);const d=b.calculateCoordinate(c,g,n);return k==null||k.info("[%s] the right tangent position: %j",s.requestId,{from:e,t1:c,t2:i,radius:n,bearing1:a,bearing2:l,right:d}),{at:d,t1:c,t2:i,hr:Number(r),hours:o}}return{}}static driftPassageAt(e,t,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(t,24,s);if(c&&i){if(!s.debug){const d=b.calculateDistance(e,c),p=b.calculateDistance(e,i);if(d>2*n&&p>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,d,p,{from:e,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(e,c),l=b.calculateBearing(c,i),u=b.calculateDistance(e,c);return{at:b.calculateCoordinate(c,a-l+180,n<u?n:u),t1:c,t2:i,hr:Number(r),hours:o}}else return k==null||k.info("[%s] no need drift: %j",s.requestId,{from:e,t1:c,t2:i,hr:r}),{}}static tropicalCenterTwin(e,t=24,n={}){var l,u,g,d,p;let s={};(l=e.forecasts)==null||l.forEach(h=>{s={...h.hours,...s}});const c=((u=e==null?void 0:e.history)==null?void 0:u[0])||(s==null?void 0:s[(g=Object.keys(s))==null?void 0:g[0]]);k==null||k.info("[%s] the first tropical center: %j",n.requestId,c);let i=(d=Object.keys(s||{}).filter(h=>Number(h)<=(t<0?24:t)))==null?void 0:d.at(-1);i||(i=(p=Object.keys(s||{}).filter(h=>Number(h)<=(t<0?24:2*t)))==null?void 0:p.at(-1));const r=s==null?void 0:s[i||-1];k==null||k.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const o=Object.keys(s||{}).filter(h=>Number(h)<=Number(i)),a={0:c};for(const h of o)a[h]=s[h];return{t1:c,t2:r,hr:Number(i),hours:a}}static pickIndex(e,t){let n=0;for(const s of e){if(x(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 c in e)s[c]=this.computeNumber(e[c],t[c],n);return s}return Math.round((e+(t-e)*n)*100)/100}else return e;else return t}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,e){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let $;try{$=J.getLogger("meteo")}catch{}finally{}function se(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:e}=new C("").window;return new e}class E{static toArrayBuffer(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}static drawCircle(e,t,n,s={}){const c=(s==null?void 0:s.steps)??64,i=(s==null?void 0:s.units)??"nauticalmiles",r=(s==null?void 0:s.properties)??{},o=T.point([e,t]),a=T.destination(o,n,90,{units:i}),l=x.utc();r.id=(s==null?void 0:s.id)||l.valueOf().toString();const u="circle";return r.name=(s==null?void 0:s.name)||`${u}_${l.format()}`,r.radius=n,r.center=[e,t],r.end=a.geometry.coordinates.map(g=>f.roundPrecision(g,9)),r.units=i,r.steps=c,r.shape="circle",$.info("[%s] draw circle with %j",s==null?void 0:s.requestId,r),T.circle(o,n,{steps:c,units:i,properties:r})}static drawRect(e,t,n={}){const s=(n==null?void 0:n.properties)??{},c=x.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="rect";s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.start=e.map(l=>f.roundPrecision(l,9)),s.end=t.map(l=>f.roundPrecision(l,9)),s.shape="rect",$.info("[%s] draw rect with %j",n==null?void 0:n.requestId,s);const[r,o]=f.convertToMonotonicLng2([e,t]),a=[Math.min(r[0],o[0]),Math.min(r[1],o[1]),Math.max(r[0],o[0]),Math.max(r[1],o[1])];return T.bboxPolygon(a,{properties:s})}static drawLine(e,t={}){const n=(t==null?void 0:t.properties)??{},s=x.utc();n.id=(t==null?void 0:t.id)||s.valueOf().toString();const c="line";n.name=(t==null?void 0:t.name)||`${c}_${s.format()}`,n.shape="line",$.info("[%s] draw line with %j",t==null?void 0:t.requestId,n);const i=f.convertToMonotonicLng2(e);return T.lineString(i,n)}static drawPolygon(e,t={}){const n=(t==null?void 0:t.properties)??{},s=x.utc();n.id=(t==null?void 0:t.id)||s.valueOf().toString();const c="polygon";n.name=(t==null?void 0:t.name)||`${c}_${s.format()}`,n.coordinates=e.map(r=>r.map(o=>f.roundPrecision(o,9))),n.shape="polygon",$.info("[%s] draw polygon with %j",t==null?void 0:t.requestId,n);const i=f.convertToMonotonicLng2(e);return T.polygon([i],n)}static drawPoint(e,t,n={}){const s=(n==null?void 0:n.properties)??{},c=x.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="point";return s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.shape="point",$.info("[%s] draw point with %j",n==null?void 0:n.requestId,s),T.point([t,e],s)}static parseCircle(e,t={}){var s,c;$.info("[%s] parse circle with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="circle"){const i=x.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const r=n==null?void 0:n.id,o=((s=n==null?void 0:n.center)==null?void 0:s.length)==2?T.point(n.center):T.centroid(e);let a="center";o.properties={id:`${a}_${r}`,parentId:r,name:a};const l=(n==null?void 0:n.units)||"nauticalmiles";let u=n==null?void 0:n.radius;if(!u){const p=T.polygonToLine(e);u=T.pointToLineDistance(o,p,{units:l})}a="end";const g=((c=n==null?void 0:n.end)==null?void 0:c.length)==2?T.point(n.end):T.destination(o,u,90,{units:l});g.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l};const d=T.lineString([o.geometry.coordinates,g.geometry.coordinates]);return a="edge",d.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l},T.featureCollection([o,g,d,e])}else return $.warn("[%s] not a orm-std circle, just return the original feature",t==null?void 0:t.requestId),T.featureCollection([e])}static parseRect(e,t={}){$.info("[%s] parse rect with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="rect"){const s=x.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,i=e.geometry.coordinates[0],o=["sw","nw","ne","se"].map((a,l)=>{const u=T.point(i[l]);return u.properties={id:`${a}_${c}`,parentId:c,name:a},u});return T.featureCollection([...o,e])}else return $.warn("[%s] not a orm-std rect, just return the original feature",t==null?void 0:t.requestId),T.featureCollection([e])}static parseLine(e,t={}){$.info("[%s] parse line with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="line"){const s=x.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=e.geometry.coordinates.map((o,a)=>{const l=`point_${a}`,u=T.point(o);return u.properties={id:`${l}_${c}`,parentId:c,name:l,index:a},u});return T.featureCollection([...r,e])}else return $.warn("[%s] not a orm-std line, just return the original feature",t==null?void 0:t.requestId),T.featureCollection([e])}static parsePolygon(e,t={}){$.info("[%s] parse polygon with %j",t==null?void 0:t.requestId,e.properties);const n=e.properties||{};if(n.shape=="polygon"){const s=x.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=e.geometry.coordinates[0].map((o,a)=>{const l=T.point(o),u=`corner_${a}`;return l.properties={id:`${u}_${c}`,parentId:c,name:u,index:a},l});return T.featureCollection([...r,e])}else return $.warn("[%s] not a orm-std polygon, just return the original feature",t==null?void 0:t.requestId),T.featureCollection([e])}static _inflateRawSync(e){var t;if(typeof process<"u"&&((t=process.versions)!=null&&t.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(e)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(e){var g;const t=new Uint8Array(e),n=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),s=new DataView(n),c=new Uint8Array(n),i=new Map;let r=-1;for(let d=n.byteLength-22;d>=0;d--)if(s.getUint32(d,!0)===101010256){r=d;break}if(r<0)throw new Error("Invalid ZIP file: EOCD not found");s.getUint16(r+8,!0);const o=s.getUint32(r+12,!0),a=s.getUint32(r+16,!0);let l=a;const u=a+o;for(;l<u;){if(s.getUint32(l,!0)!==33639248)throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);const p=s.getUint16(l+10,!0),h=s.getUint32(l+20,!0),m=s.getUint16(l+28,!0),S=s.getUint16(l+30,!0),v=s.getUint16(l+32,!0),P=s.getUint32(l+42,!0),y=c.slice(l+46,l+46+m),N=new TextDecoder().decode(y),I=s.getUint16(P+26,!0),B=s.getUint16(P+28,!0),U=P+30+I+B,R=c.slice(U,U+h);if(p===0)i.set(N,R);else if(p===8){if(typeof DecompressionStream<"u"){const D=new DecompressionStream("deflate-raw"),M=D.writable.getWriter(),A=D.readable.getReader();M.write(R),M.close();const q=[];let j=0;for(;;){const{done:F,value:O}=await A.read();if(F)break;q.push(O),j+=O.length}const G=new Uint8Array(j);let W=0;for(const F of q)G.set(F,W),W+=F.length;i.set(N,G)}else if(typeof process<"u"&&((g=process.versions)!=null&&g.node))try{i.set(N,E._inflateRawSync(R))}catch{}}l+=46+m+S+v}return i}static async convertKML2GeoJSON(e,t={}){var r,o;$.info("[%s] convert kml to geojson",t==null?void 0:t.requestId);const s=se().parseFromString(e,"application/xml"),c=Array.from(s.querySelectorAll("Placemark")),i=[];for(const a of c){const l={},u=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const y of u){const N=y.getAttribute("name"),I=(o=(r=y.querySelector("value"))==null?void 0:r.textContent)==null?void 0:o.trim();N&&I!==void 0&&I!==null&&(l[N]=I)}const g=x.utc(),d=Object.keys(l).find(y=>y.toLowerCase().indexOf("name")!==-1),p=d?l[d]:void 0,h=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,m=y=>y.trim().split(/[\s\n]+/).filter(N=>N.length>0).map(N=>{const I=N.split(",").map(Number);return[I[0],I[1]]}),S=a.querySelector("LineString > coordinates");if(S){const y=m(S.textContent||"");if(y.length>=2){const N=T.lineString(y,{...l,shape:"line",id:h,name:p});i.push(N)}continue}const v=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(v){const y=m(v.textContent||"");if(y.length>=4){const N=y[0][0]===y[y.length-1][0]&&y[0][1]===y[y.length-1][1]?y:[...y,y[0]],I=T.polygon([N],{...l,shape:"polygon",id:h,name:p});i.push(I)}continue}const P=a.querySelector("Point > coordinates");if(P){const y=m(P.textContent||"");if(y.length>=1){const N=T.point(y[0],{...l,shape:"point",id:h,name:p});i.push(N)}continue}}return T.featureCollection(i)}static async convertKMZ2GeoJSON(e,t={}){var i;$.info("[%s] convert kmz to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=E.toArrayBuffer(e));const n=await E._parseZipEntries(e),s=n.get("doc.kml")??((i=[...n.entries()].find(([r])=>r.toLowerCase().endsWith(".kml")))==null?void 0:i[1]);if(!s)return $.warn("[%s] no .kml file found in kmz",t==null?void 0:t.requestId),T.featureCollection([]);const c=new TextDecoder().decode(s);return E.convertKML2GeoJSON(c,t)}static async convertZIP2GeoJSON(e,t={}){$.info("[%s] convert zip to geojson (async)",t==null?void 0:t.requestId),typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=E.toArrayBuffer(e));const n=await E._parseZipEntries(e),s=[];for(const[c,i]of n){if(!c.toLowerCase().endsWith(".kml"))continue;const r=new TextDecoder().decode(i),o=await E.convertKML2GeoJSON(r,t);s.push(...o.features)}return s.length===0?($.warn("[%s] no .kml files found in zip",t==null?void 0:t.requestId),this.convertSHP2GeoJSON(e,t)):T.featureCollection(s)}static async convertSHP2GeoJSON(e,t={}){$.info("[%s] convert shp zip to geojson",t==null?void 0:t.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(e)&&(e=E.toArrayBuffer(e));const n=await Q(e);if(Array.isArray(n)){const s=n.flatMap(o=>o.features||[]),c=x.utc(),i=(t==null?void 0:t.id)||c.valueOf().toString(),r={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return s.forEach((o,a)=>{var p;const l=((p=o.geometry)==null?void 0:p.type)||"",u=r[l]||l.toLowerCase();o.properties=o.properties||{},o.properties.shape=u,o.properties.parentId=i,o.properties.id=`${i}_${a}`;const g=Object.keys(o.properties).find(h=>h.toLowerCase().indexOf("name")!==-1),d=g?o.properties[g]:void 0;o.properties.name=d||`${u}_${c.format()}_${a}`}),T.featureCollection(s)}return n}catch(n){return $.warn("[%s] failed to convert shp zip: %s",t==null?void 0:t.requestId,n),T.featureCollection([])}}}w.AisHelper=K,w.GeoJsonHelper=E,w.LaneHelper=b,w.LngLatHelper=f,w.TropicalHelper=ne,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
5
+ `}static toRTZWaypoints(t,e=6,n=!0){const s=[];s.push(" <waypoints>");for(let c=0;c<t.length;c++){const i=t[c],r=c+1,o=(i.lat??"").toFixed?i.lat.toFixed(e).padEnd(e+2,"0"):i.lat,a=(i.lng??"").toFixed?i.lng.toFixed(e).padEnd(e+2,"0"):i.lng,l=[`id="${r}"`,'revision="0"'];if(i.name&&l.push(`name="${b.xmlEscape(i.name)}"`),s.push(` <waypoint ${l.join(" ")}>`),s.push(` <position lat="${b.xmlEscape(o)}" lon="${b.xmlEscape(a)}" />`),c>0){const u=i.gcToPrevious?"Orthodrome":"Loxodrome";s.push(` <leg geometryType="${u}" />`)}if(n){const u=[];if(i.description&&u.push(` <description>${b.xmlEscape(i.description)}</description>`),i.utc)u.push(` <time>${b.xmlEscape(i.utc)}</time>`);else if(i.positionTime)try{u.push(` <time>${b.xmlEscape(P.unix(i.positionTime).utc().format())}</time>`)}catch{}i.cog!==void 0&&u.push(` <cog>${b.xmlEscape(i.cog)}</cog>`),i.sog!==void 0&&u.push(` <sog>${b.xmlEscape(i.sog)}</sog>`),u.length&&(s.push(" <extensions>"),s.push(...u),s.push(" </extensions>"))}s.push(" </waypoint>")}return s.push(" </waypoints>"),s}static waypoints2CSV(t,e,n){L.debug("keep name for waypoints2CSV for legacy compatibility only",t);const s=(n==null?void 0:n.precision)??6,c=e.some(m=>m.name),i=e.some(m=>m.description),r=e.some(m=>m.port!=null),o=e.some(m=>m.stbd!=null),a=e.some(m=>m.arrRad!=null),l=e.some(m=>m.speed!=null),u=e.some((m,S)=>S>0&&m.gcToPrevious!=null),g=e.some(m=>m.bearing!=null),d=e.some(m=>m.distanceFromPrevious!=null),p=["WPT No.","Latitude","Longitude"];c&&p.push("Name"),i&&p.push("Description"),u&&p.push("Leg"),g&&p.push("Bearing[deg]"),d&&p.push("Distance[NM]"),l&&p.push("Speed[kn]"),r&&p.push("PORT XTD[NM]"),o&&p.push("STBD XTD[NM]"),a&&p.push("Arr.Rad[NM]");const h=[];h.push(p.map(m=>b.csvEscapeField(m)).join(","));for(let m=0;m<e.length;m++){const S=e[m],v=[];v.push((m+1).toString()),v.push(S.lat.toFixed(s)),v.push(S.lng.toFixed(s)),c&&v.push(S.name??""),i&&v.push(S.description??""),u&&v.push(m===0?"":S.gcToPrevious?"GC":"RL"),g&&v.push(S.bearing!=null?String(S.bearing):""),d&&v.push(S.distanceFromPrevious!=null?String(S.distanceFromPrevious):""),l&&v.push(S.speed!=null?String(S.speed):""),r&&v.push(S.port!=null?String(S.port):""),o&&v.push(S.stbd!=null?String(S.stbd):""),a&&v.push(S.arrRad!=null?String(S.arrRad):""),h.push(v.map(x=>b.csvEscapeField(x)).join(","))}return h.join(`
6
+ `)}static waypoints2JRCCSV(t,e,n){const s=(n==null?void 0:n.precision)??3,c=e.some(h=>h.name),i=e.some(h=>h.port!=null),r=e.some(h=>h.stbd!=null),o=e.some(h=>h.arrRad!=null),a=e.some(h=>h.speed!=null),l=e.some((h,m)=>m>0&&h.gcToPrevious!=null),u=e.some(h=>h.rot!=null),g=e.some(h=>h.turnRad!=null),d=["// WPT No.","LAT","","","LON","",""];i&&d.push("PORT[NM]"),r&&d.push("STBD[NM]"),o&&d.push("Arr. Rad[NM]"),a&&d.push("Speed[kn]"),l&&d.push("Sail(RL/GC)"),u&&d.push("ROT[deg/min]"),g&&d.push("Turn Rad[NM]"),c&&d.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(t)}`),p.push(d.join(","));for(let h=0;h<e.length;h++){const m=e[h],S=String(h).padStart(3,"0"),v=f.lat2pretty(m.lat,6),x=f.lng2pretty(m.lng,6),y=v.degree,M=Number(v.minute).toFixed(s),D=v.direction,B=x.degree,U=Number(x.minute).toFixed(s),$=x.direction,R=[S,String(y),M,D,String(B),U,$];i&&R.push(h===0?"***":m.port!=null?String(m.port):"***"),r&&R.push(h===0?"***":m.stbd!=null?String(m.stbd):"***"),o&&R.push(h===0?"***":m.arrRad!=null?String(m.arrRad):"***"),a&&R.push(h===0?"***":m.speed!=null?Number(m.speed).toFixed(1).padStart(5,"0"):"***"),l&&R.push(h===0?"***":m.gcToPrevious?"GC":"RL"),u&&R.push(h===0?"***":m.rot!=null?String(m.rot):"***"),g&&R.push(h===0?"***":m.turnRad!=null?String(m.turnRad):"***"),c&&R.push(m.name??""),p.push(R.join(","))}return p.join(`
7
+ `)}static waypoints2XLSX(t,e,n){const s=(n==null?void 0:n.precision)??6,c=t||"Route",i=e.some(N=>N.name),r=e.some(N=>N.description),o=e.some(N=>N.port!=null),a=e.some(N=>N.stbd!=null),l=e.some(N=>N.arrRad!=null),u=e.some(N=>N.speed!=null),g=e.some((N,A)=>A>0&&N.gcToPrevious!=null),d=e.some(N=>N.bearing!=null),p=e.some(N=>N.distanceFromPrevious!=null),h=["WPT No.","Latitude","Longitude"];i&&h.push("Name"),r&&h.push("Description"),g&&h.push("Leg"),d&&h.push("Bearing[deg]"),p&&h.push("Distance[NM]"),u&&h.push("Speed[kn]"),o&&h.push("PORT XTD[NM]"),a&&h.push("STBD XTD[NM]"),l&&h.push("Arr.Rad[NM]");const m=N=>N==null?"":String(N).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");let v=`<row r="1">${h.map((N,A)=>`<c r="${J(A)}1" s="1" t="inlineStr"><is><t>${m(N)}</t></is></c>`).join("")}</row>`;for(let N=0;N<e.length;N++){const A=e[N],q=N+2,j=[],G=(z,X)=>j.push(`<c r="${J(z)}${q}"><v>${X}</v></c>`),W=(z,X)=>j.push(`<c r="${J(z)}${q}" t="inlineStr"><is><t>${m(X)}</t></is></c>`),F=(z,X)=>{X!=null?G(z,X):W(z,"")};G(0,N+1),W(1,f.lat2pretty(A.lat,s).pretty),W(2,f.lng2pretty(A.lng,s).pretty);let O=3;i&&(W(O,A.name??""),O++),r&&(W(O,A.description??""),O++),g&&(W(O,N===0?"":A.gcToPrevious?"GC":"RL"),O++),d&&(F(O,A.bearing),O++),p&&(F(O,A.distanceFromPrevious),O++),u&&(F(O,A.speed),O++),o&&(F(O,A.port),O++),a&&(F(O,A.stbd),O++),l&&(F(O,A.arrRad),O++),v+=`<row r="${q}">${j.join("")}</row>`}const x="0."+"0".repeat(s),y='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>'+v+"</sheetData></worksheet>",M='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>',D='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>',B='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="'+m(c)+'" sheetId="1" r:id="rId1"/></sheets></workbook>',U='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>',$='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><numFmts count="1"><numFmt numFmtId="164" formatCode="'+x+'"/></numFmts><fonts count="2"><font><sz val="11"/><name val="Arial"/></font><font><b/><sz val="11"/><name val="Arial"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="2"><border><left/><right/><top/><bottom/><diagonal/></border><border><bottom style="thin"><color auto="1"/></bottom></border></borders><cellStyleXfs count="1"><xf/></cellStyleXfs><cellXfs count="3"><xf/><xf fontId="1" fillId="0" borderId="1" applyFont="1" applyBorder="1"/><xf numFmtId="164" fontId="0" applyNumberFormat="1"/></cellXfs></styleSheet>',R=new TextEncoder;return et([{name:"[Content_Types].xml",data:R.encode(M)},{name:"_rels/.rels",data:R.encode(D)},{name:"xl/workbook.xml",data:R.encode(B)},{name:"xl/_rels/workbook.xml.rels",data:R.encode(U)},{name:"xl/worksheets/sheet1.xml",data:R.encode(y)},{name:"xl/styles.xml",data:R.encode($)}])}static csvEscapeField(t){if(t==null)return"";const e=String(t);return e.includes(",")||e.includes('"')||e.includes(`
8
+ `)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}static decimalToNmeaDm(t,e){const n=Math.abs(t),s=Math.floor(n),c=(n-s)*60,i=e?`${s.toString().padStart(2,"0")}${c.toFixed(2).padStart(5,"0")}`:`${s.toString().padStart(3,"0")}${c.toFixed(2).padStart(5,"0")}`,r=e?t>=0?"N":"S":t>=0?"E":"W";return{dm:i,dir:r}}static nmeaChecksum(t){let e=0;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n);return e.toString(16).toUpperCase().padStart(2,"0")}static waypoints2NMEA(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n],c=b.decimalToNmeaDm(s.lat,!0),i=b.decimalToNmeaDm(s.lng,!1),r=s.name?String(s.name).slice(0,6):`WPT${(n+1).toString().padStart(3,"0")}`,o=`GPWPL,${c.dm},${c.dir},${i.dm},${i.dir},${r}`,a=b.nmeaChecksum(o);e.push(`$${o}*${a}`)}return e.join(`\r
9
+ `)}static coordinatesSummary(t,e=3){if(t.length>1){const n=t[0],s=t[t.length-1],c=(n==null?void 0:n.positionTime)<(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),i=(n==null?void 0:n.positionTime)>(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),r=Math.round(i.diff(c,"hours",!0)*100)/100,o=this.generateRouteAccordingToWaypoints(t,!0,!0),a=this.calculateRouteDistance(o),u=K.inspectStoppages(t,e).reduce((d,p)=>(d.duration+=p.duration,d.distance+=p.distance,d),{hours:0,distance:0,spd:0,duration:0});u.hours=Math.round(u.duration/3600*100)/100,u.distance=Math.round(u.distance*100)/100,u.spd=u.hours?Math.round(u.distance/u.hours*100)/100:0;const g=r?Math.round((a-u.distance)/(r-u.hours)*100)/100:0;return{begin:c.utc().format(),end:i.utc().format(),distance:Math.round((a-u.distance)*100)/100,hours:Math.round((r-u.hours)*100)/100,avgSpeed:g,stoppage:u}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(t,e){var l,u,g;if(!((u=(l=e==null?void 0:e.sample)==null?void 0:l.hours)!=null&&u.length))return{routes:[],hour:void 0};const n=e.sample.hours.at(0),s=P.utc(t),c=P.utc(e.eta),i=s.isAfter(c)?c:s;let r=e.sample.all.find(d=>d.eta===i.format());if(!r){let d=e.sample.all.filter(y=>P.utc(y.eta).isBefore(i)).at(-1);if(d){const y=this.calculateSubRoute(d,e.route);r=(g=this.calculateNextCoordinateAlongRoute(d,d.speed*i.diff(P(d.etd),"hours",!0),y))==null?void 0:g.coordinate}else d=e.sample.all.at(0),r=d;const{cFactor:p,cog:h,wxFactor:m,meteo:S}=d,v=Math.round(r.distanceFromPrevious*1e4)/1e4,x=Math.round((v+d.distanceFromStart)*1e4)/1e4;r={...r,cFactor:p,cog:h,speed:d.speed,wxFactor:m,distanceFromStart:x,distanceFromPrevious:v,meteo:S,eta:i.format(),etd:i.format()}}r.distanceToGo=Math.round((e.distance-r.distanceFromStart)*100)/100,r.timeToGo=Math.round(c.diff(r.etd,"hours",!0)*100)/100;const o=this.calculateRangeWaypoints(n,r,e.route);return{routes:this.generateRouteAccordingToWaypoints(o),hour:r}}static pickUTCSampleFromRoute(t,e,n){var d;const s=this.calculateSubRoute(e,n),c=this.calculateRouteDistance(s),i=c/e.speed,r=P.utc(t),o=P(e.etd),a=(d=this.calculateNextCoordinateAlongRoute(e,e.speed*r.diff(P(e.etd),"hours",!0),s))==null?void 0:d.coordinate;a.speed=e.speed;const l=o.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(l.diff(r,"second"))<2?r.format():l.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((c-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(o.clone().add(i,"hour").diff(P(a.etd),"hour")*100)/100;const u=this.calculateRangeWaypoints(e,a,n);return{routes:this.generateRouteAccordingToWaypoints(u),hour:a}}static includedAngle(t,e){L==null||L.debug("calculate bearing via: %j",{bearing:t,degree:e});let n=Math.abs(t%360-(e%360||0));return n=n>180?360-n:n,n}static async intersectInECA(t,e){var c,i;const s=(e instanceof Array?e:e.features).filter(r=>{var o,a;return((o=r.geometry)==null?void 0:o.type)==="Polygon"&&!((a=r.properties)!=null&&a.disabled)});if(t!=null&&t.length){let r=t;t.some(u=>u instanceof Array)?t=this.convertRouteToCoordinates(t):r=this.divideAccordingToLng(t);const o=r.map(u=>T.lineString(u)),a=[],l=s.map(u=>({polygon:u,bbox:T.bbox(u)}));for(const u of o){const g=u.geometry.coordinates,d=this.convertRouteToCoordinates([g]),p=T.bbox(u);for(const{polygon:h,bbox:m}of l){if(p[0]>m[2]||p[2]<m[0]||p[1]>m[3]||p[3]<m[1])continue;let S=[];const v=T.lineIntersect(u,h);(c=v==null?void 0:v.features)!=null&&c.length&&(S=T.getCoords(v.features).map(M=>{const D=T.getCoord(M);return{lng:D[0],lat:D[1]}}));const x=[...d];if(S.length>0)for(const y of S)this.mergeCoordinateToWaypoints(y,x,!0);for(let y=0;y<x.length-1;y++){const M=x[y],D=x[y+1],B=this.calculateRangeWaypoints(M,D,[],x),U=this.divideAccordingToLng(B);for(const $ of U){const R=[Math.min($[0][0],$[$.length-1][0]),Math.min($[0][1],$[$.length-1][1]),Math.max($[0][0],$[$.length-1][0]),Math.max($[0][1],$[$.length-1][1])];if(R[0]>m[2]||R[2]<m[0]||R[1]>m[3]||R[3]<m[1])continue;const N=T.lineString($);if(T.booleanContains(h,N)){const A=$.map(j=>({lng:j[0],lat:j[1]})),q=this.calculateRouteDistance([$]);a.push({distance:q,waypoints:A,eca:(i=h==null?void 0:h.properties)==null?void 0:i.name})}}}}}return a}return[]}}let k;try{k=V.getLogger("vessel")}catch{}finally{}class nt{static convert2Geojson(t){var n,s,c;const e=T.featureCollection([]);for(const i of t){const r=(n=i.history)==null?void 0:n[0];if(i.forecasts){r&&r.wind&&(r.wind.kts=r.kts);for(const o of i.forecasts){let a;const l=[],u=[],g=P(o.date).utc(),d=`${i.name}-${o.model}`;for(const h in o==null?void 0:o.hours){const m=o.hours[h];a=a||m;const S=g.clone().add(Number(h),"hour"),v=T.point([m.lng,m.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:S.format(),hour:Number(h),format:S.format("MMM-DD/HHmm[Z]"),pressure:m.pressure>1e4?f.roundPrecision(m.pressure/100,0):f.roundPrecision(m.pressure,0),gusts:m.gusts,wind:m.wind||{},movement:m.movement,category:d,type:"forecast"});u.push(v),l.push(v.geometry.coordinates)}const p={kts:void 0,deg:void 0};if(r){const h=P(r.updated).utc();if(a){const S=b.calculateDistance(r,a),v=P(a.utc||a.updated).diff(h,"h",!0);p.kts=Math.round(S/v*100)/100,p.deg=b.calculateBearing(r,a,!0,0)}const m=T.point([r.lng,r.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:h.format(),hour:0,format:h.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r.pressure,0),wind:r.wind,movement:p,category:d,type:"forecast",important:!0});u.unshift(m),l.unshift(m.geometry.coordinates)}if(e.features.push(...u),(l==null?void 0:l.length)>1){const h=T.lineString(f.convertToMonotonicLng2(l),{date:(r==null?void 0:r.updated)||(g==null?void 0:g.format()),id:i.id||i.name,model:o.model,name:i.name,category:d,type:"forecast",movement:p});e.features.push(h)}}}if(e.features.sort((o,a)=>o.properties.type==="forecast"&&a.properties.type==="forecast"&&o.geometry.type==="Point"&&a.geometry.type==="Point"?P(o.properties.date).valueOf()-P(a.properties.date).valueOf():0),(s=i.history)!=null&&s.length){const o=[],a=P(r==null?void 0:r.updated).utc(),l=P((c=i.history)==null?void 0:c.at(-1).updated).utc(),u=a.diff(l,"h")%24>2?24:12;for(const g of i.history){const d=P(g.updated).utc(),p=d.isSameOrBefore(a)||d.isSame(l);p&&a.add(-u,"h");const h=T.point([g.lng,g.lat],{name:i.name,nameCn:i.nameCn,date:d.format(),format:d.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?f.roundPrecision(g.pressure/100,0):f.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${i.name}-history`,wind:g.wind,movement:g.movement,important:p});e.features.push(h),o.push(h.geometry.coordinates)}if(o.length===1&&o.push(o[0]),o.length>1){const g=T.lineString(f.convertToMonotonicLng2(o),{name:i.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r==null?void 0:r.pressure,0),kts:r==null?void 0:r.kts,level:r==null?void 0:r.type});e.features.push(g)}}}return e}static interpolate(t,e=3){var c,i,r,o;const n=(c=t==null?void 0:t.data)==null?void 0:c.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const l=a.properties.name,u=a.properties.model,g=a.properties.showCircle,d=a.properties.disabled,p=P(a.properties.date).utc();let h=e*60;const m=(i=t==null?void 0:t.data)==null?void 0:i.features.filter(x=>x.geometry.type==="Point"&&x.properties.type==="forecast"&&x.properties.category===`${l}-${u}`);let S,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(m,v),S<=m.length-1;){if(S>0){const x=m[S],y=S===0?void 0:m[S-1],M=(h/60-((r=y==null?void 0:y.properties)==null?void 0:r.hour))/(x.properties.hour-((o=y==null?void 0:y.properties)==null?void 0:o.hour)),D=this.computeNumber(y==null?void 0:y.geometry.coordinates[0],x.geometry.coordinates[0],M),B=this.computeNumber(y==null?void 0:y.geometry.coordinates[1],x.geometry.coordinates[1],M),U=T.point([D,B],{name:l,model:u,category:x==null?void 0:x.properties.category,date:v.format(),format:v.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(y==null?void 0:y.properties.gusts,x.properties.gusts,M),hour:this.computeNumber(y==null?void 0:y.properties.hour,x.properties.hour,M),movement:this.computeNumber(y==null?void 0:y.properties.movement,x.properties.movement,M),pressure:this.computeNumber(y==null?void 0:y.properties.pressure,x.properties.pressure,M),wind:this.computeNumber(y==null?void 0:y.properties.wind,x.properties.wind,M),type:"forecast",disabled:d,showCircle:g});s.push(U)}h+=e*60,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(t,e){const{t1:n,t2:s,hr:c,hours:i}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:s,hr:c,hours:i}}static diversionPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const p=b.calculateDistance(t,c),h=b.calculateDistance(t,i);if(p>2*n&&h>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,p,h,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=Math.abs(a-l);let g=0;u<180?g=u+90:u>=180&&(g=u-90);const d=b.calculateCoordinate(c,g,n);return k==null||k.info("[%s] the right tangent position: %j",s.requestId,{from:t,t1:c,t2:i,radius:n,bearing1:a,bearing2:l,right:d}),{at:d,t1:c,t2:i,hr:Number(r),hours:o}}return{}}static driftPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const d=b.calculateDistance(t,c),p=b.calculateDistance(t,i);if(d>2*n&&p>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,d,p,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=b.calculateDistance(t,c);return{at:b.calculateCoordinate(c,a-l+180,n<u?n:u),t1:c,t2:i,hr:Number(r),hours:o}}else return k==null||k.info("[%s] no need drift: %j",s.requestId,{from:t,t1:c,t2:i,hr:r}),{}}static tropicalCenterTwin(t,e=24,n={}){var l,u,g,d,p;let s={};(l=t.forecasts)==null||l.forEach(h=>{s={...h.hours,...s}});const c=((u=t==null?void 0:t.history)==null?void 0:u[0])||(s==null?void 0:s[(g=Object.keys(s))==null?void 0:g[0]]);k==null||k.info("[%s] the first tropical center: %j",n.requestId,c);let i=(d=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:e)))==null?void 0:d.at(-1);i||(i=(p=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:2*e)))==null?void 0:p.at(-1));const r=s==null?void 0:s[i||-1];k==null||k.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const o=Object.keys(s||{}).filter(h=>Number(h)<=Number(i)),a={0:c};for(const h of o)a[h]=s[h];return{t1:c,t2:r,hr:Number(i),hours:a}}static pickIndex(t,e){let n=0;for(const s of t){if(P(s.properties.date).isAfter(e))return n===0?-1:n;n++}return n}static computeNumber(t,e,n){if(t)if(e){if(isNaN(t)&&isNaN(e)&&typeof t!="string"&&typeof e!="string"){const s={};for(const c in t)s[c]=this.computeNumber(t[c],e[c],n);return s}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,t){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let I;try{I=V.getLogger("meteo")}catch{}finally{}function st(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:t}=new C("").window;return new t}class E{static toArrayBuffer(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}static drawCircle(t,e,n,s={}){const c=(s==null?void 0:s.steps)??64,i=(s==null?void 0:s.units)??"nauticalmiles",r=(s==null?void 0:s.properties)??{},o=T.point([t,e]),a=T.destination(o,n,90,{units:i}),l=P.utc();r.id=(s==null?void 0:s.id)||l.valueOf().toString();const u="circle";return r.name=(s==null?void 0:s.name)||`${u}_${l.format()}`,r.radius=n,r.center=[t,e],r.end=a.geometry.coordinates.map(g=>f.roundPrecision(g,9)),r.units=i,r.steps=c,r.shape="circle",I.info("[%s] draw circle with %j",s==null?void 0:s.requestId,r),T.circle(o,n,{steps:c,units:i,properties:r})}static drawRect(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="rect";s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.start=t.map(l=>f.roundPrecision(l,9)),s.end=e.map(l=>f.roundPrecision(l,9)),s.shape="rect",I.info("[%s] draw rect with %j",n==null?void 0:n.requestId,s);const[r,o]=f.convertToMonotonicLng2([t,e]),a=[Math.min(r[0],o[0]),Math.min(r[1],o[1]),Math.max(r[0],o[0]),Math.max(r[1],o[1])];return T.bboxPolygon(a,{properties:s})}static drawLine(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="line";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.shape="line",I.info("[%s] draw line with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.lineString(i,n)}static drawPolygon(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="polygon";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.coordinates=t.map(r=>r.map(o=>f.roundPrecision(o,9))),n.shape="polygon",I.info("[%s] draw polygon with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.polygon([i],n)}static drawPoint(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="point";return s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.shape="point",I.info("[%s] draw point with %j",n==null?void 0:n.requestId,s),T.point([e,t],s)}static parseCircle(t,e={}){var s,c;I.info("[%s] parse circle with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="circle"){const i=P.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const r=n==null?void 0:n.id,o=((s=n==null?void 0:n.center)==null?void 0:s.length)==2?T.point(n.center):T.centroid(t);let a="center";o.properties={id:`${a}_${r}`,parentId:r,name:a};const l=(n==null?void 0:n.units)||"nauticalmiles";let u=n==null?void 0:n.radius;if(!u){const p=T.polygonToLine(t);u=T.pointToLineDistance(o,p,{units:l})}a="end";const g=((c=n==null?void 0:n.end)==null?void 0:c.length)==2?T.point(n.end):T.destination(o,u,90,{units:l});g.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l};const d=T.lineString([o.geometry.coordinates,g.geometry.coordinates]);return a="edge",d.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l},T.featureCollection([o,g,d,t])}else return I.warn("[%s] not a orm-std circle, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseRect(t,e={}){I.info("[%s] parse rect with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="rect"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,i=t.geometry.coordinates[0],o=["sw","nw","ne","se"].map((a,l)=>{const u=T.point(i[l]);return u.properties={id:`${a}_${c}`,parentId:c,name:a},u});return T.featureCollection([...o,t])}else return I.warn("[%s] not a orm-std rect, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseLine(t,e={}){I.info("[%s] parse line with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="line"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates.map((o,a)=>{const l=`point_${a}`,u=T.point(o);return u.properties={id:`${l}_${c}`,parentId:c,name:l,index:a},u});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std line, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parsePolygon(t,e={}){I.info("[%s] parse polygon with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="polygon"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates[0].map((o,a)=>{const l=T.point(o),u=`corner_${a}`;return l.properties={id:`${u}_${c}`,parentId:c,name:u,index:a},l});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std polygon, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static _inflateRawSync(t){var e;if(typeof process<"u"&&((e=process.versions)!=null&&e.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(t)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(t){var g;const e=new Uint8Array(t),n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),s=new DataView(n),c=new Uint8Array(n),i=new Map;let r=-1;for(let d=n.byteLength-22;d>=0;d--)if(s.getUint32(d,!0)===101010256){r=d;break}if(r<0)throw new Error("Invalid ZIP file: EOCD not found");s.getUint16(r+8,!0);const o=s.getUint32(r+12,!0),a=s.getUint32(r+16,!0);let l=a;const u=a+o;for(;l<u;){if(s.getUint32(l,!0)!==33639248)throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);const p=s.getUint16(l+10,!0),h=s.getUint32(l+20,!0),m=s.getUint16(l+28,!0),S=s.getUint16(l+30,!0),v=s.getUint16(l+32,!0),x=s.getUint32(l+42,!0),y=c.slice(l+46,l+46+m),M=new TextDecoder().decode(y),D=s.getUint16(x+26,!0),B=s.getUint16(x+28,!0),U=x+30+D+B,$=c.slice(U,U+h);if(p===0)i.set(M,$);else if(p===8){if(typeof DecompressionStream<"u"){const R=new DecompressionStream("deflate-raw"),N=R.writable.getWriter(),A=R.readable.getReader();N.write($),N.close();const q=[];let j=0;for(;;){const{done:F,value:O}=await A.read();if(F)break;q.push(O),j+=O.length}const G=new Uint8Array(j);let W=0;for(const F of q)G.set(F,W),W+=F.length;i.set(M,G)}else if(typeof process<"u"&&((g=process.versions)!=null&&g.node))try{i.set(M,E._inflateRawSync($))}catch{}}l+=46+m+S+v}return i}static async convertKML2GeoJSON(t,e={}){var r,o;I.info("[%s] convert kml to geojson",e==null?void 0:e.requestId);const s=st().parseFromString(t,"application/xml"),c=Array.from(s.querySelectorAll("Placemark")),i=[];for(const a of c){const l={},u=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const y of u){const M=y.getAttribute("name"),D=(o=(r=y.querySelector("value"))==null?void 0:r.textContent)==null?void 0:o.trim();M&&D!==void 0&&D!==null&&(l[M]=D)}const g=P.utc(),d=Object.keys(l).find(y=>y.toLowerCase().indexOf("name")!==-1),p=d?l[d]:void 0,h=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,m=y=>y.trim().split(/[\s\n]+/).filter(M=>M.length>0).map(M=>{const D=M.split(",").map(Number);return[D[0],D[1]]}),S=a.querySelector("LineString > coordinates");if(S){const y=m(S.textContent||"");if(y.length>=2){const M=T.lineString(y,{...l,shape:"line",id:h,name:p});i.push(M)}continue}const v=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(v){const y=m(v.textContent||"");if(y.length>=4){const M=y[0][0]===y[y.length-1][0]&&y[0][1]===y[y.length-1][1]?y:[...y,y[0]],D=T.polygon([M],{...l,shape:"polygon",id:h,name:p});i.push(D)}continue}const x=a.querySelector("Point > coordinates");if(x){const y=m(x.textContent||"");if(y.length>=1){const M=T.point(y[0],{...l,shape:"point",id:h,name:p});i.push(M)}continue}}return T.featureCollection(i)}static async convertKMZ2GeoJSON(t,e={}){var i;I.info("[%s] convert kmz to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=n.get("doc.kml")??((i=[...n.entries()].find(([r])=>r.toLowerCase().endsWith(".kml")))==null?void 0:i[1]);if(!s)return I.warn("[%s] no .kml file found in kmz",e==null?void 0:e.requestId),T.featureCollection([]);const c=new TextDecoder().decode(s);return E.convertKML2GeoJSON(c,e)}static async convertZIP2GeoJSON(t,e={}){I.info("[%s] convert zip to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=[];for(const[c,i]of n){if(!c.toLowerCase().endsWith(".kml"))continue;const r=new TextDecoder().decode(i),o=await E.convertKML2GeoJSON(r,e);s.push(...o.features)}return s.length===0?(I.warn("[%s] no .kml files found in zip",e==null?void 0:e.requestId),this.convertSHP2GeoJSON(t,e)):T.featureCollection(s)}static async convertSHP2GeoJSON(t,e={}){I.info("[%s] convert shp zip to geojson",e==null?void 0:e.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await Q(t);if(Array.isArray(n)){const s=n.flatMap(o=>o.features||[]),c=P.utc(),i=(e==null?void 0:e.id)||c.valueOf().toString(),r={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return s.forEach((o,a)=>{var p;const l=((p=o.geometry)==null?void 0:p.type)||"",u=r[l]||l.toLowerCase();o.properties=o.properties||{},o.properties.shape=u,o.properties.parentId=i,o.properties.id=`${i}_${a}`;const g=Object.keys(o.properties).find(h=>h.toLowerCase().indexOf("name")!==-1),d=g?o.properties[g]:void 0;o.properties.name=d||`${u}_${c.format()}_${a}`}),T.featureCollection(s)}return n}catch(n){return I.warn("[%s] failed to convert shp zip: %s",e==null?void 0:e.requestId,n),T.featureCollection([])}}}w.AisHelper=K,w.GeoJsonHelper=E,w.LaneHelper=b,w.LngLatHelper=f,w.TropicalHelper=nt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
@@ -280,9 +280,9 @@ export declare class LaneHelper {
280
280
  */
281
281
  static simplifyRouteToCoordinates(route: number[][][], waypoints: Coordinate[], distance?: number): Coordinate[];
282
282
  /**
283
- * 基于大圆标识抽稀
284
- * @param coordinates
285
- * @param waypoints
283
+ * 基于大圆标识抽稀, 将 waypoints 中的 gcToPrevious 标记的点作为关键点,移除这些点之间的冗余点
284
+ * @param coordinates 航路点
285
+ * @param waypoints 关键航路点
286
286
  */
287
287
  static simplifyGCCoordinates(coordinates: Coordinate[], waypoints: Coordinate[]): Coordinate[];
288
288
  /**
@@ -312,14 +312,44 @@ export declare class LaneHelper {
312
312
  */
313
313
  static calculateBBox2(coords: Coordinate[]): turf.helpers.BBox;
314
314
  /**
315
- * 抽稀:基于三点夹角及距离移除冗余点
316
- * - 保留首尾点、重要标记点(important/pilot/suspend/velocity/gcToPrevious)
317
- * - 当三点夹角 >= minAngle 且相邻距离 <= minDistance 时,移除中间点
315
+ * 抽稀:基于 Ramer-Douglas-Peucker(RDP)横向偏差移除冗余点
316
+ * - 保留首尾点、重要标记点(important/pilot/suspend/velocity/gcToPrevious),并以其为分段锚点
317
+ * - 每个锚点段内,点相对首尾弦的横向偏差超过 epsilon 才保留,否则整段内部点一次性剔除
318
+ * - 抽稀后若指定 maxLeg,对超过 maxLeg 的腿在原始轨迹上均匀补点,保证航路点密度
319
+ * @param coordinates 原始坐标序列
320
+ * @param epsilon 最大允许横向偏差阈值(nm),默认 1
321
+ * @param maxLeg 最大允许腿长(nm),默认 0 不限制
322
+ */
323
+ static simplifyCoordinates(coordinates: Coordinate[], epsilon?: number, maxLeg?: number): Coordinate[];
324
+ /**
325
+ * RDP 主循环:首尾点与强制标记点作为锚点分段,段内迭代栈求最大横向偏差
326
+ * @param coordinates 原始坐标序列
327
+ * @param epsilon 最大允许横向偏差阈值(nm)
328
+ * @returns 升序保留点索引数组
329
+ */
330
+ private static rdpSimplify;
331
+ /**
332
+ * 最大腿长后处理:超过 maxLeg 的腿按腿内原始点累计里程均分为 ceil(leg/maxLeg) 段取点
318
333
  * @param coordinates 原始坐标序列
319
- * @param minDistance 最小保留距离阈值(nm),默认 0.1
320
- * @param minAngle 最小保留角度阈值(度),默认 175;>= 此值视为近似直线可抽稀
334
+ * @param keptIndices RDP 保留点索引(升序)
335
+ * @param maxLeg 最大允许腿长(nm)
336
+ * @returns 补点后的升序索引数组
337
+ */
338
+ private static splitLongLegs;
339
+ /**
340
+ * 经纬度转三维单位向量
341
+ * @param c 坐标 {lng, lat}
342
+ * @returns [x, y, z] 单位向量
343
+ */
344
+ private static toUnitVector;
345
+ /**
346
+ * 计算点 p 相对弦 start->end 的横向偏差(真实球面大圆偏差,天然兼容跨180°经线)
347
+ * @param p 待测点
348
+ * @param start 弦起点
349
+ * @param end 弦终点
350
+ * @returns {number} 单位 nm
321
351
  */
322
- static simplifyCoordinates(coordinates: Coordinate[], minDistance?: number, minAngle?: number): Coordinate[];
352
+ static perpendicularDeviation(p: Coordinate, start: Coordinate, end: Coordinate): number;
323
353
  /**
324
354
  * 在时间轨迹上寻找ts最近的点
325
355
  * @param ts ts最近的点(向后取), 单位秒
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "2.3.7",
4
+ "version": "2.3.9",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [