@idm-plugin/geo 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ class h {
|
|
|
30
30
|
* @param format
|
|
31
31
|
*/
|
|
32
32
|
static lng2pretty(t, e = 6, n = "H°M′") {
|
|
33
|
-
t = h.convertToStdLng(t,
|
|
33
|
+
t = h.convertToStdLng(t, e);
|
|
34
34
|
let s = "E";
|
|
35
35
|
t < 0 && (s = "W"), t = Math.abs(t), n = n.toUpperCase();
|
|
36
36
|
let c = t * 3600, r = "", i = "", o = "";
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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,N,V,rt,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 h{static guessTimeZoneOffset(t,e){t=h.convertToStdLng(t);const n=Y(e,t),s=N().tz(n).utcOffset();return h.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=h.convertToStdLng(t,6);let s="E";t<0&&(s="W"),t=Math.abs(t),n=n.toUpperCase();let c=t*3600,r="",i="",o="";const a=c%3600%60;n.indexOf("S")!==-1&&(c=c-a,r=h.padNumber(a,2,1));const l=c/60%60;n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?i=h.roundPrecision(l,2).toString().padStart(2,"0"):i=h.padNumber(l,2,2),c=c-l*60);const u=c/3600;n.indexOf("M")!==-1?o=h.roundPrecision(u,e).toString().padStart(3,"0"):o=h.padNumber(u,3,6),Number(r)>=60&&(i=Number(i)+1,r=0),Number(i)>=60&&(o=Number(o)+1,i=0),o=o.toString(),i=h.padNumber(Number(i),2,Number.isInteger(Number(i))?0:2),r=h.padNumber(Number(r),2,Number.isInteger(Number(r))?0:1);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,i).replace(/H+/gi,o)}${s}`;return{direction:s,degree:h.roundPrecision(u,e),minute:h.roundPrecision(l,e),second:h.roundPrecision(a,e),pretty:g,S:r,M:i,H:o}}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,r="",i="",o="";const a=c%3600%60;n.indexOf("S")!==-1&&(c=c-a,r=h.padNumber(a,2,1));const l=c/60%60;n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?i=h.roundPrecision(l,2).toString().padStart(2,"0"):i=h.padNumber(l,2,2),c=c-l*60);const u=c/3600;n.indexOf("M")!==-1?o=h.roundPrecision(u,e).toString().padStart(2,"0"):o=h.padNumber(u,2,6),Number(r)>=60&&(i=Number(i)+1,r=0),Number(i)>=60&&(o=Number(o)+1,i=0),o=o.toString(),i=h.padNumber(Number(i),2,Number.isInteger(Number(i))?0:2),r=h.padNumber(Number(r),2,Number.isInteger(Number(r))?0:1);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,i).replace(/H+/gi,o)}${s}`;return{direction:s,degree:h.roundPrecision(u,e),minute:h.roundPrecision(l,e),second:h.roundPrecision(a,e),pretty:g,S:r,M:i,H:o}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=h.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[r,i,o]=c;if(i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,o=o||0,o=o>60?o/Math.pow(10,String(o).length-2):o,r>360&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}n=r+i/60+o/3600,s==="W"&&(n=n*-1)}else n=Number(t);return h.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=h.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[r,i,o]=c;if(o=o||0,i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,o=o>60?o/Math.pow(10,String(o).length-2):o,r>90&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}if(n=r+i/60+o/3600,n>90)throw new Error(`latitude out of range: ${t}${s}`);s==="S"&&(n=n*-1)}else n=Number(t);return h.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=h.strReplace(t,n);const s=t[t.length-1].toUpperCase();return["N","S"].includes(s)?{lat:h.str2Lat(t,e)}:{lng:h.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),h.roundPrecision(t,e)}static roundPrecision(t,e=6){const n=Number("1".padEnd(e+1,"0"));return Math.round(Number(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=void 0){n=n??2;const s=h.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,r,i,o,a,l,u,g]=t.split("|");return{lat:Number(e),lng:Number(n),positionTime:Number(s),sog:Number(c),cog:Number(r),hdg:Number(i),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 r,i;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(S.calculateDistance(g,u,!0,4)/(d/3600)<e)r||(r=a),l===t.length-1&&(i=g,o=l);else{r&&(i=t[l-1],o=l);break}}if((i==null?void 0:i.positionTime)>(r==null?void 0:r.positionTime)&&r){const l={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:N.unix(r.positionTime).utc().format()},end:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:N.unix(i.positionTime).utc().format()},duration:i.positionTime-r.positionTime},u=t.filter(d=>d.positionTime>=l.start.positionTime&&d.positionTime<=l.end.positionTime),g=S.divideAccordingToLng(u);l.distance=S.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))}r=void 0,i=void 0}}return s||t.sort((o,a)=>a.positionTime-o.positionTime),c}static inspectSummary(t,e,n){const s=N(e),c=N(n),r=t.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=c.unix());let i=0,o=0;if(r.length>1)for(let l=0;l<r.length-1;l++){const u=r[l],g=r[l+1];i+=S.calculateDistance(u,g,!0,4),o+=Math.abs(g.positionTime-u.positionTime)}i=Math.round(i*100)/100,o=Math.round(o/3600*100)/100;const a=o?Math.round(i/o*100)/100:0;return{distance:i,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),f=tt(d.data),m=new Uint8Array(30+p.length),b=new DataView(m.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(8,0,!0),b.setUint32(14,f,!0),b.setUint32(18,d.data.length,!0),b.setUint32(22,d.data.length,!0),b.setUint16(26,p.length,!0),m.set(p,30),e.push({nameBytes:p,data:d.data,crc:f,offset:s}),s+=m.length+d.data.length,n.push(m,d.data)}const c=s,r=[];let i=0;for(const d of e){const p=new Uint8Array(46+d.nameBytes.length),f=new DataView(p.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(10,0,!0),f.setUint32(16,d.crc,!0),f.setUint32(20,d.data.length,!0),f.setUint32(24,d.data.length,!0),f.setUint16(28,d.nameBytes.length,!0),f.setUint32(42,d.offset,!0),p.set(d.nameBytes,46),i+=p.length,r.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,i,!0),a.setUint32(16,c,!0);const l=n.reduce((d,p)=>d+p.length,0)+i+22,u=new Uint8Array(l);let g=0;for(const d of n)u.set(d,g),g+=d.length;for(const d of r)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 S{static calculateBearing(t,e,n=!0,s=4){const c=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let r;return n?r=T.rhumbBearing(c.features[0],c.features[1]):r=T.bearing(c.features[0],c.features[1]),r<0&&(r+=360),h.roundPrecision(r,s)}static calculateDistance(t,e,n=!0,s=4,c="nauticalmiles"){t={...t},e={...e},t.lng=h.convertToStdLng(t.lng,s),e.lng=h.convertToStdLng(e.lng,s);const r=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let i;return n?i=T.rhumbDistance(r.features[0],r.features[1],{units:c}):i=T.distance(r.features[0],r.features[1],{units:c}),h.roundPrecision(i,s)}static calculateRouteDistance(t,e=4,n="nauticalmiles"){let s=0,c;for(const r of t)for(let i=0;i<r.length-1;i++){const o={lng:r[i][0],lat:r[i][1]};i===0&&c&&(s+=this.calculateDistance(c,o,!0,e,n));const a={lng:r[i+1][0],lat:r[i+1][1]};s+=this.calculateDistance(o,a,!0,e,n),c=a}return h.roundPrecision(s,e)}static calculateCoordinate(t,e,n,s="nauticalmiles",c=!0){const r=T.point([t.lng,t.lat]);let i;c?i=T.rhumbDestination(r,n,e,{units:s}):i=T.destination(r,n,e,{units:s});const o=i.geometry.coordinates;return{lng:h.convertToStdLng(o[0],8),lat:h.roundPrecision(o[1],8)}}static interpolateCoordinates(t,e,n,s=!0,c=!0,r="nauticalmiles"){const i=[],o=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,r);s&&i.push({lng:t.lng,lat:t.lat});let l=0;for(;l<a;)l+=n,l<a&&i.push(this.calculateCoordinate(t,o,l,r,!1));return c&&i.push({lng:e.lng,lat:e.lat}),i}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 r,i;for(let o=0;o<t.length-1;o++){r=h.convertToStdLng(t[o].lng,8),i=h.convertToStdLng(t[o+1].lng,8),t[o].lat=h.roundPrecision(t[o].lat,8),t[o+1].lat=h.roundPrecision(t[o+1].lat,8),s.push([r,t[o].lat]);const a=r-i;if(Math.abs(a)>180){const l=h.convertToMonotonicLng2([[r,t[o].lat],[i,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 f=T.getCoord(d.features[0]);p=h.roundPrecision(f[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([i,t[o+1].lat])}return c.push(s),c}static deduplicateRoute(t){const e=[];for(const n of t){const s=n.reduce((c,r)=>(c.findIndex(i=>i[0]===r[0]&&i[1]===r[1])===-1&&c.push(r),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=h.convertToStdLng(t.lng,8);for(const n of e)for(let s=n.length-1;s>=0;s--)h.roundPrecision(n[s][0],8)===t.lng&&h.roundPrecision(n[s][1],8)===h.roundPrecision(t.lat,8)&&n.splice(s,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=h.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)h.roundPrecision(e[n].lng,8)===t.lng&&h.roundPrecision(e[n].lat,8)===h.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=h.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,s=0,c=0,r,i;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,r=this.calculateDistance(u,t),i=this.calculateDistance(g,t))}}),r!==0&&i!==0?e[s].splice(c+1,0,[t.lng,t.lat]):r===0?e[s].splice(c,1,[t.lng,t.lat]):i===0&&e[s].splice(c+1,1,[t.lng,t.lat]),e}static appendCoordinateToRoute(t,e){t.lng=h.convertToStdLng(t.lng,8);const n=S.convertRouteToCoordinates(e);return n.push(t),S.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=S.convertRouteToCoordinates(e);return n.unshift(t),S.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(r=>{if(c===2)return;const i=[];for(const o of r){if(h.roundPrecision(e.lng,8)===h.roundPrecision(o[0],8)&&h.roundPrecision(e.lat,8)===h.roundPrecision(o[1],8)){i.push(o),c===0&&i.push([t.lng,t.lat]),c=2;break}c===1?i.push(o):h.roundPrecision(t.lng,8)===h.roundPrecision(o[0],8)&&h.roundPrecision(t.lat,8)===h.roundPrecision(o[1],8)&&(c=1,i.push(o))}i.length&&s.push(i)}),s}static calculateRangeWaypoints(t,e,n,s=[]){const c=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([t,e],c.length?c:s),i=r.findIndex(l=>h.roundPrecision(t.lng,8)===h.roundPrecision(l.lng,8)&&h.roundPrecision(t.lat,8)===h.roundPrecision(l.lat,8)),o=r.findIndex(l=>h.roundPrecision(e.lng,8)===h.roundPrecision(l.lng,8)&&h.roundPrecision(e.lat,8)===h.roundPrecision(l.lat,8));return r.filter((l,u)=>u>=i&&u<=o)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,s=0,c=0;return e.forEach((r,i)=>{for(let o=0;o<r.length-1;o++){const a={lng:r[o][0],lat:r[o][1]},l={lng:r[o+1][0],lat:r[o+1][1]},u=this.calculatePointToLineDistance(t,a,l);n>u&&(n=u,s=o,c=i)}}),{minDist:n,segIndex:c,minIndex:s}}static calculateSubRoute(t,e){const n=S.convertRouteToCoordinates(e);S.mergeCoordinateToWaypoints(t,n,!0),e=S.divideAccordingToLng(n);const{segIndex:s,minIndex:c}=this.calculateMinDistanceToRoute({...t},e);t.lng=h.convertToStdLng(t.lng);const r=[];let i=!0;for(let o=s;o<e.length;o++)if(i){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]);r.push(a),i=!1}else r.push([...e[o]]);return r}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,s=0;for(let r=0;r<e.length-1;r++){const i=e[r],o=e[r+1];if(this.calculateDistance(t,i)===0)return e;if(this.calculateDistance(t,o)===0)return e.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(t,i,o);n>a&&(n=a,s=r)}t.lng=h.convertToStdLng(t.lng);const c=[t];for(let r=s+1;r<e.length;r++)c.push(e[r]);return c}static calculatePointToLineDistance(t,e,n,s={units:"nauticalmiles",method:"geodesic"}){t.lng=h.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=h.convertToStdLng(e.lng,8),n.lng=h.convertToStdLng(n.lng,8);const c=h.convertToMonotonicLng([e,n]);e=c[0],n=c[1];const r=T.lineString([[e.lng,e.lat],[n.lng,n.lat]]),i=T.pointToLineDistance(T.point([t.lng,t.lat]),r,s),o=T.pointToLineDistance(T.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),r,s);return h.roundPrecision(Math.min(i,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],r=this.calculateRangeRoute(s,c,e);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),c.distanceFromPrevious=this.calculateRouteDistance(r),c.distanceFromStart=h.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=h.convertToStdLng(t.lng,8);let s=Number.MAX_VALUE,c=0,r=0,i=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,r=this.calculateDistance(a,t,!1,6),i=this.calculateDistance(l,t,!1,6))}r!==0&&i!==0?r<=s&&c===0?e.unshift(t):i<=s&&c===e.length-2?e.push(t):e.splice(c+1,0,t):r===0?n?e.splice(c,1,t):e.splice(c+1,0,t):i===0&&(n?e.splice(c+1,1,t):e.splice(c+1,0,t))}return e.map((o,a)=>{o.lng=h.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=h.roundPrecision(u/g,2)}return o})}static generateRouteAccordingToWaypoints(t,e=!0,n=!0){const s=[];for(let c=1;c<t.length;c++){const r=t[c-1],i=t[c];if(c===1&&s.push(r),i.gcToPrevious){const o=this.interpolateCoordinates(r,i,200,!1,!0,"nauticalmiles");s.push(...o)}else s.push(i)}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]),r=T.lineString(c),i=T.nearestPointOnLine(r,n),o=T.getCoord(i);return{lng:h.roundPrecision(o[0],8),lat:h.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],r=e[s+1];if(this.calculateDistance(t,c)===0){n=s;break}if(this.calculateDistance(t,r)===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,r=[];let i=[],o=!1,a=0,l=0,u;if(e&&n.length?(r.push(t),n.forEach((d,p)=>{if(o)i.push(d);else{const f=[];let m;for(let b=0;b<d.length;b++)if(u)f.push(d[b]);else{m={lng:d[b][0],lat:d[b][1]};const v=this.calculateDistance(t,m,!0,8,s);if(a+=v,a<e)l+=v,v&&r.push(m),t=m;else{if(l=e,a===e)u=m,f.push([u.lng,u.lat]);else{const x=a-e,y=this.calculateBearing(m,t);u=this.calculateCoordinate(m,y,x,s),f.push([u.lng,u.lat]),f.push([m.lng,m.lat])}o=!0}}f.length&&i.push(f),p===n.length-1&&!u&&(u=m)}})):(i=n,u={...t}),u)if(r.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/c*1e4)/1e4,((g=i[0])==null?void 0:g.length)>1){const d={lng:i[0][1][0],lat:i[0][1][1]};u.bearing=this.calculateBearing(u,d)}else u.bearing=0;return{coordinate:u,nextRoute:i,prevRoute:r}}static nearestCoordinateInLine(t,e,n){const s=h.convertToStdLng(t.lng,6),c=T.point([s,t.lat]),r=h.convertToStdLng(e.lng,6),i=h.convertToStdLng(n.lng,6),o=T.lineString([[r,e.lat],[i,n.lat]]),a=T.nearestPointOnLine(o,c),l=T.getCoord(a),u=h.roundPrecision(l[0],6),g=h.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===r&&g===e.lat)&&!(u===i&&g===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let s,c;return t.forEach(r=>{r.forEach(i=>{const o={lng:h.roundPrecision(i[0],8),lat:h.roundPrecision(i[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],r=e[s];if(r.gcToPrevious){const i=t.findIndex(a=>a.lng===c.lng&&a.lat===c.lat),o=t.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=o-1;a>i;a--)t.splice(a,1)}}let n=0;for(let s=1;s<t.length;s++){const c=t[s-1],r=t[s];r.gcToPrevious?(c.bearing=this.calculateBearing(c,r,!1),r.distanceFromPrevious=this.calculateDistance(c,r,!1)):(c.bearing=this.calculateBearing(c,r,!0),r.distanceFromPrevious=this.calculateDistance(c,r,!0)),n=h.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return t.map(s=>(s.lng=h.convertToStdLng(s.lng),s))}static calculateCenter(t){const e=[];for(const i of t)for(const o of i)e.push(o);const n=T.featureCollection([]),s=h.convertToMonotonicLng2(e);for(const i of s)n.features.push(T.point(i));const r=T.center(n).geometry.coordinates;return{lng:h.convertToStdLng(r[0],8),lat:h.roundPrecision(r[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 r of c)e.push(r);const n=h.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=S.rdpSimplify(t,e),r=(n>0?S.splitLongLegs(t,s,n):s).map(i=>t[i]);return L.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)",t.length,r.length,e,n),r}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=>S.toUnitVector(o)),r=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],f=g[2]*d[0]-g[0]*d[2],m=g[0]*d[1]-g[1]*d[0];const b=Math.sqrt(p*p+f*f+m*m),v=b<1e-12;v||(p/=b,f/=b,m/=b);let x=0,y=-1;for(let P=l+1;P<u;P++){const D=v?S.calculateDistance(t[P],t[l]):Math.asin(Math.min(1,Math.abs(c[P][0]*p+c[P][1]*f+c[P][2]*m)))*r;D>x&&(x=D,y=P)}x>e&&(n[y]=!0,a.push([l,y],[y,u]))}}const i=[];for(let o=0;o<n.length;o++)n[o]&&i.push(o);return i}static splitLongLegs(t,e,n){const s=[e[0]];for(let c=1;c<e.length;c++){const r=s[s.length-1],i=e[c],o=S.calculateDistance(t[r],t[i]);if(o>n&&i-r>=2){const a=Math.ceil(o/n),l=[0];for(let u=r+1;u<=i;u++)l.push(l[l.length-1]+S.calculateDistance(t[u-1],t[u]));for(let u=1;u<a;u++){const g=o/a*u;let d=r+1;for(;d<i-1&&l[d-r]<g;)d++;d>r&&d<i&&s[s.length-1]!==d&&s.push(d)}}s.push(i)}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=S.toUnitVector(e),c=S.toUnitVector(n),r=S.toUnitVector(t);let i=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(i*i+o*o+a*a);if(l<1e-12)return S.calculateDistance(t,e);i/=l,o/=l,a/=l;const u=T.convertLength(1,"radians","nauticalmiles");return Math.asin(Math.min(1,Math.abs(r[0]*i+r[1]*o+r[2]*a)))*u}static nearestTSPointInWaypoints(t,e,n){const s=N.unix(t),c=n.filter(r=>s.clone().subtract(e,"hour").unix()<=(r.positionTime||0)&&s.clone().add(e,"h").unix()>=(r.positionTime||0));return c.sort((r,i)=>(r.positionTime||0)-(i.positionTime||0)),c.at(-1)}static deadReckoning(t,e){var c,r,i,o;t>1e12&&(t=Math.round(t/1e3));const n=N.unix(t);let s=e.find(a=>a.positionTime===n.unix());if(!s){const a=(r=(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:r.at(-1),l=(o=(i=e.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:i.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:o.at(0);if(a&&l){const u=S.calculateBearing(a,l,!0),g=S.calculateDistance(a,l),d=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=S.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=N.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=S.calculatePointToLineDistance(t,l,u);g<n&&(n=g,s=a)}const c=e[s],r=e[s+1],i=S.calculateDistance(c,t),o=S.calculateDistance(r,t);if(i===0)t=c;else if(o===0)t=r;else{const a=c.positionTime||0,l=r.positionTime||0,u=S.calculateDistance(c,r);t.positionTime=Math.round(a+(l-a)*(i/u))}return t.utc=t.positionTime?N.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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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="${S.xmlEscape(t)}"></routeInfo>`),s.push(...S.toRTZWaypoints(e,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,N,V,rt,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 h{static guessTimeZoneOffset(t,e){t=h.convertToStdLng(t);const n=Y(e,t),s=N().tz(n).utcOffset();return h.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=h.convertToStdLng(t,e);let s="E";t<0&&(s="W"),t=Math.abs(t),n=n.toUpperCase();let c=t*3600,r="",i="",o="";const a=c%3600%60;n.indexOf("S")!==-1&&(c=c-a,r=h.padNumber(a,2,1));const l=c/60%60;n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?i=h.roundPrecision(l,2).toString().padStart(2,"0"):i=h.padNumber(l,2,2),c=c-l*60);const u=c/3600;n.indexOf("M")!==-1?o=h.roundPrecision(u,e).toString().padStart(3,"0"):o=h.padNumber(u,3,6),Number(r)>=60&&(i=Number(i)+1,r=0),Number(i)>=60&&(o=Number(o)+1,i=0),o=o.toString(),i=h.padNumber(Number(i),2,Number.isInteger(Number(i))?0:2),r=h.padNumber(Number(r),2,Number.isInteger(Number(r))?0:1);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,i).replace(/H+/gi,o)}${s}`;return{direction:s,degree:h.roundPrecision(u,e),minute:h.roundPrecision(l,e),second:h.roundPrecision(a,e),pretty:g,S:r,M:i,H:o}}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,r="",i="",o="";const a=c%3600%60;n.indexOf("S")!==-1&&(c=c-a,r=h.padNumber(a,2,1));const l=c/60%60;n.indexOf("M")!==-1&&(n.indexOf("S")!==-1?i=h.roundPrecision(l,2).toString().padStart(2,"0"):i=h.padNumber(l,2,2),c=c-l*60);const u=c/3600;n.indexOf("M")!==-1?o=h.roundPrecision(u,e).toString().padStart(2,"0"):o=h.padNumber(u,2,6),Number(r)>=60&&(i=Number(i)+1,r=0),Number(i)>=60&&(o=Number(o)+1,i=0),o=o.toString(),i=h.padNumber(Number(i),2,Number.isInteger(Number(i))?0:2),r=h.padNumber(Number(r),2,Number.isInteger(Number(r))?0:1);const g=`${n.replace(/S+/gi,r).replace(/M+/gi,i).replace(/H+/gi,o)}${s}`;return{direction:s,degree:h.roundPrecision(u,e),minute:h.roundPrecision(l,e),second:h.roundPrecision(a,e),pretty:g,S:r,M:i,H:o}}static str2Lng(t,e=6){let n;if(isNaN(t)){t=h.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[r,i,o]=c;if(i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,o=o||0,o=o>60?o/Math.pow(10,String(o).length-2):o,r>360&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}n=r+i/60+o/3600,s==="W"&&(n=n*-1)}else n=Number(t);return h.convertToStdLng(n,e)}static str2Lat(t,e=6){let n;if(isNaN(t)){t=h.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[r,i,o]=c;if(o=o||0,i=i||0,i=i>60?i/Math.pow(10,String(i).length-2):i,o=o>60?o/Math.pow(10,String(o).length-2):o,r>90&&!i){const a=this.roundPrecision(r/100,0);i=r-a*100,r=a}if(n=r+i/60+o/3600,n>90)throw new Error(`latitude out of range: ${t}${s}`);s==="S"&&(n=n*-1)}else n=Number(t);return h.roundPrecision(n,e)}static str2LngOrLat(t,e=6,n="LAT"){t=h.strReplace(t,n);const s=t[t.length-1].toUpperCase();return["N","S"].includes(s)?{lat:h.str2Lat(t,e)}:{lng:h.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),h.roundPrecision(t,e)}static roundPrecision(t,e=6){const n=Number("1".padEnd(e+1,"0"));return Math.round(Number(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=void 0){n=n??2;const s=h.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,r,i,o,a,l,u,g]=t.split("|");return{lat:Number(e),lng:Number(n),positionTime:Number(s),sog:Number(c),cog:Number(r),hdg:Number(i),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 r,i;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(S.calculateDistance(g,u,!0,4)/(d/3600)<e)r||(r=a),l===t.length-1&&(i=g,o=l);else{r&&(i=t[l-1],o=l);break}}if((i==null?void 0:i.positionTime)>(r==null?void 0:r.positionTime)&&r){const l={start:{lat:r.lat,lng:r.lng,sog:r.sog,positionTime:r.positionTime,utc:N.unix(r.positionTime).utc().format()},end:{lat:i.lat,lng:i.lng,sog:i.sog,positionTime:i.positionTime,utc:N.unix(i.positionTime).utc().format()},duration:i.positionTime-r.positionTime},u=t.filter(d=>d.positionTime>=l.start.positionTime&&d.positionTime<=l.end.positionTime),g=S.divideAccordingToLng(u);l.distance=S.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))}r=void 0,i=void 0}}return s||t.sort((o,a)=>a.positionTime-o.positionTime),c}static inspectSummary(t,e,n){const s=N(e),c=N(n),r=t.filter(l=>l.positionTime>=s.unix()&&l.positionTime<=c.unix());let i=0,o=0;if(r.length>1)for(let l=0;l<r.length-1;l++){const u=r[l],g=r[l+1];i+=S.calculateDistance(u,g,!0,4),o+=Math.abs(g.positionTime-u.positionTime)}i=Math.round(i*100)/100,o=Math.round(o/3600*100)/100;const a=o?Math.round(i/o*100)/100:0;return{distance:i,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),f=tt(d.data),m=new Uint8Array(30+p.length),b=new DataView(m.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(8,0,!0),b.setUint32(14,f,!0),b.setUint32(18,d.data.length,!0),b.setUint32(22,d.data.length,!0),b.setUint16(26,p.length,!0),m.set(p,30),e.push({nameBytes:p,data:d.data,crc:f,offset:s}),s+=m.length+d.data.length,n.push(m,d.data)}const c=s,r=[];let i=0;for(const d of e){const p=new Uint8Array(46+d.nameBytes.length),f=new DataView(p.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(10,0,!0),f.setUint32(16,d.crc,!0),f.setUint32(20,d.data.length,!0),f.setUint32(24,d.data.length,!0),f.setUint16(28,d.nameBytes.length,!0),f.setUint32(42,d.offset,!0),p.set(d.nameBytes,46),i+=p.length,r.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,i,!0),a.setUint32(16,c,!0);const l=n.reduce((d,p)=>d+p.length,0)+i+22,u=new Uint8Array(l);let g=0;for(const d of n)u.set(d,g),g+=d.length;for(const d of r)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 S{static calculateBearing(t,e,n=!0,s=4){const c=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let r;return n?r=T.rhumbBearing(c.features[0],c.features[1]):r=T.bearing(c.features[0],c.features[1]),r<0&&(r+=360),h.roundPrecision(r,s)}static calculateDistance(t,e,n=!0,s=4,c="nauticalmiles"){t={...t},e={...e},t.lng=h.convertToStdLng(t.lng,s),e.lng=h.convertToStdLng(e.lng,s);const r=T.points([[t.lng,t.lat],[e.lng,e.lat]]);let i;return n?i=T.rhumbDistance(r.features[0],r.features[1],{units:c}):i=T.distance(r.features[0],r.features[1],{units:c}),h.roundPrecision(i,s)}static calculateRouteDistance(t,e=4,n="nauticalmiles"){let s=0,c;for(const r of t)for(let i=0;i<r.length-1;i++){const o={lng:r[i][0],lat:r[i][1]};i===0&&c&&(s+=this.calculateDistance(c,o,!0,e,n));const a={lng:r[i+1][0],lat:r[i+1][1]};s+=this.calculateDistance(o,a,!0,e,n),c=a}return h.roundPrecision(s,e)}static calculateCoordinate(t,e,n,s="nauticalmiles",c=!0){const r=T.point([t.lng,t.lat]);let i;c?i=T.rhumbDestination(r,n,e,{units:s}):i=T.destination(r,n,e,{units:s});const o=i.geometry.coordinates;return{lng:h.convertToStdLng(o[0],8),lat:h.roundPrecision(o[1],8)}}static interpolateCoordinates(t,e,n,s=!0,c=!0,r="nauticalmiles"){const i=[],o=this.calculateBearing(t,e,!1),a=this.calculateDistance(t,e,!1,8,r);s&&i.push({lng:t.lng,lat:t.lat});let l=0;for(;l<a;)l+=n,l<a&&i.push(this.calculateCoordinate(t,o,l,r,!1));return c&&i.push({lng:e.lng,lat:e.lat}),i}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 r,i;for(let o=0;o<t.length-1;o++){r=h.convertToStdLng(t[o].lng,8),i=h.convertToStdLng(t[o+1].lng,8),t[o].lat=h.roundPrecision(t[o].lat,8),t[o+1].lat=h.roundPrecision(t[o+1].lat,8),s.push([r,t[o].lat]);const a=r-i;if(Math.abs(a)>180){const l=h.convertToMonotonicLng2([[r,t[o].lat],[i,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 f=T.getCoord(d.features[0]);p=h.roundPrecision(f[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([i,t[o+1].lat])}return c.push(s),c}static deduplicateRoute(t){const e=[];for(const n of t){const s=n.reduce((c,r)=>(c.findIndex(i=>i[0]===r[0]&&i[1]===r[1])===-1&&c.push(r),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=h.convertToStdLng(t.lng,8);for(const n of e)for(let s=n.length-1;s>=0;s--)h.roundPrecision(n[s][0],8)===t.lng&&h.roundPrecision(n[s][1],8)===h.roundPrecision(t.lat,8)&&n.splice(s,1);return e}static removeCoordinateFromWaypoints(t,e){t.lng=h.convertToStdLng(t.lng,8);for(let n=e.length-1;n>=0;n--)h.roundPrecision(e[n].lng,8)===t.lng&&h.roundPrecision(e[n].lat,8)===h.roundPrecision(t.lat,8)&&e.splice(n,1);return e}static mergeCoordinateToRoute(t,e){t.lng=h.convertToStdLng(t.lng,8);let n=Number.MAX_VALUE,s=0,c=0,r,i;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,r=this.calculateDistance(u,t),i=this.calculateDistance(g,t))}}),r!==0&&i!==0?e[s].splice(c+1,0,[t.lng,t.lat]):r===0?e[s].splice(c,1,[t.lng,t.lat]):i===0&&e[s].splice(c+1,1,[t.lng,t.lat]),e}static appendCoordinateToRoute(t,e){t.lng=h.convertToStdLng(t.lng,8);const n=S.convertRouteToCoordinates(e);return n.push(t),S.divideAccordingToLng(n)}static unshiftCoordinateToRoute(t,e){const n=S.convertRouteToCoordinates(e);return n.unshift(t),S.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(r=>{if(c===2)return;const i=[];for(const o of r){if(h.roundPrecision(e.lng,8)===h.roundPrecision(o[0],8)&&h.roundPrecision(e.lat,8)===h.roundPrecision(o[1],8)){i.push(o),c===0&&i.push([t.lng,t.lat]),c=2;break}c===1?i.push(o):h.roundPrecision(t.lng,8)===h.roundPrecision(o[0],8)&&h.roundPrecision(t.lat,8)===h.roundPrecision(o[1],8)&&(c=1,i.push(o))}i.length&&s.push(i)}),s}static calculateRangeWaypoints(t,e,n,s=[]){const c=this.convertRouteToCoordinates(n,0),r=this.mergeCoordinatesToWaypoints([t,e],c.length?c:s),i=r.findIndex(l=>h.roundPrecision(t.lng,8)===h.roundPrecision(l.lng,8)&&h.roundPrecision(t.lat,8)===h.roundPrecision(l.lat,8)),o=r.findIndex(l=>h.roundPrecision(e.lng,8)===h.roundPrecision(l.lng,8)&&h.roundPrecision(e.lat,8)===h.roundPrecision(l.lat,8));return r.filter((l,u)=>u>=i&&u<=o)}static calculateMinDistanceToRoute(t,e){let n=Number.MAX_VALUE,s=0,c=0;return e.forEach((r,i)=>{for(let o=0;o<r.length-1;o++){const a={lng:r[o][0],lat:r[o][1]},l={lng:r[o+1][0],lat:r[o+1][1]},u=this.calculatePointToLineDistance(t,a,l);n>u&&(n=u,s=o,c=i)}}),{minDist:n,segIndex:c,minIndex:s}}static calculateSubRoute(t,e){const n=S.convertRouteToCoordinates(e);S.mergeCoordinateToWaypoints(t,n,!0),e=S.divideAccordingToLng(n);const{segIndex:s,minIndex:c}=this.calculateMinDistanceToRoute({...t},e);t.lng=h.convertToStdLng(t.lng);const r=[];let i=!0;for(let o=s;o<e.length;o++)if(i){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]);r.push(a),i=!1}else r.push([...e[o]]);return r}static calculateSubWaypoints(t,e){let n=Number.MAX_VALUE,s=0;for(let r=0;r<e.length-1;r++){const i=e[r],o=e[r+1];if(this.calculateDistance(t,i)===0)return e;if(this.calculateDistance(t,o)===0)return e.filter((l,u)=>u>0);const a=this.calculatePointToLineDistance(t,i,o);n>a&&(n=a,s=r)}t.lng=h.convertToStdLng(t.lng);const c=[t];for(let r=s+1;r<e.length;r++)c.push(e[r]);return c}static calculatePointToLineDistance(t,e,n,s={units:"nauticalmiles",method:"geodesic"}){t.lng=h.convertToStdLng(t.lng,8),e={...e},n={...n},e.lng=h.convertToStdLng(e.lng,8),n.lng=h.convertToStdLng(n.lng,8);const c=h.convertToMonotonicLng([e,n]);e=c[0],n=c[1];const r=T.lineString([[e.lng,e.lat],[n.lng,n.lat]]),i=T.pointToLineDistance(T.point([t.lng,t.lat]),r,s),o=T.pointToLineDistance(T.point([t.lng>0?t.lng-360:t.lng+360,t.lat]),r,s);return h.roundPrecision(Math.min(i,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],r=this.calculateRangeRoute(s,c,e);n===0&&(s.distanceFromPrevious=0,s.distanceFromStart=0),c.distanceFromPrevious=this.calculateRouteDistance(r),c.distanceFromStart=h.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=h.convertToStdLng(t.lng,8);let s=Number.MAX_VALUE,c=0,r=0,i=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,r=this.calculateDistance(a,t,!1,6),i=this.calculateDistance(l,t,!1,6))}r!==0&&i!==0?r<=s&&c===0?e.unshift(t):i<=s&&c===e.length-2?e.push(t):e.splice(c+1,0,t):r===0?n?e.splice(c,1,t):e.splice(c+1,0,t):i===0&&(n?e.splice(c+1,1,t):e.splice(c+1,0,t))}return e.map((o,a)=>{o.lng=h.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=h.roundPrecision(u/g,2)}return o})}static generateRouteAccordingToWaypoints(t,e=!0,n=!0){const s=[];for(let c=1;c<t.length;c++){const r=t[c-1],i=t[c];if(c===1&&s.push(r),i.gcToPrevious){const o=this.interpolateCoordinates(r,i,200,!1,!0,"nauticalmiles");s.push(...o)}else s.push(i)}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]),r=T.lineString(c),i=T.nearestPointOnLine(r,n),o=T.getCoord(i);return{lng:h.roundPrecision(o[0],8),lat:h.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],r=e[s+1];if(this.calculateDistance(t,c)===0){n=s;break}if(this.calculateDistance(t,r)===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,r=[];let i=[],o=!1,a=0,l=0,u;if(e&&n.length?(r.push(t),n.forEach((d,p)=>{if(o)i.push(d);else{const f=[];let m;for(let b=0;b<d.length;b++)if(u)f.push(d[b]);else{m={lng:d[b][0],lat:d[b][1]};const v=this.calculateDistance(t,m,!0,8,s);if(a+=v,a<e)l+=v,v&&r.push(m),t=m;else{if(l=e,a===e)u=m,f.push([u.lng,u.lat]);else{const x=a-e,y=this.calculateBearing(m,t);u=this.calculateCoordinate(m,y,x,s),f.push([u.lng,u.lat]),f.push([m.lng,m.lat])}o=!0}}f.length&&i.push(f),p===n.length-1&&!u&&(u=m)}})):(i=n,u={...t}),u)if(r.push(u),u.distanceFromPrevious=Math.round(l*1e4)/1e4,u.hourFromPrevious=Math.round(l/c*1e4)/1e4,((g=i[0])==null?void 0:g.length)>1){const d={lng:i[0][1][0],lat:i[0][1][1]};u.bearing=this.calculateBearing(u,d)}else u.bearing=0;return{coordinate:u,nextRoute:i,prevRoute:r}}static nearestCoordinateInLine(t,e,n){const s=h.convertToStdLng(t.lng,6),c=T.point([s,t.lat]),r=h.convertToStdLng(e.lng,6),i=h.convertToStdLng(n.lng,6),o=T.lineString([[r,e.lat],[i,n.lat]]),a=T.nearestPointOnLine(o,c),l=T.getCoord(a),u=h.roundPrecision(l[0],6),g=h.roundPrecision(l[1],6);return{lng:u,lat:g,inline:!(u===r&&g===e.lat)&&!(u===i&&g===n.lat)}}static convertRouteToCoordinates(t,e=0){const n=[];let s,c;return t.forEach(r=>{r.forEach(i=>{const o={lng:h.roundPrecision(i[0],8),lat:h.roundPrecision(i[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],r=e[s];if(r.gcToPrevious){const i=t.findIndex(a=>a.lng===c.lng&&a.lat===c.lat),o=t.findIndex(a=>a.lng===r.lng&&a.lat===r.lat);for(let a=o-1;a>i;a--)t.splice(a,1)}}let n=0;for(let s=1;s<t.length;s++){const c=t[s-1],r=t[s];r.gcToPrevious?(c.bearing=this.calculateBearing(c,r,!1),r.distanceFromPrevious=this.calculateDistance(c,r,!1)):(c.bearing=this.calculateBearing(c,r,!0),r.distanceFromPrevious=this.calculateDistance(c,r,!0)),n=h.roundPrecision(n+r.distanceFromPrevious),r.distanceFromStart=n}return t.map(s=>(s.lng=h.convertToStdLng(s.lng),s))}static calculateCenter(t){const e=[];for(const i of t)for(const o of i)e.push(o);const n=T.featureCollection([]),s=h.convertToMonotonicLng2(e);for(const i of s)n.features.push(T.point(i));const r=T.center(n).geometry.coordinates;return{lng:h.convertToStdLng(r[0],8),lat:h.roundPrecision(r[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 r of c)e.push(r);const n=h.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=S.rdpSimplify(t,e),r=(n>0?S.splitLongLegs(t,s,n):s).map(i=>t[i]);return L.info("simplify: %d -> %d points (epsilon=%dnm, maxLeg=%dnm)",t.length,r.length,e,n),r}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=>S.toUnitVector(o)),r=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],f=g[2]*d[0]-g[0]*d[2],m=g[0]*d[1]-g[1]*d[0];const b=Math.sqrt(p*p+f*f+m*m),v=b<1e-12;v||(p/=b,f/=b,m/=b);let x=0,y=-1;for(let P=l+1;P<u;P++){const D=v?S.calculateDistance(t[P],t[l]):Math.asin(Math.min(1,Math.abs(c[P][0]*p+c[P][1]*f+c[P][2]*m)))*r;D>x&&(x=D,y=P)}x>e&&(n[y]=!0,a.push([l,y],[y,u]))}}const i=[];for(let o=0;o<n.length;o++)n[o]&&i.push(o);return i}static splitLongLegs(t,e,n){const s=[e[0]];for(let c=1;c<e.length;c++){const r=s[s.length-1],i=e[c],o=S.calculateDistance(t[r],t[i]);if(o>n&&i-r>=2){const a=Math.ceil(o/n),l=[0];for(let u=r+1;u<=i;u++)l.push(l[l.length-1]+S.calculateDistance(t[u-1],t[u]));for(let u=1;u<a;u++){const g=o/a*u;let d=r+1;for(;d<i-1&&l[d-r]<g;)d++;d>r&&d<i&&s[s.length-1]!==d&&s.push(d)}}s.push(i)}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=S.toUnitVector(e),c=S.toUnitVector(n),r=S.toUnitVector(t);let i=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(i*i+o*o+a*a);if(l<1e-12)return S.calculateDistance(t,e);i/=l,o/=l,a/=l;const u=T.convertLength(1,"radians","nauticalmiles");return Math.asin(Math.min(1,Math.abs(r[0]*i+r[1]*o+r[2]*a)))*u}static nearestTSPointInWaypoints(t,e,n){const s=N.unix(t),c=n.filter(r=>s.clone().subtract(e,"hour").unix()<=(r.positionTime||0)&&s.clone().add(e,"h").unix()>=(r.positionTime||0));return c.sort((r,i)=>(r.positionTime||0)-(i.positionTime||0)),c.at(-1)}static deadReckoning(t,e){var c,r,i,o;t>1e12&&(t=Math.round(t/1e3));const n=N.unix(t);let s=e.find(a=>a.positionTime===n.unix());if(!s){const a=(r=(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:r.at(-1),l=(o=(i=e.filter(u=>(u==null?void 0:u.positionTime)>n.unix()))==null?void 0:i.sort((u,g)=>(u.positionTime||0)-(g.positionTime||0)))==null?void 0:o.at(0);if(a&&l){const u=S.calculateBearing(a,l,!0),g=S.calculateDistance(a,l),d=(n.unix()-a.positionTime)/(l.positionTime-a.positionTime);s=S.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=N.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=S.calculatePointToLineDistance(t,l,u);g<n&&(n=g,s=a)}const c=e[s],r=e[s+1],i=S.calculateDistance(c,t),o=S.calculateDistance(r,t);if(i===0)t=c;else if(o===0)t=r;else{const a=c.positionTime||0,l=r.positionTime||0,u=S.calculateDistance(c,r);t.positionTime=Math.round(a+(l-a)*(i/u))}return t.utc=t.positionTime?N.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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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="${S.xmlEscape(t)}"></routeInfo>`),s.push(...S.toRTZWaypoints(e,6)),s.push("</route>"),s.join(`
|
|
2
2
|
`)+`
|
|
3
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="${S.xmlEscape(t)}"></routeInfo>`),c.push(...S.toRTZWaypoints(e,6,n)),c.push("</route>"),c.join(`
|
|
4
4
|
`)+`
|