@idm-plugin/geo 2.3.6 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -933,7 +933,7 @@ class b {
933
933
  d = Math.max(-1, Math.min(1, d));
934
934
  const p = Math.acos(d) * (180 / Math.PI);
935
935
  if (p >= 180 || p >= n && g <= e) {
936
- X.warn("simplify: skip point %d (angle=%.1f°, dist=%.3fnm): %j", i, p, g, r);
936
+ X.warn("simplify: skip point %d (angle=%d°, dist=%d): %j", i, p, g, r);
937
937
  continue;
938
938
  }
939
939
  s.push(r), c = i;
@@ -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,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=%.1f°, dist=%.3fnm): %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,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(`
2
2
  `)+`
3
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(`
4
4
  `)+`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "2.3.6",
4
+ "version": "2.3.7",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [