@idm-plugin/geo 2.3.8 → 2.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1311,18 +1311,22 @@ class v {
1311
1311
  const n = e.sample.hours.at(0), s = P.utc(t), c = P.utc(e.eta), i = s.isAfter(c) ? c : s;
1312
1312
  let r = e.sample.all.find((d) => d.eta === i.format());
1313
1313
  if (!r) {
1314
- const d = e.sample.all.filter((M) => P.utc(M.eta).isBefore(i)).at(-1), p = this.calculateSubRoute(d, e.route);
1315
- r = (g = this.calculateNextCoordinateAlongRoute(d, d.speed * i.diff(P(d.etd), "hours", !0), p)) == null ? void 0 : g.coordinate;
1316
- const { cFactor: h, cog: m, wxFactor: S, meteo: b } = d, x = Math.round(r.distanceFromPrevious * 1e4) / 1e4, y = Math.round((x + d.distanceFromStart) * 1e4) / 1e4;
1314
+ let d = e.sample.all.filter((y) => P.utc(y.eta).isBefore(i)).at(-1);
1315
+ if (d) {
1316
+ const y = this.calculateSubRoute(d, e.route);
1317
+ r = (g = this.calculateNextCoordinateAlongRoute(d, d.speed * i.diff(P(d.etd), "hours", !0), y)) == null ? void 0 : g.coordinate;
1318
+ } else
1319
+ d = e.sample.all.at(0), r = d;
1320
+ const { cFactor: p, cog: h, wxFactor: m, meteo: S } = d, b = Math.round(r.distanceFromPrevious * 1e4) / 1e4, x = Math.round((b + d.distanceFromStart) * 1e4) / 1e4;
1317
1321
  r = {
1318
1322
  ...r,
1319
- cFactor: h,
1320
- cog: m,
1323
+ cFactor: p,
1324
+ cog: h,
1321
1325
  speed: d.speed,
1322
- wxFactor: S,
1323
- distanceFromStart: y,
1324
- distanceFromPrevious: x,
1325
- meteo: b,
1326
+ wxFactor: m,
1327
+ distanceFromStart: x,
1328
+ distanceFromPrevious: b,
1329
+ meteo: S,
1326
1330
  eta: i.format(),
1327
1331
  etd: i.format()
1328
1332
  };
@@ -6,4 +6,4 @@
6
6
  `)}static waypoints2JRCCSV(t,e,n){const s=(n==null?void 0:n.precision)??3,c=e.some(h=>h.name),i=e.some(h=>h.port!=null),r=e.some(h=>h.stbd!=null),o=e.some(h=>h.arrRad!=null),a=e.some(h=>h.speed!=null),l=e.some((h,m)=>m>0&&h.gcToPrevious!=null),u=e.some(h=>h.rot!=null),g=e.some(h=>h.turnRad!=null),d=["// WPT No.","LAT","","","LON","",""];i&&d.push("PORT[NM]"),r&&d.push("STBD[NM]"),o&&d.push("Arr. Rad[NM]"),a&&d.push("Speed[kn]"),l&&d.push("Sail(RL/GC)"),u&&d.push("ROT[deg/min]"),g&&d.push("Turn Rad[NM]"),c&&d.push("Name");const p=[];p.push("// ROUTE SHEET exported by JRC ECDIS."),p.push("// <<NOTE>>This strings // indicate comment column/cells. You can edit freely."),p.push(`// ${b.xmlEscape(t)}`),p.push(d.join(","));for(let h=0;h<e.length;h++){const m=e[h],S=String(h).padStart(3,"0"),v=f.lat2pretty(m.lat,6),x=f.lng2pretty(m.lng,6),y=v.degree,M=Number(v.minute).toFixed(s),D=v.direction,B=x.degree,U=Number(x.minute).toFixed(s),$=x.direction,R=[S,String(y),M,D,String(B),U,$];i&&R.push(h===0?"***":m.port!=null?String(m.port):"***"),r&&R.push(h===0?"***":m.stbd!=null?String(m.stbd):"***"),o&&R.push(h===0?"***":m.arrRad!=null?String(m.arrRad):"***"),a&&R.push(h===0?"***":m.speed!=null?Number(m.speed).toFixed(1).padStart(5,"0"):"***"),l&&R.push(h===0?"***":m.gcToPrevious?"GC":"RL"),u&&R.push(h===0?"***":m.rot!=null?String(m.rot):"***"),g&&R.push(h===0?"***":m.turnRad!=null?String(m.turnRad):"***"),c&&R.push(m.name??""),p.push(R.join(","))}return p.join(`
7
7
  `)}static waypoints2XLSX(t,e,n){const s=(n==null?void 0:n.precision)??6,c=t||"Route",i=e.some(N=>N.name),r=e.some(N=>N.description),o=e.some(N=>N.port!=null),a=e.some(N=>N.stbd!=null),l=e.some(N=>N.arrRad!=null),u=e.some(N=>N.speed!=null),g=e.some((N,A)=>A>0&&N.gcToPrevious!=null),d=e.some(N=>N.bearing!=null),p=e.some(N=>N.distanceFromPrevious!=null),h=["WPT No.","Latitude","Longitude"];i&&h.push("Name"),r&&h.push("Description"),g&&h.push("Leg"),d&&h.push("Bearing[deg]"),p&&h.push("Distance[NM]"),u&&h.push("Speed[kn]"),o&&h.push("PORT XTD[NM]"),a&&h.push("STBD XTD[NM]"),l&&h.push("Arr.Rad[NM]");const m=N=>N==null?"":String(N).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");let v=`<row r="1">${h.map((N,A)=>`<c r="${J(A)}1" s="1" t="inlineStr"><is><t>${m(N)}</t></is></c>`).join("")}</row>`;for(let N=0;N<e.length;N++){const A=e[N],q=N+2,j=[],G=(z,X)=>j.push(`<c r="${J(z)}${q}"><v>${X}</v></c>`),W=(z,X)=>j.push(`<c r="${J(z)}${q}" t="inlineStr"><is><t>${m(X)}</t></is></c>`),F=(z,X)=>{X!=null?G(z,X):W(z,"")};G(0,N+1),W(1,f.lat2pretty(A.lat,s).pretty),W(2,f.lng2pretty(A.lng,s).pretty);let O=3;i&&(W(O,A.name??""),O++),r&&(W(O,A.description??""),O++),g&&(W(O,N===0?"":A.gcToPrevious?"GC":"RL"),O++),d&&(F(O,A.bearing),O++),p&&(F(O,A.distanceFromPrevious),O++),u&&(F(O,A.speed),O++),o&&(F(O,A.port),O++),a&&(F(O,A.stbd),O++),l&&(F(O,A.arrRad),O++),v+=`<row r="${q}">${j.join("")}</row>`}const x="0."+"0".repeat(s),y='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>'+v+"</sheetData></worksheet>",M='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>',D='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>',B='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="'+m(c)+'" sheetId="1" r:id="rId1"/></sheets></workbook>',U='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>',$='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><numFmts count="1"><numFmt numFmtId="164" formatCode="'+x+'"/></numFmts><fonts count="2"><font><sz val="11"/><name val="Arial"/></font><font><b/><sz val="11"/><name val="Arial"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="2"><border><left/><right/><top/><bottom/><diagonal/></border><border><bottom style="thin"><color auto="1"/></bottom></border></borders><cellStyleXfs count="1"><xf/></cellStyleXfs><cellXfs count="3"><xf/><xf fontId="1" fillId="0" borderId="1" applyFont="1" applyBorder="1"/><xf numFmtId="164" fontId="0" applyNumberFormat="1"/></cellXfs></styleSheet>',R=new TextEncoder;return et([{name:"[Content_Types].xml",data:R.encode(M)},{name:"_rels/.rels",data:R.encode(D)},{name:"xl/workbook.xml",data:R.encode(B)},{name:"xl/_rels/workbook.xml.rels",data:R.encode(U)},{name:"xl/worksheets/sheet1.xml",data:R.encode(y)},{name:"xl/styles.xml",data:R.encode($)}])}static csvEscapeField(t){if(t==null)return"";const e=String(t);return e.includes(",")||e.includes('"')||e.includes(`
8
8
  `)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}static decimalToNmeaDm(t,e){const n=Math.abs(t),s=Math.floor(n),c=(n-s)*60,i=e?`${s.toString().padStart(2,"0")}${c.toFixed(2).padStart(5,"0")}`:`${s.toString().padStart(3,"0")}${c.toFixed(2).padStart(5,"0")}`,r=e?t>=0?"N":"S":t>=0?"E":"W";return{dm:i,dir:r}}static nmeaChecksum(t){let e=0;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n);return e.toString(16).toUpperCase().padStart(2,"0")}static waypoints2NMEA(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n],c=b.decimalToNmeaDm(s.lat,!0),i=b.decimalToNmeaDm(s.lng,!1),r=s.name?String(s.name).slice(0,6):`WPT${(n+1).toString().padStart(3,"0")}`,o=`GPWPL,${c.dm},${c.dir},${i.dm},${i.dir},${r}`,a=b.nmeaChecksum(o);e.push(`$${o}*${a}`)}return e.join(`\r
9
- `)}static coordinatesSummary(t,e=3){if(t.length>1){const n=t[0],s=t[t.length-1],c=(n==null?void 0:n.positionTime)<(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),i=(n==null?void 0:n.positionTime)>(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),r=Math.round(i.diff(c,"hours",!0)*100)/100,o=this.generateRouteAccordingToWaypoints(t,!0,!0),a=this.calculateRouteDistance(o),u=K.inspectStoppages(t,e).reduce((d,p)=>(d.duration+=p.duration,d.distance+=p.distance,d),{hours:0,distance:0,spd:0,duration:0});u.hours=Math.round(u.duration/3600*100)/100,u.distance=Math.round(u.distance*100)/100,u.spd=u.hours?Math.round(u.distance/u.hours*100)/100:0;const g=r?Math.round((a-u.distance)/(r-u.hours)*100)/100:0;return{begin:c.utc().format(),end:i.utc().format(),distance:Math.round((a-u.distance)*100)/100,hours:Math.round((r-u.hours)*100)/100,avgSpeed:g,stoppage:u}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(t,e){var l,u,g;if(!((u=(l=e==null?void 0:e.sample)==null?void 0:l.hours)!=null&&u.length))return{routes:[],hour:void 0};const n=e.sample.hours.at(0),s=P.utc(t),c=P.utc(e.eta),i=s.isAfter(c)?c:s;let r=e.sample.all.find(d=>d.eta===i.format());if(!r){const d=e.sample.all.filter(M=>P.utc(M.eta).isBefore(i)).at(-1),p=this.calculateSubRoute(d,e.route);r=(g=this.calculateNextCoordinateAlongRoute(d,d.speed*i.diff(P(d.etd),"hours",!0),p))==null?void 0:g.coordinate;const{cFactor:h,cog:m,wxFactor:S,meteo:v}=d,x=Math.round(r.distanceFromPrevious*1e4)/1e4,y=Math.round((x+d.distanceFromStart)*1e4)/1e4;r={...r,cFactor:h,cog:m,speed:d.speed,wxFactor:S,distanceFromStart:y,distanceFromPrevious:x,meteo:v,eta:i.format(),etd:i.format()}}r.distanceToGo=Math.round((e.distance-r.distanceFromStart)*100)/100,r.timeToGo=Math.round(c.diff(r.etd,"hours",!0)*100)/100;const o=this.calculateRangeWaypoints(n,r,e.route);return{routes:this.generateRouteAccordingToWaypoints(o),hour:r}}static pickUTCSampleFromRoute(t,e,n){var d;const s=this.calculateSubRoute(e,n),c=this.calculateRouteDistance(s),i=c/e.speed,r=P.utc(t),o=P(e.etd),a=(d=this.calculateNextCoordinateAlongRoute(e,e.speed*r.diff(P(e.etd),"hours",!0),s))==null?void 0:d.coordinate;a.speed=e.speed;const l=o.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(l.diff(r,"second"))<2?r.format():l.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((c-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(o.clone().add(i,"hour").diff(P(a.etd),"hour")*100)/100;const u=this.calculateRangeWaypoints(e,a,n);return{routes:this.generateRouteAccordingToWaypoints(u),hour:a}}static includedAngle(t,e){L==null||L.debug("calculate bearing via: %j",{bearing:t,degree:e});let n=Math.abs(t%360-(e%360||0));return n=n>180?360-n:n,n}static async intersectInECA(t,e){var c,i;const s=(e instanceof Array?e:e.features).filter(r=>{var o,a;return((o=r.geometry)==null?void 0:o.type)==="Polygon"&&!((a=r.properties)!=null&&a.disabled)});if(t!=null&&t.length){let r=t;t.some(u=>u instanceof Array)?t=this.convertRouteToCoordinates(t):r=this.divideAccordingToLng(t);const o=r.map(u=>T.lineString(u)),a=[],l=s.map(u=>({polygon:u,bbox:T.bbox(u)}));for(const u of o){const g=u.geometry.coordinates,d=this.convertRouteToCoordinates([g]),p=T.bbox(u);for(const{polygon:h,bbox:m}of l){if(p[0]>m[2]||p[2]<m[0]||p[1]>m[3]||p[3]<m[1])continue;let S=[];const v=T.lineIntersect(u,h);(c=v==null?void 0:v.features)!=null&&c.length&&(S=T.getCoords(v.features).map(M=>{const D=T.getCoord(M);return{lng:D[0],lat:D[1]}}));const x=[...d];if(S.length>0)for(const y of S)this.mergeCoordinateToWaypoints(y,x,!0);for(let y=0;y<x.length-1;y++){const M=x[y],D=x[y+1],B=this.calculateRangeWaypoints(M,D,[],x),U=this.divideAccordingToLng(B);for(const $ of U){const R=[Math.min($[0][0],$[$.length-1][0]),Math.min($[0][1],$[$.length-1][1]),Math.max($[0][0],$[$.length-1][0]),Math.max($[0][1],$[$.length-1][1])];if(R[0]>m[2]||R[2]<m[0]||R[1]>m[3]||R[3]<m[1])continue;const N=T.lineString($);if(T.booleanContains(h,N)){const A=$.map(j=>({lng:j[0],lat:j[1]})),q=this.calculateRouteDistance([$]);a.push({distance:q,waypoints:A,eca:(i=h==null?void 0:h.properties)==null?void 0:i.name})}}}}}return a}return[]}}let k;try{k=V.getLogger("vessel")}catch{}finally{}class nt{static convert2Geojson(t){var n,s,c;const e=T.featureCollection([]);for(const i of t){const r=(n=i.history)==null?void 0:n[0];if(i.forecasts){r&&r.wind&&(r.wind.kts=r.kts);for(const o of i.forecasts){let a;const l=[],u=[],g=P(o.date).utc(),d=`${i.name}-${o.model}`;for(const h in o==null?void 0:o.hours){const m=o.hours[h];a=a||m;const S=g.clone().add(Number(h),"hour"),v=T.point([m.lng,m.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:S.format(),hour:Number(h),format:S.format("MMM-DD/HHmm[Z]"),pressure:m.pressure>1e4?f.roundPrecision(m.pressure/100,0):f.roundPrecision(m.pressure,0),gusts:m.gusts,wind:m.wind||{},movement:m.movement,category:d,type:"forecast"});u.push(v),l.push(v.geometry.coordinates)}const p={kts:void 0,deg:void 0};if(r){const h=P(r.updated).utc();if(a){const S=b.calculateDistance(r,a),v=P(a.utc||a.updated).diff(h,"h",!0);p.kts=Math.round(S/v*100)/100,p.deg=b.calculateBearing(r,a,!0,0)}const m=T.point([r.lng,r.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:h.format(),hour:0,format:h.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r.pressure,0),wind:r.wind,movement:p,category:d,type:"forecast",important:!0});u.unshift(m),l.unshift(m.geometry.coordinates)}if(e.features.push(...u),(l==null?void 0:l.length)>1){const h=T.lineString(f.convertToMonotonicLng2(l),{date:(r==null?void 0:r.updated)||(g==null?void 0:g.format()),id:i.id||i.name,model:o.model,name:i.name,category:d,type:"forecast",movement:p});e.features.push(h)}}}if(e.features.sort((o,a)=>o.properties.type==="forecast"&&a.properties.type==="forecast"&&o.geometry.type==="Point"&&a.geometry.type==="Point"?P(o.properties.date).valueOf()-P(a.properties.date).valueOf():0),(s=i.history)!=null&&s.length){const o=[],a=P(r==null?void 0:r.updated).utc(),l=P((c=i.history)==null?void 0:c.at(-1).updated).utc(),u=a.diff(l,"h")%24>2?24:12;for(const g of i.history){const d=P(g.updated).utc(),p=d.isSameOrBefore(a)||d.isSame(l);p&&a.add(-u,"h");const h=T.point([g.lng,g.lat],{name:i.name,nameCn:i.nameCn,date:d.format(),format:d.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?f.roundPrecision(g.pressure/100,0):f.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${i.name}-history`,wind:g.wind,movement:g.movement,important:p});e.features.push(h),o.push(h.geometry.coordinates)}if(o.length===1&&o.push(o[0]),o.length>1){const g=T.lineString(f.convertToMonotonicLng2(o),{name:i.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r==null?void 0:r.pressure,0),kts:r==null?void 0:r.kts,level:r==null?void 0:r.type});e.features.push(g)}}}return e}static interpolate(t,e=3){var c,i,r,o;const n=(c=t==null?void 0:t.data)==null?void 0:c.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const l=a.properties.name,u=a.properties.model,g=a.properties.showCircle,d=a.properties.disabled,p=P(a.properties.date).utc();let h=e*60;const m=(i=t==null?void 0:t.data)==null?void 0:i.features.filter(x=>x.geometry.type==="Point"&&x.properties.type==="forecast"&&x.properties.category===`${l}-${u}`);let S,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(m,v),S<=m.length-1;){if(S>0){const x=m[S],y=S===0?void 0:m[S-1],M=(h/60-((r=y==null?void 0:y.properties)==null?void 0:r.hour))/(x.properties.hour-((o=y==null?void 0:y.properties)==null?void 0:o.hour)),D=this.computeNumber(y==null?void 0:y.geometry.coordinates[0],x.geometry.coordinates[0],M),B=this.computeNumber(y==null?void 0:y.geometry.coordinates[1],x.geometry.coordinates[1],M),U=T.point([D,B],{name:l,model:u,category:x==null?void 0:x.properties.category,date:v.format(),format:v.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(y==null?void 0:y.properties.gusts,x.properties.gusts,M),hour:this.computeNumber(y==null?void 0:y.properties.hour,x.properties.hour,M),movement:this.computeNumber(y==null?void 0:y.properties.movement,x.properties.movement,M),pressure:this.computeNumber(y==null?void 0:y.properties.pressure,x.properties.pressure,M),wind:this.computeNumber(y==null?void 0:y.properties.wind,x.properties.wind,M),type:"forecast",disabled:d,showCircle:g});s.push(U)}h+=e*60,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(t,e){const{t1:n,t2:s,hr:c,hours:i}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:s,hr:c,hours:i}}static diversionPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const p=b.calculateDistance(t,c),h=b.calculateDistance(t,i);if(p>2*n&&h>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,p,h,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=Math.abs(a-l);let g=0;u<180?g=u+90:u>=180&&(g=u-90);const d=b.calculateCoordinate(c,g,n);return k==null||k.info("[%s] the right tangent position: %j",s.requestId,{from:t,t1:c,t2:i,radius:n,bearing1:a,bearing2:l,right:d}),{at:d,t1:c,t2:i,hr:Number(r),hours:o}}return{}}static driftPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const d=b.calculateDistance(t,c),p=b.calculateDistance(t,i);if(d>2*n&&p>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,d,p,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=b.calculateDistance(t,c);return{at:b.calculateCoordinate(c,a-l+180,n<u?n:u),t1:c,t2:i,hr:Number(r),hours:o}}else return k==null||k.info("[%s] no need drift: %j",s.requestId,{from:t,t1:c,t2:i,hr:r}),{}}static tropicalCenterTwin(t,e=24,n={}){var l,u,g,d,p;let s={};(l=t.forecasts)==null||l.forEach(h=>{s={...h.hours,...s}});const c=((u=t==null?void 0:t.history)==null?void 0:u[0])||(s==null?void 0:s[(g=Object.keys(s))==null?void 0:g[0]]);k==null||k.info("[%s] the first tropical center: %j",n.requestId,c);let i=(d=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:e)))==null?void 0:d.at(-1);i||(i=(p=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:2*e)))==null?void 0:p.at(-1));const r=s==null?void 0:s[i||-1];k==null||k.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const o=Object.keys(s||{}).filter(h=>Number(h)<=Number(i)),a={0:c};for(const h of o)a[h]=s[h];return{t1:c,t2:r,hr:Number(i),hours:a}}static pickIndex(t,e){let n=0;for(const s of t){if(P(s.properties.date).isAfter(e))return n===0?-1:n;n++}return n}static computeNumber(t,e,n){if(t)if(e){if(isNaN(t)&&isNaN(e)&&typeof t!="string"&&typeof e!="string"){const s={};for(const c in t)s[c]=this.computeNumber(t[c],e[c],n);return s}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,t){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let I;try{I=V.getLogger("meteo")}catch{}finally{}function st(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:t}=new C("").window;return new t}class E{static toArrayBuffer(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}static drawCircle(t,e,n,s={}){const c=(s==null?void 0:s.steps)??64,i=(s==null?void 0:s.units)??"nauticalmiles",r=(s==null?void 0:s.properties)??{},o=T.point([t,e]),a=T.destination(o,n,90,{units:i}),l=P.utc();r.id=(s==null?void 0:s.id)||l.valueOf().toString();const u="circle";return r.name=(s==null?void 0:s.name)||`${u}_${l.format()}`,r.radius=n,r.center=[t,e],r.end=a.geometry.coordinates.map(g=>f.roundPrecision(g,9)),r.units=i,r.steps=c,r.shape="circle",I.info("[%s] draw circle with %j",s==null?void 0:s.requestId,r),T.circle(o,n,{steps:c,units:i,properties:r})}static drawRect(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="rect";s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.start=t.map(l=>f.roundPrecision(l,9)),s.end=e.map(l=>f.roundPrecision(l,9)),s.shape="rect",I.info("[%s] draw rect with %j",n==null?void 0:n.requestId,s);const[r,o]=f.convertToMonotonicLng2([t,e]),a=[Math.min(r[0],o[0]),Math.min(r[1],o[1]),Math.max(r[0],o[0]),Math.max(r[1],o[1])];return T.bboxPolygon(a,{properties:s})}static drawLine(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="line";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.shape="line",I.info("[%s] draw line with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.lineString(i,n)}static drawPolygon(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="polygon";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.coordinates=t.map(r=>r.map(o=>f.roundPrecision(o,9))),n.shape="polygon",I.info("[%s] draw polygon with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.polygon([i],n)}static drawPoint(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="point";return s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.shape="point",I.info("[%s] draw point with %j",n==null?void 0:n.requestId,s),T.point([e,t],s)}static parseCircle(t,e={}){var s,c;I.info("[%s] parse circle with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="circle"){const i=P.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const r=n==null?void 0:n.id,o=((s=n==null?void 0:n.center)==null?void 0:s.length)==2?T.point(n.center):T.centroid(t);let a="center";o.properties={id:`${a}_${r}`,parentId:r,name:a};const l=(n==null?void 0:n.units)||"nauticalmiles";let u=n==null?void 0:n.radius;if(!u){const p=T.polygonToLine(t);u=T.pointToLineDistance(o,p,{units:l})}a="end";const g=((c=n==null?void 0:n.end)==null?void 0:c.length)==2?T.point(n.end):T.destination(o,u,90,{units:l});g.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l};const d=T.lineString([o.geometry.coordinates,g.geometry.coordinates]);return a="edge",d.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l},T.featureCollection([o,g,d,t])}else return I.warn("[%s] not a orm-std circle, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseRect(t,e={}){I.info("[%s] parse rect with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="rect"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,i=t.geometry.coordinates[0],o=["sw","nw","ne","se"].map((a,l)=>{const u=T.point(i[l]);return u.properties={id:`${a}_${c}`,parentId:c,name:a},u});return T.featureCollection([...o,t])}else return I.warn("[%s] not a orm-std rect, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseLine(t,e={}){I.info("[%s] parse line with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="line"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates.map((o,a)=>{const l=`point_${a}`,u=T.point(o);return u.properties={id:`${l}_${c}`,parentId:c,name:l,index:a},u});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std line, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parsePolygon(t,e={}){I.info("[%s] parse polygon with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="polygon"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates[0].map((o,a)=>{const l=T.point(o),u=`corner_${a}`;return l.properties={id:`${u}_${c}`,parentId:c,name:u,index:a},l});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std polygon, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static _inflateRawSync(t){var e;if(typeof process<"u"&&((e=process.versions)!=null&&e.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(t)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(t){var g;const e=new Uint8Array(t),n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),s=new DataView(n),c=new Uint8Array(n),i=new Map;let r=-1;for(let d=n.byteLength-22;d>=0;d--)if(s.getUint32(d,!0)===101010256){r=d;break}if(r<0)throw new Error("Invalid ZIP file: EOCD not found");s.getUint16(r+8,!0);const o=s.getUint32(r+12,!0),a=s.getUint32(r+16,!0);let l=a;const u=a+o;for(;l<u;){if(s.getUint32(l,!0)!==33639248)throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);const p=s.getUint16(l+10,!0),h=s.getUint32(l+20,!0),m=s.getUint16(l+28,!0),S=s.getUint16(l+30,!0),v=s.getUint16(l+32,!0),x=s.getUint32(l+42,!0),y=c.slice(l+46,l+46+m),M=new TextDecoder().decode(y),D=s.getUint16(x+26,!0),B=s.getUint16(x+28,!0),U=x+30+D+B,$=c.slice(U,U+h);if(p===0)i.set(M,$);else if(p===8){if(typeof DecompressionStream<"u"){const R=new DecompressionStream("deflate-raw"),N=R.writable.getWriter(),A=R.readable.getReader();N.write($),N.close();const q=[];let j=0;for(;;){const{done:F,value:O}=await A.read();if(F)break;q.push(O),j+=O.length}const G=new Uint8Array(j);let W=0;for(const F of q)G.set(F,W),W+=F.length;i.set(M,G)}else if(typeof process<"u"&&((g=process.versions)!=null&&g.node))try{i.set(M,E._inflateRawSync($))}catch{}}l+=46+m+S+v}return i}static async convertKML2GeoJSON(t,e={}){var r,o;I.info("[%s] convert kml to geojson",e==null?void 0:e.requestId);const s=st().parseFromString(t,"application/xml"),c=Array.from(s.querySelectorAll("Placemark")),i=[];for(const a of c){const l={},u=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const y of u){const M=y.getAttribute("name"),D=(o=(r=y.querySelector("value"))==null?void 0:r.textContent)==null?void 0:o.trim();M&&D!==void 0&&D!==null&&(l[M]=D)}const g=P.utc(),d=Object.keys(l).find(y=>y.toLowerCase().indexOf("name")!==-1),p=d?l[d]:void 0,h=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,m=y=>y.trim().split(/[\s\n]+/).filter(M=>M.length>0).map(M=>{const D=M.split(",").map(Number);return[D[0],D[1]]}),S=a.querySelector("LineString > coordinates");if(S){const y=m(S.textContent||"");if(y.length>=2){const M=T.lineString(y,{...l,shape:"line",id:h,name:p});i.push(M)}continue}const v=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(v){const y=m(v.textContent||"");if(y.length>=4){const M=y[0][0]===y[y.length-1][0]&&y[0][1]===y[y.length-1][1]?y:[...y,y[0]],D=T.polygon([M],{...l,shape:"polygon",id:h,name:p});i.push(D)}continue}const x=a.querySelector("Point > coordinates");if(x){const y=m(x.textContent||"");if(y.length>=1){const M=T.point(y[0],{...l,shape:"point",id:h,name:p});i.push(M)}continue}}return T.featureCollection(i)}static async convertKMZ2GeoJSON(t,e={}){var i;I.info("[%s] convert kmz to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=n.get("doc.kml")??((i=[...n.entries()].find(([r])=>r.toLowerCase().endsWith(".kml")))==null?void 0:i[1]);if(!s)return I.warn("[%s] no .kml file found in kmz",e==null?void 0:e.requestId),T.featureCollection([]);const c=new TextDecoder().decode(s);return E.convertKML2GeoJSON(c,e)}static async convertZIP2GeoJSON(t,e={}){I.info("[%s] convert zip to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=[];for(const[c,i]of n){if(!c.toLowerCase().endsWith(".kml"))continue;const r=new TextDecoder().decode(i),o=await E.convertKML2GeoJSON(r,e);s.push(...o.features)}return s.length===0?(I.warn("[%s] no .kml files found in zip",e==null?void 0:e.requestId),this.convertSHP2GeoJSON(t,e)):T.featureCollection(s)}static async convertSHP2GeoJSON(t,e={}){I.info("[%s] convert shp zip to geojson",e==null?void 0:e.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await Q(t);if(Array.isArray(n)){const s=n.flatMap(o=>o.features||[]),c=P.utc(),i=(e==null?void 0:e.id)||c.valueOf().toString(),r={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return s.forEach((o,a)=>{var p;const l=((p=o.geometry)==null?void 0:p.type)||"",u=r[l]||l.toLowerCase();o.properties=o.properties||{},o.properties.shape=u,o.properties.parentId=i,o.properties.id=`${i}_${a}`;const g=Object.keys(o.properties).find(h=>h.toLowerCase().indexOf("name")!==-1),d=g?o.properties[g]:void 0;o.properties.name=d||`${u}_${c.format()}_${a}`}),T.featureCollection(s)}return n}catch(n){return I.warn("[%s] failed to convert shp zip: %s",e==null?void 0:e.requestId,n),T.featureCollection([])}}}w.AisHelper=K,w.GeoJsonHelper=E,w.LaneHelper=b,w.LngLatHelper=f,w.TropicalHelper=nt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
9
+ `)}static coordinatesSummary(t,e=3){if(t.length>1){const n=t[0],s=t[t.length-1],c=(n==null?void 0:n.positionTime)<(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),i=(n==null?void 0:n.positionTime)>(s==null?void 0:s.positionTime)?P.unix(n==null?void 0:n.positionTime):P.unix(s==null?void 0:s.positionTime),r=Math.round(i.diff(c,"hours",!0)*100)/100,o=this.generateRouteAccordingToWaypoints(t,!0,!0),a=this.calculateRouteDistance(o),u=K.inspectStoppages(t,e).reduce((d,p)=>(d.duration+=p.duration,d.distance+=p.distance,d),{hours:0,distance:0,spd:0,duration:0});u.hours=Math.round(u.duration/3600*100)/100,u.distance=Math.round(u.distance*100)/100,u.spd=u.hours?Math.round(u.distance/u.hours*100)/100:0;const g=r?Math.round((a-u.distance)/(r-u.hours)*100)/100:0;return{begin:c.utc().format(),end:i.utc().format(),distance:Math.round((a-u.distance)*100)/100,hours:Math.round((r-u.hours)*100)/100,avgSpeed:g,stoppage:u}}return{begin:void 0,end:void 0,distance:0,hours:0,avgSpeed:0}}static pickUTCSampleFromSpeed(t,e){var l,u,g;if(!((u=(l=e==null?void 0:e.sample)==null?void 0:l.hours)!=null&&u.length))return{routes:[],hour:void 0};const n=e.sample.hours.at(0),s=P.utc(t),c=P.utc(e.eta),i=s.isAfter(c)?c:s;let r=e.sample.all.find(d=>d.eta===i.format());if(!r){let d=e.sample.all.filter(y=>P.utc(y.eta).isBefore(i)).at(-1);if(d){const y=this.calculateSubRoute(d,e.route);r=(g=this.calculateNextCoordinateAlongRoute(d,d.speed*i.diff(P(d.etd),"hours",!0),y))==null?void 0:g.coordinate}else d=e.sample.all.at(0),r=d;const{cFactor:p,cog:h,wxFactor:m,meteo:S}=d,v=Math.round(r.distanceFromPrevious*1e4)/1e4,x=Math.round((v+d.distanceFromStart)*1e4)/1e4;r={...r,cFactor:p,cog:h,speed:d.speed,wxFactor:m,distanceFromStart:x,distanceFromPrevious:v,meteo:S,eta:i.format(),etd:i.format()}}r.distanceToGo=Math.round((e.distance-r.distanceFromStart)*100)/100,r.timeToGo=Math.round(c.diff(r.etd,"hours",!0)*100)/100;const o=this.calculateRangeWaypoints(n,r,e.route);return{routes:this.generateRouteAccordingToWaypoints(o),hour:r}}static pickUTCSampleFromRoute(t,e,n){var d;const s=this.calculateSubRoute(e,n),c=this.calculateRouteDistance(s),i=c/e.speed,r=P.utc(t),o=P(e.etd),a=(d=this.calculateNextCoordinateAlongRoute(e,e.speed*r.diff(P(e.etd),"hours",!0),s))==null?void 0:d.coordinate;a.speed=e.speed;const l=o.clone().add(a.hourFromPrevious,"hour");a.eta=Math.abs(l.diff(r,"second"))<2?r.format():l.format(),a.etd=a.eta,a.distanceFromStart=Math.round(a.distanceFromPrevious*100)/100,a.distanceToGo=Math.round((c-a.distanceFromStart)*100)/100,a.timeToGo=Math.round(o.clone().add(i,"hour").diff(P(a.etd),"hour")*100)/100;const u=this.calculateRangeWaypoints(e,a,n);return{routes:this.generateRouteAccordingToWaypoints(u),hour:a}}static includedAngle(t,e){L==null||L.debug("calculate bearing via: %j",{bearing:t,degree:e});let n=Math.abs(t%360-(e%360||0));return n=n>180?360-n:n,n}static async intersectInECA(t,e){var c,i;const s=(e instanceof Array?e:e.features).filter(r=>{var o,a;return((o=r.geometry)==null?void 0:o.type)==="Polygon"&&!((a=r.properties)!=null&&a.disabled)});if(t!=null&&t.length){let r=t;t.some(u=>u instanceof Array)?t=this.convertRouteToCoordinates(t):r=this.divideAccordingToLng(t);const o=r.map(u=>T.lineString(u)),a=[],l=s.map(u=>({polygon:u,bbox:T.bbox(u)}));for(const u of o){const g=u.geometry.coordinates,d=this.convertRouteToCoordinates([g]),p=T.bbox(u);for(const{polygon:h,bbox:m}of l){if(p[0]>m[2]||p[2]<m[0]||p[1]>m[3]||p[3]<m[1])continue;let S=[];const v=T.lineIntersect(u,h);(c=v==null?void 0:v.features)!=null&&c.length&&(S=T.getCoords(v.features).map(M=>{const D=T.getCoord(M);return{lng:D[0],lat:D[1]}}));const x=[...d];if(S.length>0)for(const y of S)this.mergeCoordinateToWaypoints(y,x,!0);for(let y=0;y<x.length-1;y++){const M=x[y],D=x[y+1],B=this.calculateRangeWaypoints(M,D,[],x),U=this.divideAccordingToLng(B);for(const $ of U){const R=[Math.min($[0][0],$[$.length-1][0]),Math.min($[0][1],$[$.length-1][1]),Math.max($[0][0],$[$.length-1][0]),Math.max($[0][1],$[$.length-1][1])];if(R[0]>m[2]||R[2]<m[0]||R[1]>m[3]||R[3]<m[1])continue;const N=T.lineString($);if(T.booleanContains(h,N)){const A=$.map(j=>({lng:j[0],lat:j[1]})),q=this.calculateRouteDistance([$]);a.push({distance:q,waypoints:A,eca:(i=h==null?void 0:h.properties)==null?void 0:i.name})}}}}}return a}return[]}}let k;try{k=V.getLogger("vessel")}catch{}finally{}class nt{static convert2Geojson(t){var n,s,c;const e=T.featureCollection([]);for(const i of t){const r=(n=i.history)==null?void 0:n[0];if(i.forecasts){r&&r.wind&&(r.wind.kts=r.kts);for(const o of i.forecasts){let a;const l=[],u=[],g=P(o.date).utc(),d=`${i.name}-${o.model}`;for(const h in o==null?void 0:o.hours){const m=o.hours[h];a=a||m;const S=g.clone().add(Number(h),"hour"),v=T.point([m.lng,m.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:S.format(),hour:Number(h),format:S.format("MMM-DD/HHmm[Z]"),pressure:m.pressure>1e4?f.roundPrecision(m.pressure/100,0):f.roundPrecision(m.pressure,0),gusts:m.gusts,wind:m.wind||{},movement:m.movement,category:d,type:"forecast"});u.push(v),l.push(v.geometry.coordinates)}const p={kts:void 0,deg:void 0};if(r){const h=P(r.updated).utc();if(a){const S=b.calculateDistance(r,a),v=P(a.utc||a.updated).diff(h,"h",!0);p.kts=Math.round(S/v*100)/100,p.deg=b.calculateBearing(r,a,!0,0)}const m=T.point([r.lng,r.lat],{model:o.model,name:i.name,nameCn:i.nameCn,date:h.format(),hour:0,format:h.format("MMM-DD/HHmm[Z]"),pressure:r.pressure>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r.pressure,0),wind:r.wind,movement:p,category:d,type:"forecast",important:!0});u.unshift(m),l.unshift(m.geometry.coordinates)}if(e.features.push(...u),(l==null?void 0:l.length)>1){const h=T.lineString(f.convertToMonotonicLng2(l),{date:(r==null?void 0:r.updated)||(g==null?void 0:g.format()),id:i.id||i.name,model:o.model,name:i.name,category:d,type:"forecast",movement:p});e.features.push(h)}}}if(e.features.sort((o,a)=>o.properties.type==="forecast"&&a.properties.type==="forecast"&&o.geometry.type==="Point"&&a.geometry.type==="Point"?P(o.properties.date).valueOf()-P(a.properties.date).valueOf():0),(s=i.history)!=null&&s.length){const o=[],a=P(r==null?void 0:r.updated).utc(),l=P((c=i.history)==null?void 0:c.at(-1).updated).utc(),u=a.diff(l,"h")%24>2?24:12;for(const g of i.history){const d=P(g.updated).utc(),p=d.isSameOrBefore(a)||d.isSame(l);p&&a.add(-u,"h");const h=T.point([g.lng,g.lat],{name:i.name,nameCn:i.nameCn,date:d.format(),format:d.format("MMM-DD/HHmm[Z]"),pressure:g.pressure>1e4?f.roundPrecision(g.pressure/100,0):f.roundPrecision(g.pressure,0),kts:g.kts,level:g.type,type:"history",category:`${i.name}-history`,wind:g.wind,movement:g.movement,important:p});e.features.push(h),o.push(h.geometry.coordinates)}if(o.length===1&&o.push(o[0]),o.length>1){const g=T.lineString(f.convertToMonotonicLng2(o),{name:i.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?f.roundPrecision((r==null?void 0:r.pressure)/100,0):f.roundPrecision(r==null?void 0:r.pressure,0),kts:r==null?void 0:r.kts,level:r==null?void 0:r.type});e.features.push(g)}}}return e}static interpolate(t,e=3){var c,i,r,o;const n=(c=t==null?void 0:t.data)==null?void 0:c.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),s=[];for(const a of n){const l=a.properties.name,u=a.properties.model,g=a.properties.showCircle,d=a.properties.disabled,p=P(a.properties.date).utc();let h=e*60;const m=(i=t==null?void 0:t.data)==null?void 0:i.features.filter(x=>x.geometry.type==="Point"&&x.properties.type==="forecast"&&x.properties.category===`${l}-${u}`);let S,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(m,v),S<=m.length-1;){if(S>0){const x=m[S],y=S===0?void 0:m[S-1],M=(h/60-((r=y==null?void 0:y.properties)==null?void 0:r.hour))/(x.properties.hour-((o=y==null?void 0:y.properties)==null?void 0:o.hour)),D=this.computeNumber(y==null?void 0:y.geometry.coordinates[0],x.geometry.coordinates[0],M),B=this.computeNumber(y==null?void 0:y.geometry.coordinates[1],x.geometry.coordinates[1],M),U=T.point([D,B],{name:l,model:u,category:x==null?void 0:x.properties.category,date:v.format(),format:v.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(y==null?void 0:y.properties.gusts,x.properties.gusts,M),hour:this.computeNumber(y==null?void 0:y.properties.hour,x.properties.hour,M),movement:this.computeNumber(y==null?void 0:y.properties.movement,x.properties.movement,M),pressure:this.computeNumber(y==null?void 0:y.properties.pressure,x.properties.pressure,M),wind:this.computeNumber(y==null?void 0:y.properties.wind,x.properties.wind,M),type:"forecast",disabled:d,showCircle:g});s.push(U)}h+=e*60,v=p.clone().add(h,"minute").set({minute:0,second:0,millisecond:0})}}return s}static accelPassageAt(t,e){const{t1:n,t2:s,hr:c,hours:i}=this.tropicalCenterTwin(t,24,e);return{t1:n,t2:s,hr:c,hours:i}}static diversionPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const p=b.calculateDistance(t,c),h=b.calculateDistance(t,i);if(p>2*n&&h>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need diversion: %j",s.requestId,p,h,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=Math.abs(a-l);let g=0;u<180?g=u+90:u>=180&&(g=u-90);const d=b.calculateCoordinate(c,g,n);return k==null||k.info("[%s] the right tangent position: %j",s.requestId,{from:t,t1:c,t2:i,radius:n,bearing1:a,bearing2:l,right:d}),{at:d,t1:c,t2:i,hr:Number(r),hours:o}}return{}}static driftPassageAt(t,e,n,s={}){const{t1:c,t2:i,hr:r,hours:o}=this.tropicalCenterTwin(e,24,s);if(c&&i){if(!s.debug){const d=b.calculateDistance(t,c),p=b.calculateDistance(t,i);if(d>2*n&&p>2*n)return k==null||k.info("[%s] the distance between from and t1(%d) and t2(%d) is enough, no need drifting: %j",s.requestId,d,p,{from:t,t1:c,t2:i,hr:r}),{}}const a=b.calculateBearing(t,c),l=b.calculateBearing(c,i),u=b.calculateDistance(t,c);return{at:b.calculateCoordinate(c,a-l+180,n<u?n:u),t1:c,t2:i,hr:Number(r),hours:o}}else return k==null||k.info("[%s] no need drift: %j",s.requestId,{from:t,t1:c,t2:i,hr:r}),{}}static tropicalCenterTwin(t,e=24,n={}){var l,u,g,d,p;let s={};(l=t.forecasts)==null||l.forEach(h=>{s={...h.hours,...s}});const c=((u=t==null?void 0:t.history)==null?void 0:u[0])||(s==null?void 0:s[(g=Object.keys(s))==null?void 0:g[0]]);k==null||k.info("[%s] the first tropical center: %j",n.requestId,c);let i=(d=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:e)))==null?void 0:d.at(-1);i||(i=(p=Object.keys(s||{}).filter(h=>Number(h)<=(e<0?24:2*e)))==null?void 0:p.at(-1));const r=s==null?void 0:s[i||-1];k==null||k.info("[%s] the second tropical center: %j in %d hrs",n.requestId,r,i);const o=Object.keys(s||{}).filter(h=>Number(h)<=Number(i)),a={0:c};for(const h of o)a[h]=s[h];return{t1:c,t2:r,hr:Number(i),hours:a}}static pickIndex(t,e){let n=0;for(const s of t){if(P(s.properties.date).isAfter(e))return n===0?-1:n;n++}return n}static computeNumber(t,e,n){if(t)if(e){if(isNaN(t)&&isNaN(e)&&typeof t!="string"&&typeof e!="string"){const s={};for(const c in t)s[c]=this.computeNumber(t[c],e[c],n);return s}return Math.round((t+(e-t)*n)*100)/100}else return t;else return e}}typeof globalThis<"u"&&typeof globalThis.Buffer>"u"&&(globalThis.Buffer={isBuffer(C){return C instanceof Uint8Array},from(C,t){if(typeof C=="string")return new TextEncoder().encode(C);if(C instanceof ArrayBuffer)return new Uint8Array(C);if(Array.isArray(C))return new Uint8Array(C);throw new TypeError("Buffer.from: unsupported source type")}});let I;try{I=V.getLogger("meteo")}catch{}finally{}function st(){if(typeof DOMParser<"u")return new DOMParser;const{JSDOM:C}=require("jsdom"),{DOMParser:t}=new C("").window;return new t}class E{static toArrayBuffer(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}static drawCircle(t,e,n,s={}){const c=(s==null?void 0:s.steps)??64,i=(s==null?void 0:s.units)??"nauticalmiles",r=(s==null?void 0:s.properties)??{},o=T.point([t,e]),a=T.destination(o,n,90,{units:i}),l=P.utc();r.id=(s==null?void 0:s.id)||l.valueOf().toString();const u="circle";return r.name=(s==null?void 0:s.name)||`${u}_${l.format()}`,r.radius=n,r.center=[t,e],r.end=a.geometry.coordinates.map(g=>f.roundPrecision(g,9)),r.units=i,r.steps=c,r.shape="circle",I.info("[%s] draw circle with %j",s==null?void 0:s.requestId,r),T.circle(o,n,{steps:c,units:i,properties:r})}static drawRect(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="rect";s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.start=t.map(l=>f.roundPrecision(l,9)),s.end=e.map(l=>f.roundPrecision(l,9)),s.shape="rect",I.info("[%s] draw rect with %j",n==null?void 0:n.requestId,s);const[r,o]=f.convertToMonotonicLng2([t,e]),a=[Math.min(r[0],o[0]),Math.min(r[1],o[1]),Math.max(r[0],o[0]),Math.max(r[1],o[1])];return T.bboxPolygon(a,{properties:s})}static drawLine(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="line";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.shape="line",I.info("[%s] draw line with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.lineString(i,n)}static drawPolygon(t,e={}){const n=(e==null?void 0:e.properties)??{},s=P.utc();n.id=(e==null?void 0:e.id)||s.valueOf().toString();const c="polygon";n.name=(e==null?void 0:e.name)||`${c}_${s.format()}`,n.coordinates=t.map(r=>r.map(o=>f.roundPrecision(o,9))),n.shape="polygon",I.info("[%s] draw polygon with %j",e==null?void 0:e.requestId,n);const i=f.convertToMonotonicLng2(t);return T.polygon([i],n)}static drawPoint(t,e,n={}){const s=(n==null?void 0:n.properties)??{},c=P.utc();s.id=(n==null?void 0:n.id)||c.valueOf().toString();const i="point";return s.name=(n==null?void 0:n.name)||`${i}_${c.format()}`,s.shape="point",I.info("[%s] draw point with %j",n==null?void 0:n.requestId,s),T.point([e,t],s)}static parseCircle(t,e={}){var s,c;I.info("[%s] parse circle with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="circle"){const i=P.utc();n.id=(n==null?void 0:n.id)||i.valueOf().toString();const r=n==null?void 0:n.id,o=((s=n==null?void 0:n.center)==null?void 0:s.length)==2?T.point(n.center):T.centroid(t);let a="center";o.properties={id:`${a}_${r}`,parentId:r,name:a};const l=(n==null?void 0:n.units)||"nauticalmiles";let u=n==null?void 0:n.radius;if(!u){const p=T.polygonToLine(t);u=T.pointToLineDistance(o,p,{units:l})}a="end";const g=((c=n==null?void 0:n.end)==null?void 0:c.length)==2?T.point(n.end):T.destination(o,u,90,{units:l});g.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l};const d=T.lineString([o.geometry.coordinates,g.geometry.coordinates]);return a="edge",d.properties={id:`${a}_${r}`,parentId:r,name:a,radius:u,units:l},T.featureCollection([o,g,d,t])}else return I.warn("[%s] not a orm-std circle, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseRect(t,e={}){I.info("[%s] parse rect with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="rect"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,i=t.geometry.coordinates[0],o=["sw","nw","ne","se"].map((a,l)=>{const u=T.point(i[l]);return u.properties={id:`${a}_${c}`,parentId:c,name:a},u});return T.featureCollection([...o,t])}else return I.warn("[%s] not a orm-std rect, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parseLine(t,e={}){I.info("[%s] parse line with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="line"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates.map((o,a)=>{const l=`point_${a}`,u=T.point(o);return u.properties={id:`${l}_${c}`,parentId:c,name:l,index:a},u});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std line, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static parsePolygon(t,e={}){I.info("[%s] parse polygon with %j",e==null?void 0:e.requestId,t.properties);const n=t.properties||{};if(n.shape=="polygon"){const s=P.utc();n.id=(n==null?void 0:n.id)||s.valueOf().toString();const c=n==null?void 0:n.id,r=t.geometry.coordinates[0].map((o,a)=>{const l=T.point(o),u=`corner_${a}`;return l.properties={id:`${u}_${c}`,parentId:c,name:u,index:a},l});return T.featureCollection([...r,t])}else return I.warn("[%s] not a orm-std polygon, just return the original feature",e==null?void 0:e.requestId),T.featureCollection([t])}static _inflateRawSync(t){var e;if(typeof process<"u"&&((e=process.versions)!=null&&e.node)){const n=require("zlib");return new Uint8Array(n.inflateRawSync(Buffer.from(t)))}throw new Error("Sync inflate is not supported in browser; use the async convertKMZ2GeoJSONAsync / convertZIP2GeoJSONAsync instead")}static async _parseZipEntries(t){var g;const e=new Uint8Array(t),n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),s=new DataView(n),c=new Uint8Array(n),i=new Map;let r=-1;for(let d=n.byteLength-22;d>=0;d--)if(s.getUint32(d,!0)===101010256){r=d;break}if(r<0)throw new Error("Invalid ZIP file: EOCD not found");s.getUint16(r+8,!0);const o=s.getUint32(r+12,!0),a=s.getUint32(r+16,!0);let l=a;const u=a+o;for(;l<u;){if(s.getUint32(l,!0)!==33639248)throw new Error(`Invalid ZIP file: Central Directory signature mismatch at offset ${l}`);const p=s.getUint16(l+10,!0),h=s.getUint32(l+20,!0),m=s.getUint16(l+28,!0),S=s.getUint16(l+30,!0),v=s.getUint16(l+32,!0),x=s.getUint32(l+42,!0),y=c.slice(l+46,l+46+m),M=new TextDecoder().decode(y),D=s.getUint16(x+26,!0),B=s.getUint16(x+28,!0),U=x+30+D+B,$=c.slice(U,U+h);if(p===0)i.set(M,$);else if(p===8){if(typeof DecompressionStream<"u"){const R=new DecompressionStream("deflate-raw"),N=R.writable.getWriter(),A=R.readable.getReader();N.write($),N.close();const q=[];let j=0;for(;;){const{done:F,value:O}=await A.read();if(F)break;q.push(O),j+=O.length}const G=new Uint8Array(j);let W=0;for(const F of q)G.set(F,W),W+=F.length;i.set(M,G)}else if(typeof process<"u"&&((g=process.versions)!=null&&g.node))try{i.set(M,E._inflateRawSync($))}catch{}}l+=46+m+S+v}return i}static async convertKML2GeoJSON(t,e={}){var r,o;I.info("[%s] convert kml to geojson",e==null?void 0:e.requestId);const s=st().parseFromString(t,"application/xml"),c=Array.from(s.querySelectorAll("Placemark")),i=[];for(const a of c){const l={},u=Array.from(a.querySelectorAll("ExtendedData > Data"));for(const y of u){const M=y.getAttribute("name"),D=(o=(r=y.querySelector("value"))==null?void 0:r.textContent)==null?void 0:o.trim();M&&D!==void 0&&D!==null&&(l[M]=D)}const g=P.utc(),d=Object.keys(l).find(y=>y.toLowerCase().indexOf("name")!==-1),p=d?l[d]:void 0,h=`${g.valueOf().toString()}_${Math.random().toString(36).slice(2,8)}`,m=y=>y.trim().split(/[\s\n]+/).filter(M=>M.length>0).map(M=>{const D=M.split(",").map(Number);return[D[0],D[1]]}),S=a.querySelector("LineString > coordinates");if(S){const y=m(S.textContent||"");if(y.length>=2){const M=T.lineString(y,{...l,shape:"line",id:h,name:p});i.push(M)}continue}const v=a.querySelector("Polygon outerBoundaryIs LinearRing > coordinates");if(v){const y=m(v.textContent||"");if(y.length>=4){const M=y[0][0]===y[y.length-1][0]&&y[0][1]===y[y.length-1][1]?y:[...y,y[0]],D=T.polygon([M],{...l,shape:"polygon",id:h,name:p});i.push(D)}continue}const x=a.querySelector("Point > coordinates");if(x){const y=m(x.textContent||"");if(y.length>=1){const M=T.point(y[0],{...l,shape:"point",id:h,name:p});i.push(M)}continue}}return T.featureCollection(i)}static async convertKMZ2GeoJSON(t,e={}){var i;I.info("[%s] convert kmz to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=n.get("doc.kml")??((i=[...n.entries()].find(([r])=>r.toLowerCase().endsWith(".kml")))==null?void 0:i[1]);if(!s)return I.warn("[%s] no .kml file found in kmz",e==null?void 0:e.requestId),T.featureCollection([]);const c=new TextDecoder().decode(s);return E.convertKML2GeoJSON(c,e)}static async convertZIP2GeoJSON(t,e={}){I.info("[%s] convert zip to geojson (async)",e==null?void 0:e.requestId),typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await E._parseZipEntries(t),s=[];for(const[c,i]of n){if(!c.toLowerCase().endsWith(".kml"))continue;const r=new TextDecoder().decode(i),o=await E.convertKML2GeoJSON(r,e);s.push(...o.features)}return s.length===0?(I.warn("[%s] no .kml files found in zip",e==null?void 0:e.requestId),this.convertSHP2GeoJSON(t,e)):T.featureCollection(s)}static async convertSHP2GeoJSON(t,e={}){I.info("[%s] convert shp zip to geojson",e==null?void 0:e.requestId);try{typeof Buffer<"u"&&Buffer.isBuffer(t)&&(t=E.toArrayBuffer(t));const n=await Q(t);if(Array.isArray(n)){const s=n.flatMap(o=>o.features||[]),c=P.utc(),i=(e==null?void 0:e.id)||c.valueOf().toString(),r={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon"};return s.forEach((o,a)=>{var p;const l=((p=o.geometry)==null?void 0:p.type)||"",u=r[l]||l.toLowerCase();o.properties=o.properties||{},o.properties.shape=u,o.properties.parentId=i,o.properties.id=`${i}_${a}`;const g=Object.keys(o.properties).find(h=>h.toLowerCase().indexOf("name")!==-1),d=g?o.properties[g]:void 0;o.properties.name=d||`${u}_${c.format()}_${a}`}),T.featureCollection(s)}return n}catch(n){return I.warn("[%s] failed to convert shp zip: %s",e==null?void 0:e.requestId,n),T.featureCollection([])}}}w.AisHelper=K,w.GeoJsonHelper=E,w.LaneHelper=b,w.LngLatHelper=f,w.TropicalHelper=nt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "2.3.8",
4
+ "version": "2.3.9",
5
5
  "description": "idm plugin for geo in browser",
6
6
  "type": "module",
7
7
  "keywords": [