@rr0/ufoathome 0.194.0 → 0.196.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-embed-scene/rr0-scene.mjs +4 -4
- package/dist-embed-sighting/CaseMessages_en-G5J5w1_d.js +1 -0
- package/dist-embed-sighting/CaseMessages_es-D7Rp1_1K.js +1 -0
- package/dist-embed-sighting/CaseMessages_fr-B8eZ1NIJ.js +1 -0
- package/dist-embed-sighting/CaseMessages_it-Cu02nVVo.js +1 -0
- package/dist-embed-sighting/{CaseReportExport-B9iaGKNP.js → CaseReportExport-CdRgJb5M.js} +1 -1
- package/dist-embed-sighting/rr0-sighting.mjs +343 -324
- package/dist-embed-sighting-editor/{AdsbLolArchiveProvider--KjPxNqw.js → AdsbLolArchiveProvider-BqEnqRP0.js} +1 -1
- package/dist-embed-sighting-editor/{BallesterGuaspAssessor-BTmq0r-G.js → BallesterGuaspAssessor-BL_yzudf.js} +1 -1
- package/dist-embed-sighting-editor/{BeamEditor-CI8-9VOc.js → BeamEditor-DA29mfqm.js} +1 -1
- package/dist-embed-sighting-editor/{BeamSystem-odg570aR.js → BeamSystem-DYohqXlF.js} +1 -1
- package/dist-embed-sighting-editor/{BirdEditor-DV3ndYff.js → BirdEditor-CAoRqqRV.js} +1 -1
- package/dist-embed-sighting-editor/{BirdFlock-O7K_g8y7.js → BirdFlock-TI63ZAKZ.js} +1 -1
- package/dist-embed-sighting-editor/{CaseEditorMessages_en-CoFukfwf.js → CaseEditorMessages_en-BPdxQsTX.js} +1 -1
- package/dist-embed-sighting-editor/{CaseEditorMessages_es-DZptbzB7.js → CaseEditorMessages_es-B48BAICC.js} +1 -1
- package/dist-embed-sighting-editor/{CaseEditorMessages_fr-DXl2GNmR.js → CaseEditorMessages_fr-DTWi9mIY.js} +1 -1
- package/dist-embed-sighting-editor/{CaseEditorMessages_it-ss10VmRM.js → CaseEditorMessages_it-CMLxgu8y.js} +1 -1
- package/dist-embed-sighting-editor/CaseElement-AXaERD8m.js +112 -0
- package/dist-embed-sighting-editor/CaseMessages_en-G5J5w1_d.js +1 -0
- package/dist-embed-sighting-editor/CaseMessages_es-D7Rp1_1K.js +1 -0
- package/dist-embed-sighting-editor/CaseMessages_fr-B8eZ1NIJ.js +1 -0
- package/dist-embed-sighting-editor/CaseMessages_it-Cu02nVVo.js +1 -0
- package/dist-embed-sighting-editor/{CaseReportExport-D0GXupCT.js → CaseReportExport-CDZp6xGk.js} +2 -2
- package/dist-embed-sighting-editor/{ContrailSystem-BddkU7fj.js → ContrailSystem-B0cQbaHc.js} +1 -1
- package/dist-embed-sighting-editor/{ControlPasses-CNlCUT1L.js → ControlPasses-BvS8haeS.js} +1 -1
- package/dist-embed-sighting-editor/{CoverageAssessor-DjY8iKp5.js → CoverageAssessor-DD1kSvun.js} +1 -1
- package/dist-embed-sighting-editor/{DroneEditor-DRsM2ash.js → DroneEditor-BRB2-dAw.js} +1 -1
- package/dist-embed-sighting-editor/{DroneFlight-Fr4Vgso3.js → DroneFlight-BpnBgJ9K.js} +1 -1
- package/dist-embed-sighting-editor/{Flightradar24Provider-BxeduRam.js → Flightradar24Provider-D5OdIL0L.js} +1 -1
- package/dist-embed-sighting-editor/{GLTFLoader-C6nlGTTi.js → GLTFLoader-DuqJVU4y.js} +1 -1
- package/dist-embed-sighting-editor/{HeadlightSystem-DI5wHYZu.js → HeadlightSystem-BejdfHqe.js} +1 -1
- package/dist-embed-sighting-editor/{HynekAssessor-DlXalbph.js → HynekAssessor-CwzpS7YP.js} +1 -1
- package/dist-embed-sighting-editor/{LanternEditor-M887ltwe.js → LanternEditor-BnXAwLuQ.js} +1 -1
- package/dist-embed-sighting-editor/{LaserBeam-Drpkr84G.js → LaserBeam-tqM2fwHf.js} +1 -1
- package/dist-embed-sighting-editor/{LaunchEditor-BjAk4XZR.js → LaunchEditor-vwecAGwH.js} +1 -1
- package/dist-embed-sighting-editor/{LaunchPlume-CrzPcqw7.js → LaunchPlume-DWyU0YyJ.js} +1 -1
- package/dist-embed-sighting-editor/{LaunchSimulation-C1ZWpKZT.js → LaunchSimulation-C_OJQoKC.js} +1 -1
- package/dist-embed-sighting-editor/{ModelSource-Bko_3OJt.js → ModelSource-D1Wt6VYS.js} +1 -1
- package/dist-embed-sighting-editor/{ModelThumbnails-DSshyLu2.js → ModelThumbnails-C_8KCF7H.js} +1 -1
- package/dist-embed-sighting-editor/{ModelViewer-_yhAYvNy.js → ModelViewer-Cy-6IZBY.js} +1 -1
- package/dist-embed-sighting-editor/{ModuleConformance-B6iFVb8X.js → ModuleConformance-DYi4XZdB.js} +2 -2
- package/dist-embed-sighting-editor/{ModuleSession-jKFl1FMo.js → ModuleSession-BDbaoiCf.js} +2 -2
- package/dist-embed-sighting-editor/ModuleThree-DRf9SEr_.js +1 -0
- package/dist-embed-sighting-editor/{ModulesPanelElement-VPRCdjmv.js → ModulesPanelElement-hDjGLhRa.js} +3 -3
- package/dist-embed-sighting-editor/{NearestApproach-O8k2n_qL.js → NearestApproach-D6tQo7dk.js} +1 -1
- package/dist-embed-sighting-editor/{PoherAssessor-sTJEnlmb.js → PoherAssessor-BTYpHucH.js} +1 -1
- package/dist-embed-sighting-editor/{RailwaySystem-BZqNSSFA.js → RailwaySystem-D_8D64Bu.js} +1 -1
- package/dist-embed-sighting-editor/{ReentryEditor-DfDGpL5C.js → ReentryEditor-D7HxkvKP.js} +2 -2
- package/dist-embed-sighting-editor/{ReentrySimulation-BuUK0niI.js → ReentrySimulation-Bom073AV.js} +1 -1
- package/dist-embed-sighting-editor/{ReferenceSystem-DvcQp167.js → ReferenceSystem-D_eueNAb.js} +1 -1
- package/dist-embed-sighting-editor/{SightingElement-BfxNhmfn.js → SightingElement-DukKlaH1.js} +4 -4
- package/dist-embed-sighting-editor/{SkyLantern-B7UlFgmB.js → SkyLantern-BDpxvmY3.js} +1 -1
- package/dist-embed-sighting-editor/{TraceSystem-vZF4B5EC.js → TraceSystem-B1mmypS3.js} +2 -2
- package/dist-embed-sighting-editor/{WaterSystem-DSWmZbiL.js → WaterSystem-mZ-f2CcD.js} +2 -2
- package/dist-embed-sighting-editor/rr0-sighting-editor.mjs +378 -366
- package/dist-embed-sighting-editor/{trafficRuntime-C5BXL-G6.js → trafficRuntime-CvK_m6bC.js} +1 -1
- package/dist-embed-ufoathome/{AdsbLolArchiveProvider-DXRO-h2K.js → AdsbLolArchiveProvider-BAZqWk1I.js} +1 -1
- package/dist-embed-ufoathome/{BallesterGuaspAssessor-ZSDHMhXN.js → BallesterGuaspAssessor-D5DnaJGn.js} +1 -1
- package/dist-embed-ufoathome/{BeamEditor-BvF4J204.js → BeamEditor-DmuKTRqU.js} +1 -1
- package/dist-embed-ufoathome/{BeamSystem-Yg5JRiCT.js → BeamSystem-KHzcEosy.js} +1 -1
- package/dist-embed-ufoathome/{BodyEditor-CRJFVGzZ.js → BodyEditor-Blkm_Xmd.js} +1 -1
- package/dist-embed-ufoathome/{CaseEditorElement-MwO-zwnP.js → CaseEditorElement-BTZu9wey.js} +41 -36
- package/dist-embed-ufoathome/{CaseEditorMessages_en-CoFukfwf.js → CaseEditorMessages_en-BPdxQsTX.js} +1 -1
- package/dist-embed-ufoathome/{CaseEditorMessages_es-DZptbzB7.js → CaseEditorMessages_es-B48BAICC.js} +1 -1
- package/dist-embed-ufoathome/{CaseEditorMessages_fr-DXl2GNmR.js → CaseEditorMessages_fr-DTWi9mIY.js} +1 -1
- package/dist-embed-ufoathome/{CaseEditorMessages_it-ss10VmRM.js → CaseEditorMessages_it-CMLxgu8y.js} +1 -1
- package/dist-embed-ufoathome/CaseElement-Cr3vTWdf.js +112 -0
- package/dist-embed-ufoathome/CaseMessages_en-G5J5w1_d.js +1 -0
- package/dist-embed-ufoathome/CaseMessages_es-D7Rp1_1K.js +1 -0
- package/dist-embed-ufoathome/CaseMessages_fr-B8eZ1NIJ.js +1 -0
- package/dist-embed-ufoathome/CaseMessages_it-Cu02nVVo.js +1 -0
- package/dist-embed-ufoathome/{CaseReportExport-D9YyGZHP.js → CaseReportExport-CyuSf3U_.js} +3 -3
- package/dist-embed-ufoathome/{CaseTimeline-CnP5rqaK.js → ColumnResize-DifCqMt1.js} +14 -7
- package/dist-embed-ufoathome/{ContrailSystem-O_yvjart.js → ContrailSystem-DqZ8PoEd.js} +1 -1
- package/dist-embed-ufoathome/{ControlPasses-BaglOE-7.js → ControlPasses-BtU_MVQU.js} +1 -1
- package/dist-embed-ufoathome/{CoverageAssessor-CBh0sDI1.js → CoverageAssessor-DkVligEj.js} +1 -1
- package/dist-embed-ufoathome/{Flightradar24Provider-C8Uj-qTs.js → Flightradar24Provider-GYjtvwah.js} +1 -1
- package/dist-embed-ufoathome/{GLTFLoader-B4SVqjkZ.js → GLTFLoader-DzEwUqtj.js} +1 -1
- package/dist-embed-ufoathome/{GeoJsonExport-C-daFhc2.js → GeoJsonExport-B1i0YjqN.js} +1 -1
- package/dist-embed-ufoathome/{GeographicFigures-N4WyX3J_.js → GeographicFigures-D5ZCRN0K.js} +1 -1
- package/dist-embed-ufoathome/{HeadlightSystem-7mtgTwud.js → HeadlightSystem-x2xYh-cs.js} +1 -1
- package/dist-embed-ufoathome/{HynekAssessor-DdoHR-Qt.js → HynekAssessor-DOUPfuRV.js} +1 -1
- package/dist-embed-ufoathome/{InterviewEditorElement-BSXLlt4e.js → InterviewEditorElement-Dt-KQiv0.js} +1 -1
- package/dist-embed-ufoathome/{InterviewElement-Dwk9iHNv.js → InterviewElement-BPsBLXlf.js} +1 -1
- package/dist-embed-ufoathome/{KmlExport-CX-tTjIv.js → KmlExport-JEXMAssj.js} +1 -1
- package/dist-embed-ufoathome/{LaserBeam-DUL1O57g.js → LaserBeam-Cy9lfcCE.js} +1 -1
- package/dist-embed-ufoathome/{LaunchEditor-X_zWEOTY.js → LaunchEditor-zWZhMyLf.js} +1 -1
- package/dist-embed-ufoathome/{LaunchPlume-CcfhClxb.js → LaunchPlume-CcUQvACB.js} +1 -1
- package/dist-embed-ufoathome/{LaunchSimulation-C9gbGzGM.js → LaunchSimulation-DRH0rTE7.js} +1 -1
- package/dist-embed-ufoathome/{ModelSource-BtuW2Ztg.js → ModelSource-Dljnl-RW.js} +1 -1
- package/dist-embed-ufoathome/{ModelThumbnails-CacTTCW4.js → ModelThumbnails-DeaPuKSb.js} +1 -1
- package/dist-embed-ufoathome/{ModelViewer-BlFPQJAr.js → ModelViewer-B-ZLBTmq.js} +1 -1
- package/dist-embed-ufoathome/{ModuleConformance-qYpBoQH9.js → ModuleConformance-Bd8yK7Ic.js} +2 -2
- package/dist-embed-ufoathome/{ModuleSession-D4LhYKvL.js → ModuleSession-DXdpVejH.js} +3 -3
- package/dist-embed-ufoathome/{ModuleThree-DLikU-uy.js → ModuleThree-BL59t48W.js} +1 -1
- package/dist-embed-ufoathome/{ModulesPanelElement-GY7cTQ5t.js → ModulesPanelElement-6KUAMJcl.js} +3 -3
- package/dist-embed-ufoathome/{NearestApproach-4ntSx6IQ.js → NearestApproach-wbFbwOAh.js} +1 -1
- package/dist-embed-ufoathome/{PictureRegistration-BLs4DkTI.js → PictureRegistration-CfSYGbeh.js} +1 -1
- package/dist-embed-ufoathome/{PoherAssessor-6t5qvmJy.js → PoherAssessor-CVIeQpd7.js} +1 -1
- package/dist-embed-ufoathome/{RailwaySystem-Dm-PbG_D.js → RailwaySystem-DTXetaSg.js} +1 -1
- package/dist-embed-ufoathome/{ReentryEditor-C7A3Kh3_.js → ReentryEditor-7Fxkxq-Q.js} +1 -1
- package/dist-embed-ufoathome/{ReentrySimulation-BlgfVSxb.js → ReentrySimulation-T3H0mJI3.js} +1 -1
- package/dist-embed-ufoathome/{ReferenceSystem-Bv62TprV.js → ReferenceSystem-CJaq2UzO.js} +1 -1
- package/dist-embed-ufoathome/{ShareDialogElement-DLr5u_tk.js → ShareDialogElement-ClhewPap.js} +11 -11
- package/dist-embed-ufoathome/{SightingElement-DuNE_Yt0.js → SightingElement-BtHQ5LDE.js} +4 -4
- package/dist-embed-ufoathome/{TraceSystem-Cl5kzaIr.js → TraceSystem-B42kzZXG.js} +1 -1
- package/dist-embed-ufoathome/{VideoButton-DXPI7_Vt.js → VideoButton-DhanY6AD.js} +1 -1
- package/dist-embed-ufoathome/{WaterSystem-CTGGh-Y-.js → WaterSystem-DyJivqCq.js} +1 -1
- package/dist-embed-ufoathome/rr0-ufoathome.mjs +3 -3
- package/dist-embed-ufoathome/{surroundingsSources-CVKKb8h6.js → surroundingsSources-DEMGw8rm.js} +1 -1
- package/dist-embed-ufoathome/{trafficRuntime-DvKPyJcx.js → trafficRuntime-BJFdLEcT.js} +1 -1
- package/package.json +1 -1
- package/dist-embed-sighting/CaseMessages_en-BbbbikHH.js +0 -1
- package/dist-embed-sighting/CaseMessages_es-AHBxl8Ka.js +0 -1
- package/dist-embed-sighting/CaseMessages_fr-CD33PQCH.js +0 -1
- package/dist-embed-sighting/CaseMessages_it-DyMACGSU.js +0 -1
- package/dist-embed-sighting-editor/CaseElement-DzwFIDZZ.js +0 -100
- package/dist-embed-sighting-editor/CaseMessages_en-BbbbikHH.js +0 -1
- package/dist-embed-sighting-editor/CaseMessages_es-AHBxl8Ka.js +0 -1
- package/dist-embed-sighting-editor/CaseMessages_fr-CD33PQCH.js +0 -1
- package/dist-embed-sighting-editor/CaseMessages_it-DyMACGSU.js +0 -1
- package/dist-embed-sighting-editor/ModuleThree-Fvr5G-Yh.js +0 -1
- package/dist-embed-ufoathome/CaseElement-Ch0QzF7-.js +0 -100
- package/dist-embed-ufoathome/CaseMessages_en-BbbbikHH.js +0 -1
- package/dist-embed-ufoathome/CaseMessages_es-AHBxl8Ka.js +0 -1
- package/dist-embed-ufoathome/CaseMessages_fr-CD33PQCH.js +0 -1
- package/dist-embed-ufoathome/CaseMessages_it-DyMACGSU.js +0 -1
package/dist-embed-ufoathome/{surroundingsSources-CVKKb8h6.js → surroundingsSources-DEMGw8rm.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as B}from"./rr0-ufoathome.mjs";import{x as V,cP as tt,cQ as q,y as j,cR as C,cS as X,cT as et}from"./ShareDialogElement-DLr5u_tk.js";import{l as ot}from"./SaidPosition-CWiVNaNW.js";import"./Sighting-CBpJpdm9.js";import"./VisualAids-DI-hEL46.js";import"./Decor-Dn-cvniW.js";import"./RecordingIssue-BlWT8Xsu.js";import"./Obstacles-v9SkfBD7.js";class I{constructor(t){this.survey=t}static CACHE_NAME="rr0-surroundings";static MAX_AGE_MS=720*3600*1e3;static FORMAT=8;static MAX_STORED=400;static asked=new Map;get id(){return this.survey.id}get name(){return this.survey.name}get attribution(){return this.survey.attribution}get creditUrl(){return this.survey.creditUrl}get contemporary(){return this.survey.contemporary}covers(t,e){return this.survey.covers(t,e)}async getSurroundings(t,e){const s=I.key(this.survey.id,t,e);let o=I.asked.get(s);return o===void 0&&(o=this.recalled(s,t,e),I.asked.set(s,o),o.catch(()=>I.asked.delete(s))),structuredClone(await o)}later(t,e){const s=this.survey.later?.(t,e);if(!s)return;const o=I.key(this.survey.id,t,e);return s.then(n=>{const a=I.partial.get(o);if(a){I.partial.delete(o);const{incomplete:r,...i}=a,h=[...a.credits??[],...n.credits??[]].filter((l,f,M)=>M.findIndex(d=>d.url===l.url)===f),c={...i,...n,dates:{...a.dates,...n.dates},...h.length>0?{credits:h}:{}};I.asked.set(o,Promise.resolve(c)),I.openCache().then(l=>l&&I.store(l,I.request(o),c))}return structuredClone(n)})}static partial=new Map;static forget(){I.partial.clear(),I.asked.clear()}static key(t,e,s){return`${t}/v${I.FORMAT}/${e.lat.toFixed(5)}/${e.lng.toFixed(5)}/${Math.round(s)}`}async recalled(t,e,s){const o=await I.openCache(),n=I.request(t);if(o)try{const r=await o.match(n);if(r){const{savedAt:i,surroundings:h}=await r.json();if(Date.now()-i<I.MAX_AGE_MS)return h;await o.delete(n)}}catch{}const a=await this.survey.getSurroundings(e,s);return a.incomplete?(I.asked.delete(t),I.partial.set(t,structuredClone(a)),a):(o&&I.store(o,n,a),a)}static async store(t,e,s){try{const o={savedAt:Date.now(),surroundings:s};await t.put(e,new Response(JSON.stringify(o),{headers:{"Content-Type":"application/json"}}));const n=await t.keys();for(const a of n.slice(0,Math.max(0,n.length-I.MAX_STORED)))await t.delete(a)}catch{}}static async openCache(){try{return typeof caches>"u"?void 0:await caches.open(I.CACHE_NAME)}catch{return}}static request(t){const e=typeof location>"u"?"http://localhost":location.origin;return new Request(`${e}/__surroundings__/${encodeURIComponent(t)}`)}}class st{constructor(t){if(this.candidates=t,t.length===0)throw new Error("A survey needs at least one candidate");this.current=t[0]}current;get id(){return this.current.id}get name(){return this.current.name}get attribution(){return this.current.attribution}get creditUrl(){return this.current.creditUrl}get contemporary(){return this.current.contemporary}covers(t,e){return this.candidates.some(s=>s.covers(t,e))}async getSurroundings(t,e){let s;for(const o of this.candidates)if(o.covers(t.lat,t.lng))try{const n=await o.getSurroundings(t,e);return this.current=o,n}catch(n){if(s??=n,!(n instanceof V))throw n}throw s??new V("no-coverage","No survey reaches this place")}later(t,e){return this.current.later?.(t,e)}}class D{constructor(t,e,s,o){this.heights=t,this.building=e,this.width=s,this.height=o}static ROOF_PERCENTILE=.9;static STEP_M=.9;static RECTANGLE_FILL=.72;static MIN_DEPTH_M=2.5;static MAX_PARTS=24;static MAX_CELLS=640;buildings(t){const e=t.metresPerPixel,s=t.minAreaM2??12,o=new Uint8Array(this.width*this.height),n=[];for(let a=0;a<this.building.length;a++){if(!this.building[a]||o[a])continue;const r=this.patchFrom(a,o);if(!(r.length*e*e<s))for(const i of this.buildingsOf(r,e,s))Math.hypot(i.eastM,i.northM)<=t.radiusM&&n.push(i)}return n.sort((a,r)=>Math.hypot(a.eastM,a.northM)-Math.hypot(r.eastM,r.northM)),n.slice(0,t.maxBuildings??60)}patchFrom(t,e){const s=[],o=[t];for(e[t]=1;o.length>0;){const n=o.pop();s.push(n);const a=n%this.width,r=Math.floor(n/this.width);for(const[i,h]of[[1,0],[-1,0],[0,1],[0,-1]]){const c=a+i,l=r+h;if(c<0||l<0||c>=this.width||l>=this.height)continue;const f=l*this.width+c;this.building[f]&&!e[f]&&Math.abs(this.heights[f]-this.heights[n])<=D.STEP_M&&(e[f]=1,o.push(f))}}return s}buildingsOf(t,e,s){const o=this.width/2,n=this.height/2,a=[],r=[],i=[];for(const h of t){const c=h%this.width,l=Math.floor(h/this.width);a.push((c+.5-o)*e),r.push((n-l-.5)*e),i.push(this.heights[h])}return D.ofPoints(a,r,i,e,s)}static ofPoints(t,e,s,o,n,a=D.RECTANGLE_FILL,r=[]){const i=[];for(let m=0;m<t.length;m++)for(const[E,v]of[[-.5,-.5],[.5,-.5],[-.5,.5],[.5,.5]])i.push([t[m]+E*o,e[m]+v*o]);const h=D.hull(i),{angle:c,rectangle:l}=D.smallestRectangle(h),f=t.length*o*o,M=(l.maxU-l.minU)*(l.maxV-l.minV);if(f/M>=a||f<4*n)return[D.building(l,c,D.roof(s))];const d=h.map((m,E)=>({from:{east:m[0],north:m[1]},to:{east:h[(E+1)%h.length][0],north:h[(E+1)%h.length][1]}})),g=D.dominantAngles([...r,...d]);return D.parts(t,e,s,g.length>0?g:[c],o,n)}static dominantAngles(t,e=3){const s=new Map;for(const o of t){const n=Math.hypot(o.to.east-o.from.east,o.to.north-o.from.north);if(n<1e-6)continue;const a=(Math.atan2(o.to.north-o.from.north,o.to.east-o.from.east)%(Math.PI/2)+Math.PI/2)%(Math.PI/2),r=Math.round(a/(Math.PI/60));s.set(r,(s.get(r)??0)+n)}return[...s.entries()].sort((o,n)=>n[1]-o[1]).slice(0,e).map(([o])=>o*Math.PI/60)}static parts(t,e,s,o,n,a){let r=t.map((h,c)=>c);const i=[];for(let h=0;h<D.MAX_PARTS&&r.length>0;h++){let c;for(const M of o){const d=D.largestIn(t,e,r,M,n);d&&(c===void 0||d.area>c.area)&&(c=d)}if(c===void 0||c.area<a)break;const l=c.covered;Math.min(c.rectangle.maxU-c.rectangle.minU,c.rectangle.maxV-c.rectangle.minV)>=D.MIN_DEPTH_M&&i.push(D.building(c.rectangle,c.angle,D.roof([...l].map(M=>s[M])))),r=r.filter(M=>!l.has(M))}return i}static largestIn(t,e,s,o,n){const a=Math.cos(o),r=Math.sin(o);let i=1/0,h=-1/0,c=1/0,l=-1/0;const f=[],M=[];for(const A of s){const y=t[A]*a+e[A]*r,N=-t[A]*r+e[A]*a;f.push(y),M.push(N),i=Math.min(i,y),h=Math.max(h,y),c=Math.min(c,N),l=Math.max(l,N)}const d=Math.max(n*Math.SQRT2,Math.max(h-i,l-c)/D.MAX_CELLS),g=Math.max(1,Math.ceil((h-i)/d+1e-9)),m=Math.max(1,Math.ceil((l-c)/d+1e-9)),E=new Uint8Array(g*m),v=s.map((A,y)=>{const N=Math.min(g-1,Math.max(0,Math.floor((f[y]-i)/d))),x=Math.min(m-1,Math.max(0,Math.floor((M[y]-c)/d)));return E[x*g+N]=1,x*g+N}),w=D.largestRectangle(E,g,m);if(w===void 0)return;const p=new Set;return s.forEach((A,y)=>{const N=v[y]%g,x=Math.floor(v[y]/g);N>=w.column&&N<w.column+w.columns&&x>=w.row&&x<w.row+w.rows&&p.add(A)}),{area:w.area*d*d,angle:o,covered:p,rectangle:{minU:i+w.column*d,maxU:i+(w.column+w.columns)*d,minV:c+w.row*d,maxV:c+(w.row+w.rows)*d}}}static largestRectangle(t,e,s){const o=new Array(e).fill(0);let n;for(let a=0;a<s;a++){for(let i=0;i<e;i++)o[i]=t[a*e+i]?o[i]+1:0;const r=[];for(let i=0;i<=e;i++){const h=i===e?0:o[i];for(;r.length>0&&o[r[r.length-1]]>=h;){const c=r.pop(),l=r.length===0?i:i-r[r.length-1]-1,f=o[c]*l;(n===void 0||f>n.area)&&(n={column:i-l,row:a-o[c]+1,columns:l,rows:o[c],area:f})}r.push(i)}}return n}static roof(t){const e=[...t].sort((s,o)=>s-o);return Math.max(2,e[Math.min(e.length-1,Math.floor(e.length*D.ROOF_PERCENTILE))])}static building(t,e,s){const o=Math.cos(e),n=Math.sin(e),a=t.maxU-t.minU,r=t.maxV-t.minV,i=(t.minU+t.maxU)/2,h=(t.minV+t.maxV)/2,l=((90-(a<r?e:e+Math.PI/2)*180/Math.PI)%180+180)%180;return{eastM:D.tenth(i*o-h*n),northM:D.tenth(i*n+h*o),widthM:D.tenth(Math.max(a,r)),lengthM:D.tenth(Math.min(a,r)),heightM:D.tenth(s),headingDeg:Math.round(l*10)/10}}static smallestRectangle(t){let e={area:1/0,angle:0,rectangle:{minU:0,maxU:0,minV:0,maxV:0}};for(let s=0;s<Math.max(1,t.length);s++){const[o,n]=t[s]??[0,0],[a,r]=t[(s+1)%t.length]??[1,0],i=Math.atan2(r-n,a-o),h=Math.cos(i),c=Math.sin(i);let l=1/0,f=-1/0,M=1/0,d=-1/0;for(const[m,E]of t){const v=m*h+E*c,w=-m*c+E*h;l=Math.min(l,v),f=Math.max(f,v),M=Math.min(M,w),d=Math.max(d,w)}const g=(f-l)*(d-M);g<e.area&&(e={area:g,angle:i,rectangle:{minU:l,maxU:f,minV:M,maxV:d}})}return e}static hull(t){const e=[...t].sort((r,i)=>r[0]-i[0]||r[1]-i[1]),s=e.filter((r,i)=>i===0||r[0]!==e[i-1][0]||r[1]!==e[i-1][1]);if(s.length<3)return s;const o=(r,i,h)=>(i[0]-r[0])*(h[1]-r[1])-(i[1]-r[1])*(h[0]-r[0]),n=[];for(const r of s){for(;n.length>=2&&o(n[n.length-2],n[n.length-1],r)<=0;)n.pop();n.push(r)}const a=[];for(const r of[...s].reverse()){for(;a.length>=2&&o(a[a.length-2],a[a.length-1],r)<=0;)a.pop();a.push(r)}return[...n.slice(0,-1),...a.slice(0,-1)]}static tenth(t){return Math.round(t*10)/10}}class H{constructor(t,e,s,o){this.heights=t,this.vegetation=e,this.width=s,this.height=o}static SUMMIT_RADIUS_M=2.5;static CROWN_REACH_M=8;static MAX_WIDTH_M=16;static MIN_WIDTH_M=2;static tenth(t){return Math.round(t*10)/10}trees(t){const e=t.metresPerPixel,s=t.minHeightM??4,o=t.eyeM??1.6,n=t.minElevationDeg??2,a=Math.max(1,Math.round(H.SUMMIT_RADIUS_M/e)),r=Math.round(H.CROWN_REACH_M/e),i=this.width/2,h=this.height/2,c=[];for(let l=0;l<this.height;l++)for(let f=0;f<this.width;f++){const M=this.canopy(f,l);if(M<s)continue;const d=(f+.5-i)*e,g=(h-l-.5)*e,m=Math.hypot(d,g);if(m>t.radiusM||!this.isSummit(f,l,M,a))continue;const E=Math.atan2(M-o,Math.max(m,1))*180/Math.PI;E<n||c.push({tree:{eastM:H.tenth(d),northM:H.tenth(g),heightM:H.tenth(M),widthM:H.tenth(this.crownWidth(f,l,M,e,r))},elevation:E})}return c.sort((l,f)=>f.elevation-l.elevation),c.slice(0,t.maxTrees??150).map(l=>l.tree)}canopy(t,e){if(t<0||e<0||t>=this.width||e>=this.height)return 0;const s=e*this.width+t;return this.vegetation[s]?this.heights[s]:0}isSummit(t,e,s,o){for(let n=-o;n<=o;n++)for(let a=-o;a<=o;a++){if(a===0&&n===0)continue;const r=this.canopy(t+a,e+n);if(r>s||r===s&&(n<0||n===0&&a<0))return!1}return!0}crownWidth(t,e,s,o,n){let a=0;for(let i=-n;i<=n;i++)for(let h=-n;h<=n;h++)Math.hypot(h,i)*o<=H.CROWN_REACH_M&&this.canopy(t+h,e+i)>=s*.5&&a++;const r=2*Math.sqrt(a*o*o/Math.PI);return Math.max(H.MIN_WIDTH_M,Math.min(r,H.MAX_WIDTH_M))}}class _{static WALLS={1:"stone",2:"meuliere",3:"concrete",4:"brick",5:"block",6:"wood",9:"other"};static ROOFS={1:"tile",2:"slate",3:"zinc",4:"concrete",9:"other"};static WALL_COLOURS={stone:"#b9ae9b",meuliere:"#b8a78a",concrete:"#b4b2ac",brick:"#a65f48",block:"#d0c6b2",wood:"#7d5c3e",other:"#c9c0ae"};static PLASTER="#d3cab8";static ROOF_COLOURS={tile:"#a0583f",slate:"#4a5059",zinc:"#8d969c",concrete:"#8f8e8a",other:"#7a7872"};static VARIATION=.12;static OLD_ROOF="#7d858c";static OLD_STOREY_M=3.6;static GRAND_STOREY_M=4.5;static MIN_STOREY_M=2.4;static MAX_STOREY_M=6;static of(t,e){const s=String(t??"").trim();if(!/^\d{1,2}$/.test(s))return;const o=Number(s),n=o%10!==0?o%10:Math.floor(o/10);return(e==="wall"?_.WALLS:_.ROOFS)[String(n)]}static roofColor(t){return t?_.ROOF_COLOURS[t]:void 0}static fit(t){return t.map(e=>{const s=e.style,o={...e.facade,color:e.facade?.color??_.wallColor(e)};s==="church"?o.openings="lancet":s==="monument"||s==="works"?o.openings="plain":(s==="old"||s==="grand")&&(o.openings="tall"),e.closedAtNight&&o.openings!=="plain"&&(o.closedAtNight=!0);const n=_.storeyOf(e);n!==void 0&&s!=="church"&&s!=="monument"&&(o.storeyM=n);const a=s==="old"&&e.roof?.color===void 0?{shape:"flat",riseM:0,...e.roof,color:_.OLD_ROOF}:e.roof;return{...e,facade:o,...a?{roof:a}:{}}})}static storeyOf(t){const e=t.heightM-(t.roof?.riseM??0);if(t.floors&&t.floors>0){const s=e/t.floors;if(s>=_.MIN_STOREY_M&&s<=_.MAX_STOREY_M)return Math.round(s*100)/100}return t.style==="old"?_.OLD_STOREY_M:t.style==="grand"?_.GRAND_STOREY_M:void 0}static wallColor(t){const e=t.style==="church"||t.style==="monument"||t.style==="old",s=t.wallMaterial?_.WALL_COLOURS[t.wallMaterial]:e?_.WALL_COLOURS.stone:_.PLASTER,o=Math.sin(t.eastM*12.9898+t.northM*78.233)*43758.5453,n=1+(o-Math.floor(o)-.5)*2*_.VARIATION,a=r=>Math.max(0,Math.min(255,Math.round(parseInt(s.slice(r,r+2),16)*n))).toString(16).padStart(2,"0");return`#${a(1)}${a(3)}${a(5)}`}}class R{static MIN_RISE_M=1.2;static MIN_EAVES_M=2.5;static MIN_SEEN=.35;static NO_DATA=-9999;static BANDS=7;static INSET_M=.9;static LIFT=1.18;static PEAK=.3;static LEVEL=.45;static fit(t,e,s){return!e&&!s&&!t.some(o=>o.roofMaterial)?t:t.map(o=>{const n=e?R.shapeOf(o,e):void 0,a=(s?R.colorOf(o,s):void 0)??_.roofColor(o.roofMaterial);if(!n&&!a)return o;const r={shape:n?.shape??"flat",...n?.ridge==="depth"?{ridge:"depth"}:{},riseM:n?.riseM??0,...a?{color:a}:{}},i=n&&n.shape!=="flat"?n.topM:o.heightM;return{...o,heightM:i,roof:r}})}static world(t,e,s){const o=t.headingDeg*Math.PI/180;return{east:t.eastM+e*Math.cos(o)+s*Math.sin(o),north:t.northM-e*Math.sin(o)+s*Math.cos(o)}}static shapeOf(t,e){const s=R.BANDS,o=Math.max(e.metresPerPixel,.5),n=t.widthM/2-R.INSET_M,a=t.lengthM/2-R.INSET_M;if(n<=0||a<=0)return;const r=[],i=Array.from({length:s},()=>({sum:0,n:0})),h=Array.from({length:s},()=>({sum:0,n:0}));let c=0;for(let y=-n;y<=n;y+=o)for(let N=-a;N<=a;N+=o){c++;const{east:x,north:$}=R.world(t,y,N),z=Math.floor(x/e.metresPerPixel+e.size/2),Y=Math.floor(e.size/2-$/e.metresPerPixel);if(z<0||Y<0||z>=e.size||Y>=e.size)continue;const k=Y*e.size+z,P=e.heights[k];if(e.vegetation[k]||P===R.NO_DATA||!(P>0))continue;r.push(P);const J=i[Math.min(s-1,Math.floor((y+n)/(2*n)*s))],Q=h[Math.min(s-1,Math.floor((N+a)/(2*a)*s))];J.sum+=P,J.n++,Q.sum+=P,Q.n++}if(c===0||r.length/c<R.MIN_SEEN)return;r.sort((y,N)=>y-N);const l=R.percentile(r,.08),f=R.percentile(r,.92),M=f-l;if(l<R.MIN_EAVES_M||M>Math.min(t.widthM,t.lengthM))return;if(M<R.MIN_RISE_M)return{shape:"flat",riseM:0,topM:f};const d=R.profile(i),g=R.profile(h);if(!d||!g)return;const m=R.peak(g)/M,E=R.peak(d)/M,v=R.spread(d)/M,w=R.spread(g)/M,p=m>=R.PEAK&&v<=R.LEVEL,A=E>=R.PEAK&&w<=R.LEVEL;if(p&&(!A||m>=E))return{shape:"gable",ridge:"width",riseM:M,topM:f};if(A)return{shape:"gable",ridge:"depth",riseM:M,topM:f};if(m>=R.PEAK&&E>=R.PEAK/2)return{shape:"hip",ridge:"width",riseM:M,topM:f}}static profile(t){const e=t.map(s=>s.n>0?s.sum/s.n:NaN);return e.filter(Number.isFinite).length>=t.length-1?e.map((s,o)=>Number.isFinite(s)?s:R.neighbour(e,o)):void 0}static neighbour(t,e){return Number.isFinite(t[e-1])?t[e-1]:t[e+1]}static peak(t){const e=Math.max(1,Math.floor(t.length/3)),s=n=>n.reduce((a,r)=>a+r,0)/n.length,o=[...t.slice(0,e),...t.slice(t.length-e)];return s(t.slice(e,t.length-e))-s(o)}static spread(t){return Math.max(...t)-Math.min(...t)}static percentile(t,e){return t[Math.min(t.length-1,Math.floor(t.length*e))]}static colorOf(t,e){const s=Math.max(e.metresPerPixel,.5),o=Math.max(t.widthM/2-R.INSET_M,s),n=Math.max(t.lengthM/2-R.INSET_M,s),a=[],r=[],i=[];for(let l=-o;l<=o;l+=s)for(let f=-n;f<=n;f+=s){const{east:M,north:d}=R.world(t,l,f),g=Math.floor(M/e.metresPerPixel+e.size/2),m=Math.floor(e.size/2-d/e.metresPerPixel);if(g<0||m<0||g>=e.size||m>=e.size)continue;const E=(m*e.size+g)*e.samples,v=e.values[E],w=e.values[E+1],p=e.values[E+2];w>v&&w>p||(a.push(v),r.push(w),i.push(p))}if(a.length===0)return;const h=l=>l.sort((f,M)=>f-M)[Math.floor(l.length/2)],c=l=>Math.min(255,Math.round(l*R.LIFT)).toString(16).padStart(2,"0");return`#${c(h(a))}${c(h(r))}${c(h(i))}`}}class G{static DEFAULT_HEIGHT_M=6;static METRES_PER_DEGREE=111320;static STREET_SPACING_M=35;static KERB_OFFSET_M=1;static DEFAULT_WIDTH_M=5.5;static PATIENCE_MS=15e3;static MAX=150;static lampsFrom(t,e,s){const o=[],n=new Set;for(const r of t.elements??[]){if(r.id!==void 0){const l=`${r.type}/${r.id}`;if(n.has(l))continue;n.add(l)}if(r.type==="way"){r.tags?.lit==="yes"&&G.alongStreet(r,e,o);continue}if(r.tags?.highway!=="street_lamp"||typeof r.lat!="number"||typeof r.lon!="number")continue;const i=(r.lon-e.lng)*G.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180),h=(r.lat-e.lat)*G.METRES_PER_DEGREE;if(Math.hypot(i,h)>s)continue;const c=Number.parseFloat(r.tags?.height??"");o.push({eastM:Math.round(i*10)/10,northM:Math.round(h*10)/10,...Number.isFinite(c)&&c>=2&&c<=20?{heightM:c}:{}})}const a=o.filter(r=>Math.hypot(r.eastM,r.northM)<=s);return o.length=0,o.push(...a),o.sort((r,i)=>Math.hypot(r.eastM,r.northM)-Math.hypot(i.eastM,i.northM)),o.slice(0,G.MAX)}static alongStreet(t,e,s){const o=t.geometry;if(!o||o.length<2)return;const n=d=>[(d.lon-e.lng)*G.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180),(d.lat-e.lat)*G.METRES_PER_DEGREE],a=o.map(n),r=Number.parseFloat(t.tags?.width??""),i=Number.parseInt(t.tags?.lanes??"",10),c=(Number.isFinite(r)&&r>0?r:Number.isFinite(i)&&i>0?i*3.5:G.DEFAULT_WIDTH_M)/2+G.KERB_OFFSET_M;let l=1,f=G.STREET_SPACING_M/2,M=0;for(let d=1;d<a.length;d++){const[g,m]=a[d-1],[E,v]=a[d],w=Math.hypot(E-g,v-m);if(w===0)continue;const p=(E-g)/w,A=(v-m)/w;for(;f<=M+w;f+=G.STREET_SPACING_M){const y=f-M;s.push({eastM:Math.round((g+p*y+A*c*l)*10)/10,northM:Math.round((m+A*y-p*c*l)*10)/10,supposed:!0}),l=-l}M+=w}}}class u{constructor(t={},e=[],s=[]){this.lampSources=e,this.signalSources=s,this.client=new tt(t)}static METRES_PER_DEGREE=111320;static KERB_OFFSET_M=.6;static SETBACK_M=.5;static MIN_CROSSING_M=3;static MAX_CROSSING_M=30;static SAME_CROSSING_M=5;static SAME_HEAD_M=2.5;static SAME_HEAD_DEG=45;static MAX_SIGNALS=160;static MAX_CROSSINGS=150;static MAX_SIGNS=100;static ROADS=new Set([...q.DRIVABLE,"living_street","busway","road"]);static ON_ROAD="^(traffic_signals|crossing|stop|give_way)$";static CREDIT={name:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL"};client;local(t,e){const s=u.boxOf(t,e),o=(r,i)=>{if(!r)return Promise.resolve(void 0);const h=`${r.credit.url} ${s}`;let c=u.localPending.get(h);return c||(c=i().then(l=>({credit:r.credit,found:l}),()=>{u.localPending.delete(h)}),u.localPending.set(h,c)),c},n=this.lampSources.find(r=>r.covers(t.lat,t.lng)),a=this.signalSources.find(r=>r.covers(t.lat,t.lng));return Promise.all([o(n,()=>n.lampsNear(t,e)),o(a,()=>a.signalsNear(t,e))]).then(([r,i])=>({lamps:r,signals:i}))}static localPending=new Map;static withLocal(t,e){const s=e?.lamps?e.lamps.found:t.lamps,o=e?.signals?e.signals.found:t.signals,a=[...u.found({crossings:t.crossings,signs:t.signs,...e?.lamps?{}:{lamps:s},...e?.signals?{}:{signals:o}})?[u.CREDIT]:[],...e?.lamps&&e.lamps.found.length>0?[e.lamps.credit]:[],...e?.signals&&e.signals.found.length>0?[e.signals.credit]:[]],{lamps:r,signals:i,credits:h,...c}=t;return{...c,...s?.length?{lamps:s}:{},...o?.length?{signals:o}:{},...a.length>0?{credits:a}:{}}}static today(){return new Date().toISOString().slice(0,10)}static later(t,e,s){return t?.answered(e,s).then(o=>({...o,...u.found(o)?{dates:{lamps:u.today()}}:{}}))}static found(t){return!!(t?.lamps?.length||t?.signals?.length||t?.crossings?.length||t?.signs?.length)}static query(t){const e=u.ON_ROAD;return`[out:json][timeout:25];(node["highway"="street_lamp"](${t});way["highway"]["lit"="yes"](${t});node["highway"~"${e}"](${t});node["traffic_sign"](${t});way["footway"="crossing"](${t}););out geom;(node._["highway"~"${e}"];node._["traffic_sign"];)->.kerb;way(bn.kerb)["highway"];out geom;`}static pending=new Map;async near(t,e){const s=this.ask(u.boxOf(t,e)),o=this.local(t,e);let n;const a=Symbol("late"),r=new Promise(i=>{n=setTimeout(()=>i(a),G.PATIENCE_MS)});try{const[i,h]=await Promise.all([Promise.race([s,r]),Promise.race([o,r])]),c=h===a?void 0:h;return i===a||i===void 0?{...u.withLocal({},c),incomplete:!0}:u.withLocal(u.from(i,t,e),c)}finally{clearTimeout(n)}}static RETRY_DELAYS_MS=[15e3,6e4,18e4,6e5];async answered(t,e){const s=u.boxOf(t,e);for(let o=0;;o++){const n=await this.ask(s);if(n)return u.withLocal(u.from(n,t,e),await this.local(t,e));if(o>=u.RETRY_DELAYS_MS.length)throw new Error("Overpass did not answer");await new Promise(a=>setTimeout(a,u.RETRY_DELAYS_MS[o]))}}ask(t){let e=u.pending.get(t);return e||(e=this.client.query(u.query(t)).catch(()=>{u.pending.delete(t)}),u.pending.set(t,e)),e}static boxOf(t,e){const s=e/u.METRES_PER_DEGREE,o=e/(u.METRES_PER_DEGREE*Math.cos(t.lat*Math.PI/180));return[t.lat-s,t.lng-o,t.lat+s,t.lng+o].map(n=>n.toFixed(6)).join(",")}static forget(){u.pending.clear(),u.localPending.clear()}static from(t,e,s){const o=G.lampsFrom(t,e,s),n=Math.cos(e.lat*Math.PI/180),a=(p,A)=>[(A-e.lng)*u.METRES_PER_DEGREE*n,(p-e.lat)*u.METRES_PER_DEGREE],r=(p,A)=>`${p.toFixed(7)},${A.toFixed(7)}`,i=new Map,h=new Set,c=[],l=[];for(const p of t.elements??[]){if(p.type==="node"){typeof p.lat=="number"&&typeof p.lon=="number"&&l.push(p);continue}if(p.type!=="way"||!p.geometry||p.geometry.length<2)continue;if(p.id!==void 0){if(h.has(p.id))continue;h.add(p.id)}const A=p.tags??{};if(A.footway==="crossing"&&c.push(p),!u.ROADS.has(A.highway??""))continue;const y=p.geometry.map(N=>a(N.lat,N.lon));p.geometry.forEach((N,x)=>{const $=r(N.lat,N.lon);i.set($,[...i.get($)??[],{way:p,points:y,index:x}])})}const f=[],M=[],d=[],g=new Set;for(const p of l){if(p.id!==void 0){if(g.has(p.id))continue;g.add(p.id)}const A=p.tags??{},y=a(p.lat,p.lon),N=i.get(r(p.lat,p.lon))??[],x=A.highway;if(x==="traffic_signals")for(const k of u.approaches(N,u.directionOf(A),!1))f.push(u.head(y,k,"vehicles"));if(x==="crossing"||x==="traffic_signals"&&A.crossing!==void 0){const k=N[0];if(k&&u.marked(A)){const P=u.directionAt(k);P&&M.push({eastM:u.round(y[0]),northM:u.round(y[1]),headingDeg:u.heading(P),widthM:q.widthOf(k.way.tags??{})}),P&&(A.crossing==="traffic_signals"||A["crossing:signals"]==="yes")&&f.push(...u.pedestrianHeads(y,P,k))}}if(x==="traffic_signals")continue;const $=x==="stop"?{face:"stop"}:x==="give_way"?{face:"give-way"}:u.faceOf(A);if(!$)continue;const z=A.traffic_sign?{code:A.traffic_sign}:{};if(N.length>0){const k=u.approaches(N,u.directionOf(A),!0)[0];if(k){const P=u.head(y,k,"vehicles");d.push({eastM:P.eastM,northM:P.northM,headingDeg:P.headingDeg,...$,...z})}continue}const Y=u.compassOf(A.direction);Y!==void 0&&d.push({eastM:u.round(y[0]),northM:u.round(y[1]),headingDeg:(Y+180)%360,...$,...z})}for(const p of c){const A=u.crossingAlong(p,a);A&&!M.some(y=>Math.hypot(y.eastM-A.eastM,y.northM-A.northM)<u.SAME_CROSSING_M)&&M.push(A)}const m=f.filter((p,A)=>!f.slice(0,A).some(y=>y.for===p.for&&Math.hypot(y.eastM-p.eastM,y.northM-p.northM)<u.SAME_HEAD_M&&Math.abs((y.headingDeg-p.headingDeg+540)%360-180)<u.SAME_HEAD_DEG)),E=(p,A)=>p.filter(y=>Math.hypot(y.eastM,y.northM)<=s).sort((y,N)=>Math.hypot(y.eastM,y.northM)-Math.hypot(N.eastM,N.northM)).slice(0,A),v={};o.length>0&&(v.lamps=o);const w={signals:E(m,u.MAX_SIGNALS),crossings:E(M,u.MAX_CROSSINGS),signs:E(d,u.MAX_SIGNS)};return w.signals.length>0&&(v.signals=w.signals),w.crossings.length>0&&(v.crossings=w.crossings),w.signs.length>0&&(v.signs=w.signs),v}static approaches(t,e,s){const o=[];for(const a of t){const r=a.way.tags??{},i=r.oneway==="yes"||r.oneway==="true"||r.oneway==="1"||r.junction==="roundabout"||r.highway==="motorway",h=r.oneway==="-1",{points:c,index:l}=a,f=(d,g)=>{let m=0;for(let E=Math.min(d,g);E<Math.max(d,g);E++)m+=Math.hypot(c[E+1][0]-c[E][0],c[E+1][1]-c[E][1]);return m},M=d=>{const g=c[l][0]-c[d][0],m=c[l][1]-c[d][1],E=Math.hypot(g,m);return E>0?[g/E,m/E]:void 0};if(l>0&&!h){const d=M(l-1);d&&o.push({approach:{unit:d,road:a},toEndM:f(l,c.length-1),forward:!0})}if(l<c.length-1&&!i){const d=M(l+1);d&&o.push({approach:{unit:d,road:a},toEndM:f(0,l),forward:!1})}}const n=e!==void 0&&t.length===1?o.filter(a=>a.forward===(e==="forward")):o;return!s||n.length<=1?n.map(a=>a.approach):[n.reduce((a,r)=>r.toEndM<a.toEndM?r:a).approach]}static head(t,e,s){const[o,n]=e.unit,a=q.widthOf(e.road.way.tags??{})/2+u.KERB_OFFSET_M,r=u.SETBACK_M,i=u.heading(e.unit);return{eastM:u.round(t[0]-o*r+n*a),northM:u.round(t[1]-n*r-o*a),headingDeg:(i+180)%360,for:s,phase:j.phaseOf(i)}}static pedestrianHeads(t,e,s){const o=q.widthOf(s.way.tags??{})/2+u.KERB_OFFSET_M,n=u.heading(e),a=j.phaseOf(n);return[1,-1].map(r=>({eastM:u.round(t[0]+e[1]*o*r),northM:u.round(t[1]-e[0]*o*r),headingDeg:(n+(r===1?270:90))%360,for:"pedestrians",phase:a}))}static crossingAlong(t,e){if(!u.marked(t.tags??{}))return;const s=t.geometry.map(h=>e(h.lat,h.lon)),[o,n]=s[0],[a,r]=s[s.length-1],i=Math.hypot(a-o,r-n);if(!(i<u.MIN_CROSSING_M))return{eastM:u.round((o+a)/2),northM:u.round((n+r)/2),headingDeg:(u.heading([(a-o)/i,(r-n)/i])+90)%360,widthM:Math.round(Math.min(i,u.MAX_CROSSING_M)*10)/10}}static marked(t){const e=t.crossing;return e!=="unmarked"&&e!=="no"&&e!=="informal"&&t["crossing:markings"]!=="no"}static directionAt(t){const{points:e,index:s}=t,[o,n]=s<e.length-1?[e[s],e[s+1]]:[e[s-1],e[s]],a=Math.hypot(n[0]-o[0],n[1]-o[1]);return a>0?[(n[0]-o[0])/a,(n[1]-o[1])/a]:void 0}static directionOf(t){const e=t["traffic_signals:direction"]??t["traffic_sign:direction"]??t.direction;return e==="forward"||e==="backward"?e:void 0}static compassOf(t){if(t===void 0)return;const e=Number.parseFloat(t);if(Number.isFinite(e)&&/^\s*-?\d/.test(t))return(e%360+360)%360;const o=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"].indexOf(t.trim().toUpperCase());return o<0?void 0:o*22.5}static faceOf(t){const e=t.traffic_sign;if(!e||e==="no"||e==="none")return;const s=e.split(/[;,]/).map(o=>o.trim());if(s.some(o=>/stop|:AB4\b|:206\b|:R1-1\b|:B2\b/i.test(o)))return{face:"stop"};if(s.some(o=>/give_way|yield|:AB3a\b|:205\b|:R1-2\b|:B1\b/i.test(o)))return{face:"give-way"};for(const o of s){const n=/maxspeed|:B14\b|:274\b|:C14\b|:R2-1\b/i.test(o)?Number.parseInt(/\[(\d+)\]/.exec(o)?.[1]??t.maxspeed??"",10):Number.NaN;if(Number.isFinite(n)&&n>0)return{face:"speed-limit",value:n}}return{face:"other"}}static heading([t,e]){return Math.round((Math.atan2(t,e)*180/Math.PI+360)%360*10)/10}static round(t){return Math.round(t*10)/10}}class nt{id="ign-lidar-hd";name="IGN LiDAR HD";attribution="Canopy and roofs © IGN, LiDAR HD (Licence Ouverte 2.0), as surveyed on a day the service does not give";creditUrl="https://geoservices.ign.fr/lidarhd";contemporary=!0;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","The LiDAR HD survey covers France only");const s=C.lidarRadius(e),[o,n,a,r,i]=await Promise.all([this.platform.lidar(t,s),this.platform.photo(t,s).catch(()=>{}),this.furniture?.near(t,e),this.platform.laserDate(t),this.platform.photoDate(t)]);return{trees:new H(o.heights,o.vegetation,o.size,o.size).trees({metresPerPixel:o.metresPerPixel,radiusM:s}),buildings:_.fit(R.fit(new D(o.heights,o.building,o.size,o.size).buildings({metresPerPixel:o.metresPerPixel,radiusM:s,maxBuildings:300}),o,n)),bridges:[],lines:[],...a,dates:{...r?{laser:r}:{},...n&&i?{photo:i}:{},...u.found(a)?{lamps:u.today()}:{}}}}}class O{static MAP_NATURES={Eglise:"church",Chapelle:"church",Monument:"monument","Tour, donjon":"monument","Fort, blockhaus, casemate":"monument","Arc de triomphe":"monument","Arène ou théâtre antique":"monument",Château:"old","Industriel, agricole ou commercial":"works",Serre:"works",Silo:"works"};static MAP_WORKS=new Set(["Industriel","Agricole","Annexe"]);static MAP_CLOSED_AT_NIGHT=new Set(["Commercial et services","Sportif"]);static OSM_CLOSED_AT_NIGHT=new Set(["retail","commercial","office","supermarket","kiosk","sports_hall","sports_centre","stadium","school","university","college","kindergarten","public","civic","government","train_station","transportation"]);static OSM_BUILDINGS={cathedral:"church",church:"church",chapel:"church",basilica:"church",temple:"church",mosque:"church",synagogue:"church",shrine:"church",religious:"church",castle:"old",palace:"old",fortress:"monument",bunker:"monument",triumphal_arch:"monument",industrial:"works",warehouse:"works",barn:"works",farm_auxiliary:"works",shed:"works",hangar:"works",garage:"works",garages:"works",greenhouse:"works",silo:"works",storage_tank:"works",cowshed:"works",stable:"works",sty:"works",manufacture:"works"};static OSM_HISTORIC={church:"church",chapel:"church",monastery:"old",castle:"old",manor:"old",fort:"monument",tower:"monument",monument:"monument",memorial:"monument",city_gate:"monument"};static OLD_BEFORE=1900;static GRAND_FROM_M=15;static GRAND_UP_TO_M=40;static TOWER_SLENDERNESS=2;static CHURCH_PITCH=.7;static CHURCH_ROOF_OF_WALLS=.35;static CHURCH_ROOF_COLOUR="#5a6068";static ofMap(t){const e=O.year(t.date_d_apparition),o=O.MAP_NATURES[String(t.nature??"")]??(t.usage_1==="Religieux"?"church":void 0)??(O.MAP_WORKS.has(String(t.usage_1??""))?"works":void 0)??O.ofYear(e)??O.grand(t),n=O.MAP_CLOSED_AT_NIGHT.has(String(t.usage_1??""));return{...o?{style:o}:{},...e!==void 0?{builtYear:e}:{},...n?{closedAtNight:!0}:{}}}static ofOsm(t){const e=O.year(t.start_date),s=t.historic&&t.historic!=="no"?O.OSM_HISTORIC[t.historic]??"old":void 0,o=t.amenity==="place_of_worship"?"church":void 0,n=O.OSM_BUILDINGS[t.building??""]??s??o??O.ofYear(e),a=O.OSM_CLOSED_AT_NIGHT.has(t.building??"")||t.shop!==void 0&&t.shop!=="no";return{...n?{style:n}:{},...e!==void 0?{builtYear:e}:{},...a?{closedAtNight:!0}:{}}}static year(t){const e=Number(/\b(\d{4})\b/.exec(String(t??""))?.[1]);return Number.isFinite(e)&&e>=1e3&&e<=2100?e:void 0}static fit(t){return t.map(e=>e.style==="church"?O.church(e):e)}static isTower(t){return t.heightM>=O.TOWER_SLENDERNESS*Math.max(t.widthM,t.lengthM)}static church(t){const e=t.roof?.color??O.CHURCH_ROOF_COLOUR;if(O.isTower(t))return{...t,roof:{shape:"flat",riseM:0,color:e}};if(t.roof&&t.roof.shape!=="flat")return t;const s=Math.round(Math.min(O.CHURCH_PITCH*t.lengthM,O.CHURCH_ROOF_OF_WALLS*t.heightM)*10)/10,o={shape:"gable",riseM:s,color:e};return{...t,heightM:Math.round((t.heightM+s)*10)/10,roof:o}}static ofYear(t){return t!==void 0&&t<O.OLD_BEFORE?"old":void 0}static grand(t){const e=Number(t.hauteur),s=Number(t.nombre_d_etages);if(!(Number.isFinite(s)&&s>0)&&!(t.usage_1==="Résidentiel"||t.date_d_apparition))return e>=O.GRAND_FROM_M&&e<=O.GRAND_UP_TO_M?"grand":void 0}}class b{static METRES_PER_DEGREE=111320;static NAMED_NATURES={Silo:"Silo"};static DEFAULT_HEIGHT_M=6;static FLOOR_HEIGHT_M=3;static FINE_M=.5;static COARSE_M=1;static MAX_CELLS=4e4;static RECTANGLE_FILL=.9;static buildings(t,e,s,o=12,n=300,a=[]){const r=[];for(const h of b.reached(t,a,e,s)){const c=h.feature,l=Number(c.properties.nombre_d_etages),f=Number(c.properties.hauteur),M=Number.isFinite(f)&&f>0?f:Number.isFinite(l)&&l>0?l*b.FLOOR_HEIGHT_M:b.DEFAULT_HEIGHT_M,{style:d,builtYear:g,closedAtNight:m}=O.ofMap(c.properties);for(const E of b.rectanglesOf(h.rings,M,o)){const v=_.of(c.properties.materiaux_des_murs,"wall"),w=_.of(c.properties.materiaux_de_la_toiture,"roof"),p=b.NAMED_NATURES[String(c.properties.nature??"")];r.push({...E,...p?{name:p}:{},...Number.isFinite(l)&&l>0?{floors:l}:{},...v?{wallMaterial:v}:{},...w?{roofMaterial:w}:{},...d?{style:d}:{},...g!==void 0?{builtYear:g}:{},...m?{closedAtNight:m}:{}})}}const i=h=>Math.hypot(h.eastM,h.northM);if(r.length>n){const h=c=>(c.heightM+6)*Math.sqrt(c.widthM*c.lengthM)/Math.max(i(c),50);r.sort((c,l)=>h(l)-h(c)),r.length=n}return r.sort((h,c)=>i(h)-i(c)),r}static named(t,e,s){const o=e.map(n=>({name:typeof n.properties.toponyme=="string"?n.properties.toponyme:"",rings:b.rings(n,s)})).filter(n=>n.name.length>0&&n.rings.length>0);return o.length===0?t:t.map(n=>{const a=o.find(r=>b.inside(n.eastM,n.northM,r.rings));return a?{...n,name:a.name}:n})}static reached(t,e,s,o){const n=t.map(i=>({feature:i,rings:b.rings(i,s)})).filter(i=>i.rings.length>0),a=n.map(i=>b.reach(i.rings)<=o),r=e.filter(i=>typeof i.properties.toponyme=="string"&&i.properties.toponyme.length>0).map(i=>b.rings(i,s)).filter(i=>i.length>0);if(r.length>0){const i=n.map(c=>{const l=c.rings[0],f=l.reduce((d,g)=>d+g.east,0)/l.length,M=l.reduce((d,g)=>d+g.north,0)/l.length;return r.findIndex(d=>b.inside(f,M,d))}),h=new Set(i.filter((c,l)=>c>=0&&a[l]));i.forEach((c,l)=>{h.has(c)&&(a[l]=!0)})}return n.filter((i,h)=>a[h])}static reach(t){if(b.inside(0,0,t))return 0;let e=1/0;for(const s of t)for(let o=0;o+1<s.length;o++){const n=s[o],a=s[o+1],r=a.east-n.east,i=a.north-n.north,h=r*r+i*i>0?Math.max(0,Math.min(1,-(n.east*r+n.north*i)/(r*r+i*i))):0;e=Math.min(e,Math.hypot(n.east+h*r,n.north+h*i))}return e}static inside(t,e,s){let o=0;for(const n of s)for(let a=0;a+1<n.length;a++){const r=n[a],i=n[a+1];r.north<=e!=i.north<=e&&r.east+(e-r.north)/(i.north-r.north)*(i.east-r.east)>t&&o++}return o%2===1}static rings(t,e){const s=t.geometry,o=s.type==="Polygon"?[s.coordinates]:s.type==="MultiPolygon"?s.coordinates:[],n=Math.cos(e.lat*Math.PI/180),a=[];for(const r of o)for(const i of r)a.push(i.map(([h,c])=>({east:(h-e.lng)*b.METRES_PER_DEGREE*n,north:(c-e.lat)*b.METRES_PER_DEGREE})));return a}static rectanglesOf(t,e,s){let o=1/0,n=-1/0,a=1/0,r=-1/0;for(const f of t)for(const M of f)o=Math.min(o,M.east),n=Math.max(n,M.east),a=Math.min(a,M.north),r=Math.max(r,M.north);let i=b.FINE_M;(n-o)*(r-a)/(i*i)>b.MAX_CELLS&&(i=b.COARSE_M);const h=[],c=[];for(let f=a+i/2;f<r;f+=i){const M=[];for(const d of t)for(let g=0;g+1<d.length;g++){const m=d[g],E=d[g+1];m.north<=f!=E.north<=f&&M.push(m.east+(f-m.north)/(E.north-m.north)*(E.east-m.east))}M.sort((d,g)=>d-g);for(let d=0;d+1<M.length;d+=2)for(let g=Math.ceil((M[d]-i/2)/i)*i+i/2;g<M[d+1];g+=i)h.push(g),c.push(f)}if(h.length*i*i<s)return[];const l=t.flatMap(f=>f.slice(0,-1).map((M,d)=>({from:M,to:f[d+1]})));return D.ofPoints(h,c,new Array(h.length).fill(e),i,s,b.RECTANGLE_FILL,l)}}class F{id="ign-lidar-topo";name="IGN LiDAR HD + BD TOPO";attribution="Canopy © IGN, LiDAR HD; buildings, bridges and lines © IGN, BD TOPO (Licence Ouverte 2.0), as surveyed on days the services do not give";creditUrl="https://geoservices.ign.fr/lidarhd";contemporary=!0;static BRIDGE_MARGIN_M=30;static MAX_BRIDGE_WINDOWS=8;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","The IGN's surveys cover France only");const s=C.radius(e),[o,n,a,r,i,h]=await Promise.allSettled([this.platform.lidar(t,s),this.platform.vectors(t,s,!0),this.platform.photo(t,s),this.furniture?.near(t,e)??Promise.resolve(void 0),this.platform.laserDate(t),this.platform.photoDate(t)]),c=C.lidarRadius(s);if(o.status==="rejected"&&n.status==="rejected")throw o.reason;const l=o.status==="fulfilled"?o.value:void 0,f=n.status==="fulfilled"?n.value:void 0,M=f!==void 0&&f.buildings.length===0&&f.bridges.length===0&&f.lines.length===0;if(o.status==="rejected"&&o.reason instanceof V&&o.reason.reason==="no-coverage"&&M)throw o.reason;return{trees:l?new H(l.heights,l.vegetation,l.size,l.size).trees({metresPerPixel:l.metresPerPixel,radiusM:c}):[],buildings:this.roofed(this.buildings(l,f,t,s),l,a.status==="fulfilled"?a.value:void 0),bridges:f?await this.bridges(f,t,s,l?.structures,c):[],lines:f?X.lines(f,t,s,l?.structures):[],...r.status==="fulfilled"?r.value:{},dates:{...o.status==="fulfilled"&&i.status==="fulfilled"&&i.value?{laser:i.value}:{},...a.status==="fulfilled"&&h.status==="fulfilled"&&h.value?{photo:h.value}:{},...f?.mapDate?{map:f.mapDate}:{},...r.status==="fulfilled"&&u.found(r.value)?{lamps:u.today()}:{}}}}async bridges(t,e,s,o,n){const a=X.bridges(t,e,s,o);let r=0;return Promise.all(a.map(async i=>{if(o!==void 0&&Math.hypot(i.eastM,i.northM)+i.lengthM/2<=n)return i;const h=i.lengthM/2+F.BRIDGE_MARGIN_M;if(r++>=F.MAX_BRIDGE_WINDOWS)return i;const c=ot(i.eastM,-i.northM,e.lat,e.lng);try{const l=await this.platform.lidar(c,h),f=X.bridges(t,c,h,l.structures).sort((M,d)=>Math.hypot(M.eastM,M.northM)-Math.hypot(d.eastM,d.northM))[0];return!f||Math.hypot(f.eastM,f.northM)>i.lengthM/2?i:{...f,eastM:X.tenth(f.eastM+i.eastM),northM:X.tenth(f.northM+i.northM)}}catch{return i}}))}roofed(t,e,s){return _.fit(O.fit(R.fit(t,e,s)))}buildings(t,e,s,o){const n=e?b.buildings(e.buildings,s,o,void 0,void 0,e.zones):[],a=n.length>0||t===void 0?n:new D(t.heights,t.building,t.size,t.size).buildings({metresPerPixel:t.metresPerPixel,radiusM:C.lidarRadius(o),maxBuildings:300});return e?b.named(a,e.zones,s):a}}class at{id="ign-bd-topo";name="IGN BD TOPO";attribution="Buildings, bridges and lines © IGN, BD TOPO (Licence Ouverte 2.0), as drawn on a day the service does not give";creditUrl="https://geoservices.ign.fr/bdtopo";contemporary=!0;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","BD TOPO covers France only");const s=C.radius(e),[o,n,a,r]=await Promise.all([this.platform.vectors(t,s,!0),this.platform.photo(t,s).catch(()=>{}),this.furniture?.near(t,e),this.platform.photoDate(t)]);return{trees:[],buildings:_.fit(O.fit(R.fit(b.named(b.buildings(o.buildings,t,s,void 0,void 0,o.zones),o.zones,t),void 0,n))),bridges:X.bridges(o,t,s,void 0),lines:X.lines(o,t,s,void 0),...a,dates:{...o.mapDate?{map:o.mapDate}:{},...n&&r?{photo:r}:{},...u.found(a)?{lamps:u.today()}:{}}}}}class S{static ROOF_SHAPES={flat:"flat",gabled:"gable",gambrel:"gable",saltbox:"gable","half-hipped":"hip",hipped:"hip",pyramidal:"hip",mansard:"hip",round:"gable",dome:"dome",onion:"dome"};static WALL_MATERIALS={brick:"brick",stone:"stone",granite:"stone",sandstone:"stone",limestone:"stone",concrete:"concrete",cement_block:"block",block:"block",wood:"wood",timber_framing:"wood"};static ROOF_MATERIALS={roof_tiles:"tile",tiles:"tile",tile:"tile",slate:"slate",metal:"zinc",zinc:"zinc",tin:"zinc",copper:"zinc",concrete:"concrete",eternit:"other"};static COLOURS={white:"#e8e6e0",grey:"#8c8c8a",gray:"#8c8c8a",black:"#3a3a3a",red:"#a8483a",brown:"#6e4f38",beige:"#d6c9a8",yellow:"#d8c070",orange:"#c9773a",green:"#5f7a52",blue:"#506a8a",tan:"#c0a37a",cream:"#e6dcc0",pink:"#c99a96",silver:"#b4b6b6"};static height(t){const e=Number.parseFloat((t??"").replace(",","."));return Number.isFinite(e)&&e>=2&&e<=500?e:void 0}static levels(t){const e=Number.parseInt(t??"",10);return Number.isFinite(e)&&e>=1&&e<=150?e:void 0}static roofShape(t){return S.ROOF_SHAPES[(t??"").trim().toLowerCase()]}static wallMaterial(t){return S.WALL_MATERIALS[(t??"").trim().toLowerCase()]}static roofMaterial(t){return S.ROOF_MATERIALS[(t??"").trim().toLowerCase()]}static colour(t){const e=(t??"").trim().toLowerCase();return/^#[0-9a-f]{6}$/.test(e)?e:/^#[0-9a-f]{3}$/.test(e)?`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`:S.COLOURS[e]}}class W{id="osm-buildings";name="OpenStreetMap buildings";attribution="Buildings © OpenStreetMap contributors (ODbL), as drawn on the day of the data, which a recording is not";creditUrl="https://www.openstreetmap.org/copyright";contemporary=!0;static MAX_RADIUS_M=1500;static MIN_AREA_M2=12;static MAX_BUILDINGS=300;client;furniture;constructor(t={},e){this.client=new tt(t),this.furniture=e}covers(){return!0}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){const s=Math.min(e,W.MAX_RADIUS_M);let o;try{o=await this.client.query(`[out:json][timeout:30];(way["building"](around:${s},${t.lat},${t.lng});relation["building"]["type"="multipolygon"](around:${s},${t.lat},${t.lng}););out geom;`)}catch(r){throw new V("unreachable",r instanceof Error?r.message:String(r))}const n=await this.furniture?.near(t,e),a=(o.osm3s?.timestamp_osm_base??"").slice(0,10);return{trees:[],buildings:_.fit(O.fit(W.buildings(o,t,s))),bridges:[],lines:[],...n,dates:{.../^\d{4}-\d{2}-\d{2}$/.test(a)?{map:a}:{},...u.found(n)?{lamps:u.today()}:{}}}}static buildings(t,e,s){const o=[];for(const n of t.elements??[]){const a=W.ringsOf(n);if(a.length===0)continue;const r=n.tags??{},i=S.levels(r["building:levels"]),h=S.height(r.height),c={geometry:{type:"Polygon",coordinates:a},properties:{...h?{hauteur:h}:{},...i?{nombre_d_etages:i}:{}}};for(const l of b.buildings([c],e,s,W.MIN_AREA_M2,50))o.push(W.described(l,r,h!==void 0))}return o.sort((n,a)=>Math.hypot(n.eastM,n.northM)-Math.hypot(a.eastM,a.northM)),o.slice(0,W.MAX_BUILDINGS)}static ringsOf(t){const e=o=>{if(!o||o.length<4)return;const n=o.map(i=>[i.lon,i.lat]),a=n[0],r=n[n.length-1];return a[0]===r[0]&&a[1]===r[1]?n:void 0};if(t.type==="way"){const o=e(t.geometry);return o?[o]:[]}return(t.members??[]).filter(o=>o.role==="outer").map(o=>e(o.geometry)).filter(o=>o!==void 0).slice(0,1)}static described(t,e,s){const o=S.wallMaterial(e["building:material"]),n=S.roofMaterial(e["roof:material"]),a=S.colour(e["building:colour"]),r=S.colour(e["roof:colour"])??_.roofColor(n),i=S.roofShape(e["roof:shape"]),h=a?{color:a}:void 0;let c,l=t.heightM;if(i==="gable"||i==="hip"||i==="dome"){const g=S.height(e["roof:height"]),m=Math.round((g??Math.min(5,Math.max(1.5,.29*Math.min(t.widthM,t.lengthM))))*10)/10;s||(l=Math.round((t.heightM+m)*10)/10),c={shape:i,riseM:m,...e["roof:orientation"]==="across"?{ridge:"depth"}:{},...r?{color:r}:{}}}else(i==="flat"||r)&&(c={shape:"flat",riseM:0,...r?{color:r}:{}});const{style:f,builtYear:M,closedAtNight:d}=O.ofOsm(e);return{...t,heightM:l,...f?{style:f}:{},...M!==void 0?{builtYear:M}:{},...d?{closedAtNight:d}:{},...e.name?{name:e.name}:{},...o?{wallMaterial:o}:{},...n?{roofMaterial:n}:{},...h?{facade:h}:{},...c?{roof:c}:{}}}}class L{credit={name:"Ville de Paris, Éclairage public",url:"https://opendata.paris.fr/explore/dataset/eclairage-public/",licence:"ODbL",of:"lamps"};static BOUNDS={south:48.8156,north:48.9022,west:2.2241,east:2.4698};static ENDPOINT="https://opendata.paris.fr/api/explore/v2.1/catalog/datasets/eclairage-public/records";static PAGE=100;static MAX=150;static MAX_PAGES=4;static METRES_PER_DEGREE=111320;static SAME_COLUMN_M=.5;static MIN_HEIGHT_M=2;fetchImpl;constructor(t){this.fetchImpl=t??fetch.bind(globalThis)}covers(t,e){const s=L.BOUNDS;return t>=s.south&&t<=s.north&&e>=s.west&&e<=s.east}async lampsNear(t,e){const s=[];let o=[];for(let n=0;n<L.MAX_PAGES&&o.length<L.MAX;n++){const a=await this.fetchImpl(L.query(t,e,L.PAGE,n*L.PAGE));if(!a.ok)throw new Error(`opendata.paris.fr refused (${a.status})`);const r=(await a.json()).results??[];if(s.push(...r),o=L.lampsFrom(s,t),r.length<L.PAGE)break}return o.slice(0,L.MAX)}static query(t,e,s,o){const n=`geom'POINT(${t.lng.toFixed(6)} ${t.lat.toFixed(6)})'`,a=new URLSearchParams({select:"geo_point_2d,lib_ouvrag,lampe_temperature_couleur,lampe_flux,support_hauteur",where:`within_distance(geo_point_2d,${n},${Math.round(e)}m)`,order_by:`distance(geo_point_2d,${n})`,limit:String(s),offset:String(o)});return`${L.ENDPOINT}?${a}`}static lampsFrom(t,e){const s=Math.cos(e.lat*Math.PI/180),o=a=>{const r=typeof a=="number"?a:Number.parseFloat(a??"");return Number.isFinite(r)&&r>0?r:void 0},n=[];for(const a of t){const r=a.geo_point_2d;if(!r||a.lib_ouvrag==="Projecteur")continue;const i=Math.round((r.lon-e.lng)*L.METRES_PER_DEGREE*s*10)/10,h=Math.round((r.lat-e.lat)*L.METRES_PER_DEGREE*10)/10,c=o(a.lampe_flux),l=n.find(d=>Math.hypot(d.eastM-i,d.northM-h)<L.SAME_COLUMN_M);if(l){c!==void 0&&(l.lumens=(l.lumens??0)+c);continue}const f=o(a.lampe_temperature_couleur),M=o(a.support_hauteur);n.push({eastM:i,northM:h,...M!==void 0&&M>=L.MIN_HEIGHT_M?{heightM:M}:{},...f!==void 0?{colorTemperatureK:f}:{},...c!==void 0?{lumens:c}:{},...a.lib_ouvrag==="Console"?{mount:"wall"}:{}})}return n}}class T{constructor(t,e){this.roads=t,this.fetchImpl=e??fetch.bind(globalThis)}credit={name:"Ville de Paris, Signalisation lumineuse tricolore",url:"https://opendata.paris.fr/explore/dataset/signalisation-tricolore/",licence:"ODbL",of:"signals"};static BOUNDS={south:48.8156,north:48.9022,west:2.2241,east:2.4698};static ENDPOINT="https://opendata.paris.fr/api/explore/v2.1/catalog/datasets/signalisation-tricolore/records";static PAGE=100;static MAX_PAGES=5;static MAX=160;static METRES_PER_DEGREE=111320;static SAME_POST_M=.8;static SEARCH_M=15;static PEDESTRIAN_ALONG_M=.4;fetchImpl;covers(t,e){const s=T.BOUNDS;return t>=s.south&&t<=s.north&&e>=s.west&&e<=s.east}async signalsNear(t,e){const s=(e+T.SEARCH_M)/T.METRES_PER_DEGREE,o=s/Math.cos(t.lat*Math.PI/180),[n,a]=await Promise.all([this.lenses(t,e),this.roads.getRoads({south:t.lat-s,north:t.lat+s,west:t.lng-o,east:t.lng+o})]);return T.signalsFrom(n,a,t)}async lenses(t,e){const s=[];for(let o=0;o<T.MAX_PAGES;o++){const n=await this.fetchImpl(T.query(t,e,T.PAGE,o*T.PAGE));if(!n.ok)throw new Error(`opendata.paris.fr refused (${n.status})`);const a=(await n.json()).results??[];if(s.push(...a),a.length<T.PAGE)break}return s}static query(t,e,s,o){const n=`geom'POINT(${t.lng.toFixed(6)} ${t.lat.toFixed(6)})'`,a=new URLSearchParams({select:"geo_point_2d,lib_regime",where:`within_distance(geo_point_2d,${n},${Math.round(e)}m)`,order_by:`distance(geo_point_2d,${n})`,limit:String(s),offset:String(o)});return`${T.ENDPOINT}?${a}`}static signalsFrom(t,e,s){const o=Math.cos(s.lat*Math.PI/180),n=(h,c)=>[(c-s.lng)*T.METRES_PER_DEGREE*o,(h-s.lat)*T.METRES_PER_DEGREE],a=[];for(const h of t){if(!h.geo_point_2d)continue;const c=n(h.geo_point_2d.lat,h.geo_point_2d.lon),l=(h.lib_regime??"").toUpperCase(),f=/ROUGE|JAUNE|VERT/.test(l),M=/PASSEZ|ATTENDEZ/.test(l);if(!f&&!M)continue;let d=a.find(g=>Math.hypot(g.at[0]-c[0],g.at[1]-c[1])<T.SAME_POST_M);d||a.push(d={at:c,vehicles:0,pedestrians:0}),f&&d.vehicles++,M&&d.pedestrians++}const r=e.map(h=>({way:h,points:h.points.map(c=>n(c.lat,c.lng))})),i=[];for(const h of a){const c=T.nearestRoad(h.at,r);if(!c)continue;const[l,f]=c.unit,M=T.heading(c.unit),d=(h.at[0]-c.foot[0])*f-(h.at[1]-c.foot[1])*l>=0,g=c.way.direction,m=g==="forward"?M:g==="backward"?(M+180)%360:d?M:(M+180)%360,E=w=>Math.round(w*10)/10,v=w=>E((w%360+360)%360);if(h.vehicles>0&&i.push({eastM:E(h.at[0]),northM:E(h.at[1]),headingDeg:v(m+180),for:"vehicles",phase:j.phaseOf(m)}),h.pedestrians>0){const w=T.heading([c.foot[0]-h.at[0],c.foot[1]-h.at[1]]),p=h.vehicles>0?T.PEDESTRIAN_ALONG_M:0;i.push({eastM:E(h.at[0]+l*p),northM:E(h.at[1]+f*p),headingDeg:v(Number.isNaN(w)?M+90:w),for:"pedestrians",phase:j.phaseOf(M)})}}return i.sort((h,c)=>Math.hypot(h.eastM,h.northM)-Math.hypot(c.eastM,c.northM)).slice(0,T.MAX)}static nearestRoad(t,e){let s;for(const{way:o,points:n}of e)for(let a=1;a<n.length;a++){const[r,i]=n[a-1],[h,c]=n[a],l=Math.hypot(h-r,c-i);if(l===0)continue;const f=[(h-r)/l,(c-i)/l],M=Math.max(0,Math.min(l,(t[0]-r)*f[0]+(t[1]-i)*f[1])),d=[r+f[0]*M,i+f[1]*M],g=Math.hypot(t[0]-d[0],t[1]-d[1]);g<=T.SEARCH_M&&(!s||g<s.distance)&&(s={way:o,unit:f,foot:d,distance:g})}return s}static heading([t,e]){return t===0&&e===0?Number.NaN:Math.round((Math.atan2(t,e)*180/Math.PI+360)%360*10)/10}}const K=B.point("surroundings").provide(B.BUILT_IN,[{id:"ign-lidar-topo",name:"IGN LiDAR HD + BD TOPO",credit:"© IGN, LiDAR HD and BD TOPO, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>new I(new F({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"ign-lidar-hd",name:"IGN LiDAR HD",credit:"© IGN, LiDAR HD, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>new I(new nt({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"ign-bd-topo",name:"IGN BD TOPO",credit:"© IGN, BD TOPO, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/bdtopo",create:()=>new I(new at({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"osm-buildings",name:"OpenStreetMap buildings",credit:"Buildings and street lamps © OpenStreetMap contributors (ODbL)",creditUrl:"https://www.openstreetmap.org/copyright",create:()=>new I(new W({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))}]);class U{static DEFAULT_ID=K[0].id;static WORLD_ID="osm-buildings";static TOWN_LAMPS=[new L];static TOWN_SIGNALS=[new T(new et)];static NONE="none";static byId(t){return t===U.NONE?void 0:K.find(e=>e.id===t)??K[0]}static providerFor(t,e,s){const o=U.byId(t)?.create();if(t!==void 0&&t!==U.DEFAULT_ID)return o?.covers(e,s)?o:void 0;const n=K.find(r=>r.id===U.WORLD_ID).create(),a=[o,n].filter(r=>r!==void 0&&r.covers(e,s));return a.length>1?new st(a):a[0]}}export{K as SURROUNDINGS_SOURCES,U as SurroundingsSources};
|
|
1
|
+
import{e as B}from"./rr0-ufoathome.mjs";import{x as V,cP as tt,cQ as q,y as j,cR as C,cS as X,cT as et}from"./ShareDialogElement-ClhewPap.js";import{l as ot}from"./SaidPosition-CWiVNaNW.js";import"./Sighting-CBpJpdm9.js";import"./VisualAids-DI-hEL46.js";import"./Decor-Dn-cvniW.js";import"./RecordingIssue-BlWT8Xsu.js";import"./Obstacles-v9SkfBD7.js";class I{constructor(t){this.survey=t}static CACHE_NAME="rr0-surroundings";static MAX_AGE_MS=720*3600*1e3;static FORMAT=8;static MAX_STORED=400;static asked=new Map;get id(){return this.survey.id}get name(){return this.survey.name}get attribution(){return this.survey.attribution}get creditUrl(){return this.survey.creditUrl}get contemporary(){return this.survey.contemporary}covers(t,e){return this.survey.covers(t,e)}async getSurroundings(t,e){const s=I.key(this.survey.id,t,e);let o=I.asked.get(s);return o===void 0&&(o=this.recalled(s,t,e),I.asked.set(s,o),o.catch(()=>I.asked.delete(s))),structuredClone(await o)}later(t,e){const s=this.survey.later?.(t,e);if(!s)return;const o=I.key(this.survey.id,t,e);return s.then(n=>{const a=I.partial.get(o);if(a){I.partial.delete(o);const{incomplete:r,...i}=a,h=[...a.credits??[],...n.credits??[]].filter((l,f,M)=>M.findIndex(d=>d.url===l.url)===f),c={...i,...n,dates:{...a.dates,...n.dates},...h.length>0?{credits:h}:{}};I.asked.set(o,Promise.resolve(c)),I.openCache().then(l=>l&&I.store(l,I.request(o),c))}return structuredClone(n)})}static partial=new Map;static forget(){I.partial.clear(),I.asked.clear()}static key(t,e,s){return`${t}/v${I.FORMAT}/${e.lat.toFixed(5)}/${e.lng.toFixed(5)}/${Math.round(s)}`}async recalled(t,e,s){const o=await I.openCache(),n=I.request(t);if(o)try{const r=await o.match(n);if(r){const{savedAt:i,surroundings:h}=await r.json();if(Date.now()-i<I.MAX_AGE_MS)return h;await o.delete(n)}}catch{}const a=await this.survey.getSurroundings(e,s);return a.incomplete?(I.asked.delete(t),I.partial.set(t,structuredClone(a)),a):(o&&I.store(o,n,a),a)}static async store(t,e,s){try{const o={savedAt:Date.now(),surroundings:s};await t.put(e,new Response(JSON.stringify(o),{headers:{"Content-Type":"application/json"}}));const n=await t.keys();for(const a of n.slice(0,Math.max(0,n.length-I.MAX_STORED)))await t.delete(a)}catch{}}static async openCache(){try{return typeof caches>"u"?void 0:await caches.open(I.CACHE_NAME)}catch{return}}static request(t){const e=typeof location>"u"?"http://localhost":location.origin;return new Request(`${e}/__surroundings__/${encodeURIComponent(t)}`)}}class st{constructor(t){if(this.candidates=t,t.length===0)throw new Error("A survey needs at least one candidate");this.current=t[0]}current;get id(){return this.current.id}get name(){return this.current.name}get attribution(){return this.current.attribution}get creditUrl(){return this.current.creditUrl}get contemporary(){return this.current.contemporary}covers(t,e){return this.candidates.some(s=>s.covers(t,e))}async getSurroundings(t,e){let s;for(const o of this.candidates)if(o.covers(t.lat,t.lng))try{const n=await o.getSurroundings(t,e);return this.current=o,n}catch(n){if(s??=n,!(n instanceof V))throw n}throw s??new V("no-coverage","No survey reaches this place")}later(t,e){return this.current.later?.(t,e)}}class D{constructor(t,e,s,o){this.heights=t,this.building=e,this.width=s,this.height=o}static ROOF_PERCENTILE=.9;static STEP_M=.9;static RECTANGLE_FILL=.72;static MIN_DEPTH_M=2.5;static MAX_PARTS=24;static MAX_CELLS=640;buildings(t){const e=t.metresPerPixel,s=t.minAreaM2??12,o=new Uint8Array(this.width*this.height),n=[];for(let a=0;a<this.building.length;a++){if(!this.building[a]||o[a])continue;const r=this.patchFrom(a,o);if(!(r.length*e*e<s))for(const i of this.buildingsOf(r,e,s))Math.hypot(i.eastM,i.northM)<=t.radiusM&&n.push(i)}return n.sort((a,r)=>Math.hypot(a.eastM,a.northM)-Math.hypot(r.eastM,r.northM)),n.slice(0,t.maxBuildings??60)}patchFrom(t,e){const s=[],o=[t];for(e[t]=1;o.length>0;){const n=o.pop();s.push(n);const a=n%this.width,r=Math.floor(n/this.width);for(const[i,h]of[[1,0],[-1,0],[0,1],[0,-1]]){const c=a+i,l=r+h;if(c<0||l<0||c>=this.width||l>=this.height)continue;const f=l*this.width+c;this.building[f]&&!e[f]&&Math.abs(this.heights[f]-this.heights[n])<=D.STEP_M&&(e[f]=1,o.push(f))}}return s}buildingsOf(t,e,s){const o=this.width/2,n=this.height/2,a=[],r=[],i=[];for(const h of t){const c=h%this.width,l=Math.floor(h/this.width);a.push((c+.5-o)*e),r.push((n-l-.5)*e),i.push(this.heights[h])}return D.ofPoints(a,r,i,e,s)}static ofPoints(t,e,s,o,n,a=D.RECTANGLE_FILL,r=[]){const i=[];for(let m=0;m<t.length;m++)for(const[E,v]of[[-.5,-.5],[.5,-.5],[-.5,.5],[.5,.5]])i.push([t[m]+E*o,e[m]+v*o]);const h=D.hull(i),{angle:c,rectangle:l}=D.smallestRectangle(h),f=t.length*o*o,M=(l.maxU-l.minU)*(l.maxV-l.minV);if(f/M>=a||f<4*n)return[D.building(l,c,D.roof(s))];const d=h.map((m,E)=>({from:{east:m[0],north:m[1]},to:{east:h[(E+1)%h.length][0],north:h[(E+1)%h.length][1]}})),g=D.dominantAngles([...r,...d]);return D.parts(t,e,s,g.length>0?g:[c],o,n)}static dominantAngles(t,e=3){const s=new Map;for(const o of t){const n=Math.hypot(o.to.east-o.from.east,o.to.north-o.from.north);if(n<1e-6)continue;const a=(Math.atan2(o.to.north-o.from.north,o.to.east-o.from.east)%(Math.PI/2)+Math.PI/2)%(Math.PI/2),r=Math.round(a/(Math.PI/60));s.set(r,(s.get(r)??0)+n)}return[...s.entries()].sort((o,n)=>n[1]-o[1]).slice(0,e).map(([o])=>o*Math.PI/60)}static parts(t,e,s,o,n,a){let r=t.map((h,c)=>c);const i=[];for(let h=0;h<D.MAX_PARTS&&r.length>0;h++){let c;for(const M of o){const d=D.largestIn(t,e,r,M,n);d&&(c===void 0||d.area>c.area)&&(c=d)}if(c===void 0||c.area<a)break;const l=c.covered;Math.min(c.rectangle.maxU-c.rectangle.minU,c.rectangle.maxV-c.rectangle.minV)>=D.MIN_DEPTH_M&&i.push(D.building(c.rectangle,c.angle,D.roof([...l].map(M=>s[M])))),r=r.filter(M=>!l.has(M))}return i}static largestIn(t,e,s,o,n){const a=Math.cos(o),r=Math.sin(o);let i=1/0,h=-1/0,c=1/0,l=-1/0;const f=[],M=[];for(const A of s){const y=t[A]*a+e[A]*r,N=-t[A]*r+e[A]*a;f.push(y),M.push(N),i=Math.min(i,y),h=Math.max(h,y),c=Math.min(c,N),l=Math.max(l,N)}const d=Math.max(n*Math.SQRT2,Math.max(h-i,l-c)/D.MAX_CELLS),g=Math.max(1,Math.ceil((h-i)/d+1e-9)),m=Math.max(1,Math.ceil((l-c)/d+1e-9)),E=new Uint8Array(g*m),v=s.map((A,y)=>{const N=Math.min(g-1,Math.max(0,Math.floor((f[y]-i)/d))),x=Math.min(m-1,Math.max(0,Math.floor((M[y]-c)/d)));return E[x*g+N]=1,x*g+N}),w=D.largestRectangle(E,g,m);if(w===void 0)return;const p=new Set;return s.forEach((A,y)=>{const N=v[y]%g,x=Math.floor(v[y]/g);N>=w.column&&N<w.column+w.columns&&x>=w.row&&x<w.row+w.rows&&p.add(A)}),{area:w.area*d*d,angle:o,covered:p,rectangle:{minU:i+w.column*d,maxU:i+(w.column+w.columns)*d,minV:c+w.row*d,maxV:c+(w.row+w.rows)*d}}}static largestRectangle(t,e,s){const o=new Array(e).fill(0);let n;for(let a=0;a<s;a++){for(let i=0;i<e;i++)o[i]=t[a*e+i]?o[i]+1:0;const r=[];for(let i=0;i<=e;i++){const h=i===e?0:o[i];for(;r.length>0&&o[r[r.length-1]]>=h;){const c=r.pop(),l=r.length===0?i:i-r[r.length-1]-1,f=o[c]*l;(n===void 0||f>n.area)&&(n={column:i-l,row:a-o[c]+1,columns:l,rows:o[c],area:f})}r.push(i)}}return n}static roof(t){const e=[...t].sort((s,o)=>s-o);return Math.max(2,e[Math.min(e.length-1,Math.floor(e.length*D.ROOF_PERCENTILE))])}static building(t,e,s){const o=Math.cos(e),n=Math.sin(e),a=t.maxU-t.minU,r=t.maxV-t.minV,i=(t.minU+t.maxU)/2,h=(t.minV+t.maxV)/2,l=((90-(a<r?e:e+Math.PI/2)*180/Math.PI)%180+180)%180;return{eastM:D.tenth(i*o-h*n),northM:D.tenth(i*n+h*o),widthM:D.tenth(Math.max(a,r)),lengthM:D.tenth(Math.min(a,r)),heightM:D.tenth(s),headingDeg:Math.round(l*10)/10}}static smallestRectangle(t){let e={area:1/0,angle:0,rectangle:{minU:0,maxU:0,minV:0,maxV:0}};for(let s=0;s<Math.max(1,t.length);s++){const[o,n]=t[s]??[0,0],[a,r]=t[(s+1)%t.length]??[1,0],i=Math.atan2(r-n,a-o),h=Math.cos(i),c=Math.sin(i);let l=1/0,f=-1/0,M=1/0,d=-1/0;for(const[m,E]of t){const v=m*h+E*c,w=-m*c+E*h;l=Math.min(l,v),f=Math.max(f,v),M=Math.min(M,w),d=Math.max(d,w)}const g=(f-l)*(d-M);g<e.area&&(e={area:g,angle:i,rectangle:{minU:l,maxU:f,minV:M,maxV:d}})}return e}static hull(t){const e=[...t].sort((r,i)=>r[0]-i[0]||r[1]-i[1]),s=e.filter((r,i)=>i===0||r[0]!==e[i-1][0]||r[1]!==e[i-1][1]);if(s.length<3)return s;const o=(r,i,h)=>(i[0]-r[0])*(h[1]-r[1])-(i[1]-r[1])*(h[0]-r[0]),n=[];for(const r of s){for(;n.length>=2&&o(n[n.length-2],n[n.length-1],r)<=0;)n.pop();n.push(r)}const a=[];for(const r of[...s].reverse()){for(;a.length>=2&&o(a[a.length-2],a[a.length-1],r)<=0;)a.pop();a.push(r)}return[...n.slice(0,-1),...a.slice(0,-1)]}static tenth(t){return Math.round(t*10)/10}}class H{constructor(t,e,s,o){this.heights=t,this.vegetation=e,this.width=s,this.height=o}static SUMMIT_RADIUS_M=2.5;static CROWN_REACH_M=8;static MAX_WIDTH_M=16;static MIN_WIDTH_M=2;static tenth(t){return Math.round(t*10)/10}trees(t){const e=t.metresPerPixel,s=t.minHeightM??4,o=t.eyeM??1.6,n=t.minElevationDeg??2,a=Math.max(1,Math.round(H.SUMMIT_RADIUS_M/e)),r=Math.round(H.CROWN_REACH_M/e),i=this.width/2,h=this.height/2,c=[];for(let l=0;l<this.height;l++)for(let f=0;f<this.width;f++){const M=this.canopy(f,l);if(M<s)continue;const d=(f+.5-i)*e,g=(h-l-.5)*e,m=Math.hypot(d,g);if(m>t.radiusM||!this.isSummit(f,l,M,a))continue;const E=Math.atan2(M-o,Math.max(m,1))*180/Math.PI;E<n||c.push({tree:{eastM:H.tenth(d),northM:H.tenth(g),heightM:H.tenth(M),widthM:H.tenth(this.crownWidth(f,l,M,e,r))},elevation:E})}return c.sort((l,f)=>f.elevation-l.elevation),c.slice(0,t.maxTrees??150).map(l=>l.tree)}canopy(t,e){if(t<0||e<0||t>=this.width||e>=this.height)return 0;const s=e*this.width+t;return this.vegetation[s]?this.heights[s]:0}isSummit(t,e,s,o){for(let n=-o;n<=o;n++)for(let a=-o;a<=o;a++){if(a===0&&n===0)continue;const r=this.canopy(t+a,e+n);if(r>s||r===s&&(n<0||n===0&&a<0))return!1}return!0}crownWidth(t,e,s,o,n){let a=0;for(let i=-n;i<=n;i++)for(let h=-n;h<=n;h++)Math.hypot(h,i)*o<=H.CROWN_REACH_M&&this.canopy(t+h,e+i)>=s*.5&&a++;const r=2*Math.sqrt(a*o*o/Math.PI);return Math.max(H.MIN_WIDTH_M,Math.min(r,H.MAX_WIDTH_M))}}class _{static WALLS={1:"stone",2:"meuliere",3:"concrete",4:"brick",5:"block",6:"wood",9:"other"};static ROOFS={1:"tile",2:"slate",3:"zinc",4:"concrete",9:"other"};static WALL_COLOURS={stone:"#b9ae9b",meuliere:"#b8a78a",concrete:"#b4b2ac",brick:"#a65f48",block:"#d0c6b2",wood:"#7d5c3e",other:"#c9c0ae"};static PLASTER="#d3cab8";static ROOF_COLOURS={tile:"#a0583f",slate:"#4a5059",zinc:"#8d969c",concrete:"#8f8e8a",other:"#7a7872"};static VARIATION=.12;static OLD_ROOF="#7d858c";static OLD_STOREY_M=3.6;static GRAND_STOREY_M=4.5;static MIN_STOREY_M=2.4;static MAX_STOREY_M=6;static of(t,e){const s=String(t??"").trim();if(!/^\d{1,2}$/.test(s))return;const o=Number(s),n=o%10!==0?o%10:Math.floor(o/10);return(e==="wall"?_.WALLS:_.ROOFS)[String(n)]}static roofColor(t){return t?_.ROOF_COLOURS[t]:void 0}static fit(t){return t.map(e=>{const s=e.style,o={...e.facade,color:e.facade?.color??_.wallColor(e)};s==="church"?o.openings="lancet":s==="monument"||s==="works"?o.openings="plain":(s==="old"||s==="grand")&&(o.openings="tall"),e.closedAtNight&&o.openings!=="plain"&&(o.closedAtNight=!0);const n=_.storeyOf(e);n!==void 0&&s!=="church"&&s!=="monument"&&(o.storeyM=n);const a=s==="old"&&e.roof?.color===void 0?{shape:"flat",riseM:0,...e.roof,color:_.OLD_ROOF}:e.roof;return{...e,facade:o,...a?{roof:a}:{}}})}static storeyOf(t){const e=t.heightM-(t.roof?.riseM??0);if(t.floors&&t.floors>0){const s=e/t.floors;if(s>=_.MIN_STOREY_M&&s<=_.MAX_STOREY_M)return Math.round(s*100)/100}return t.style==="old"?_.OLD_STOREY_M:t.style==="grand"?_.GRAND_STOREY_M:void 0}static wallColor(t){const e=t.style==="church"||t.style==="monument"||t.style==="old",s=t.wallMaterial?_.WALL_COLOURS[t.wallMaterial]:e?_.WALL_COLOURS.stone:_.PLASTER,o=Math.sin(t.eastM*12.9898+t.northM*78.233)*43758.5453,n=1+(o-Math.floor(o)-.5)*2*_.VARIATION,a=r=>Math.max(0,Math.min(255,Math.round(parseInt(s.slice(r,r+2),16)*n))).toString(16).padStart(2,"0");return`#${a(1)}${a(3)}${a(5)}`}}class R{static MIN_RISE_M=1.2;static MIN_EAVES_M=2.5;static MIN_SEEN=.35;static NO_DATA=-9999;static BANDS=7;static INSET_M=.9;static LIFT=1.18;static PEAK=.3;static LEVEL=.45;static fit(t,e,s){return!e&&!s&&!t.some(o=>o.roofMaterial)?t:t.map(o=>{const n=e?R.shapeOf(o,e):void 0,a=(s?R.colorOf(o,s):void 0)??_.roofColor(o.roofMaterial);if(!n&&!a)return o;const r={shape:n?.shape??"flat",...n?.ridge==="depth"?{ridge:"depth"}:{},riseM:n?.riseM??0,...a?{color:a}:{}},i=n&&n.shape!=="flat"?n.topM:o.heightM;return{...o,heightM:i,roof:r}})}static world(t,e,s){const o=t.headingDeg*Math.PI/180;return{east:t.eastM+e*Math.cos(o)+s*Math.sin(o),north:t.northM-e*Math.sin(o)+s*Math.cos(o)}}static shapeOf(t,e){const s=R.BANDS,o=Math.max(e.metresPerPixel,.5),n=t.widthM/2-R.INSET_M,a=t.lengthM/2-R.INSET_M;if(n<=0||a<=0)return;const r=[],i=Array.from({length:s},()=>({sum:0,n:0})),h=Array.from({length:s},()=>({sum:0,n:0}));let c=0;for(let y=-n;y<=n;y+=o)for(let N=-a;N<=a;N+=o){c++;const{east:x,north:$}=R.world(t,y,N),z=Math.floor(x/e.metresPerPixel+e.size/2),Y=Math.floor(e.size/2-$/e.metresPerPixel);if(z<0||Y<0||z>=e.size||Y>=e.size)continue;const k=Y*e.size+z,P=e.heights[k];if(e.vegetation[k]||P===R.NO_DATA||!(P>0))continue;r.push(P);const J=i[Math.min(s-1,Math.floor((y+n)/(2*n)*s))],Q=h[Math.min(s-1,Math.floor((N+a)/(2*a)*s))];J.sum+=P,J.n++,Q.sum+=P,Q.n++}if(c===0||r.length/c<R.MIN_SEEN)return;r.sort((y,N)=>y-N);const l=R.percentile(r,.08),f=R.percentile(r,.92),M=f-l;if(l<R.MIN_EAVES_M||M>Math.min(t.widthM,t.lengthM))return;if(M<R.MIN_RISE_M)return{shape:"flat",riseM:0,topM:f};const d=R.profile(i),g=R.profile(h);if(!d||!g)return;const m=R.peak(g)/M,E=R.peak(d)/M,v=R.spread(d)/M,w=R.spread(g)/M,p=m>=R.PEAK&&v<=R.LEVEL,A=E>=R.PEAK&&w<=R.LEVEL;if(p&&(!A||m>=E))return{shape:"gable",ridge:"width",riseM:M,topM:f};if(A)return{shape:"gable",ridge:"depth",riseM:M,topM:f};if(m>=R.PEAK&&E>=R.PEAK/2)return{shape:"hip",ridge:"width",riseM:M,topM:f}}static profile(t){const e=t.map(s=>s.n>0?s.sum/s.n:NaN);return e.filter(Number.isFinite).length>=t.length-1?e.map((s,o)=>Number.isFinite(s)?s:R.neighbour(e,o)):void 0}static neighbour(t,e){return Number.isFinite(t[e-1])?t[e-1]:t[e+1]}static peak(t){const e=Math.max(1,Math.floor(t.length/3)),s=n=>n.reduce((a,r)=>a+r,0)/n.length,o=[...t.slice(0,e),...t.slice(t.length-e)];return s(t.slice(e,t.length-e))-s(o)}static spread(t){return Math.max(...t)-Math.min(...t)}static percentile(t,e){return t[Math.min(t.length-1,Math.floor(t.length*e))]}static colorOf(t,e){const s=Math.max(e.metresPerPixel,.5),o=Math.max(t.widthM/2-R.INSET_M,s),n=Math.max(t.lengthM/2-R.INSET_M,s),a=[],r=[],i=[];for(let l=-o;l<=o;l+=s)for(let f=-n;f<=n;f+=s){const{east:M,north:d}=R.world(t,l,f),g=Math.floor(M/e.metresPerPixel+e.size/2),m=Math.floor(e.size/2-d/e.metresPerPixel);if(g<0||m<0||g>=e.size||m>=e.size)continue;const E=(m*e.size+g)*e.samples,v=e.values[E],w=e.values[E+1],p=e.values[E+2];w>v&&w>p||(a.push(v),r.push(w),i.push(p))}if(a.length===0)return;const h=l=>l.sort((f,M)=>f-M)[Math.floor(l.length/2)],c=l=>Math.min(255,Math.round(l*R.LIFT)).toString(16).padStart(2,"0");return`#${c(h(a))}${c(h(r))}${c(h(i))}`}}class G{static DEFAULT_HEIGHT_M=6;static METRES_PER_DEGREE=111320;static STREET_SPACING_M=35;static KERB_OFFSET_M=1;static DEFAULT_WIDTH_M=5.5;static PATIENCE_MS=15e3;static MAX=150;static lampsFrom(t,e,s){const o=[],n=new Set;for(const r of t.elements??[]){if(r.id!==void 0){const l=`${r.type}/${r.id}`;if(n.has(l))continue;n.add(l)}if(r.type==="way"){r.tags?.lit==="yes"&&G.alongStreet(r,e,o);continue}if(r.tags?.highway!=="street_lamp"||typeof r.lat!="number"||typeof r.lon!="number")continue;const i=(r.lon-e.lng)*G.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180),h=(r.lat-e.lat)*G.METRES_PER_DEGREE;if(Math.hypot(i,h)>s)continue;const c=Number.parseFloat(r.tags?.height??"");o.push({eastM:Math.round(i*10)/10,northM:Math.round(h*10)/10,...Number.isFinite(c)&&c>=2&&c<=20?{heightM:c}:{}})}const a=o.filter(r=>Math.hypot(r.eastM,r.northM)<=s);return o.length=0,o.push(...a),o.sort((r,i)=>Math.hypot(r.eastM,r.northM)-Math.hypot(i.eastM,i.northM)),o.slice(0,G.MAX)}static alongStreet(t,e,s){const o=t.geometry;if(!o||o.length<2)return;const n=d=>[(d.lon-e.lng)*G.METRES_PER_DEGREE*Math.cos(e.lat*Math.PI/180),(d.lat-e.lat)*G.METRES_PER_DEGREE],a=o.map(n),r=Number.parseFloat(t.tags?.width??""),i=Number.parseInt(t.tags?.lanes??"",10),c=(Number.isFinite(r)&&r>0?r:Number.isFinite(i)&&i>0?i*3.5:G.DEFAULT_WIDTH_M)/2+G.KERB_OFFSET_M;let l=1,f=G.STREET_SPACING_M/2,M=0;for(let d=1;d<a.length;d++){const[g,m]=a[d-1],[E,v]=a[d],w=Math.hypot(E-g,v-m);if(w===0)continue;const p=(E-g)/w,A=(v-m)/w;for(;f<=M+w;f+=G.STREET_SPACING_M){const y=f-M;s.push({eastM:Math.round((g+p*y+A*c*l)*10)/10,northM:Math.round((m+A*y-p*c*l)*10)/10,supposed:!0}),l=-l}M+=w}}}class u{constructor(t={},e=[],s=[]){this.lampSources=e,this.signalSources=s,this.client=new tt(t)}static METRES_PER_DEGREE=111320;static KERB_OFFSET_M=.6;static SETBACK_M=.5;static MIN_CROSSING_M=3;static MAX_CROSSING_M=30;static SAME_CROSSING_M=5;static SAME_HEAD_M=2.5;static SAME_HEAD_DEG=45;static MAX_SIGNALS=160;static MAX_CROSSINGS=150;static MAX_SIGNS=100;static ROADS=new Set([...q.DRIVABLE,"living_street","busway","road"]);static ON_ROAD="^(traffic_signals|crossing|stop|give_way)$";static CREDIT={name:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL"};client;local(t,e){const s=u.boxOf(t,e),o=(r,i)=>{if(!r)return Promise.resolve(void 0);const h=`${r.credit.url} ${s}`;let c=u.localPending.get(h);return c||(c=i().then(l=>({credit:r.credit,found:l}),()=>{u.localPending.delete(h)}),u.localPending.set(h,c)),c},n=this.lampSources.find(r=>r.covers(t.lat,t.lng)),a=this.signalSources.find(r=>r.covers(t.lat,t.lng));return Promise.all([o(n,()=>n.lampsNear(t,e)),o(a,()=>a.signalsNear(t,e))]).then(([r,i])=>({lamps:r,signals:i}))}static localPending=new Map;static withLocal(t,e){const s=e?.lamps?e.lamps.found:t.lamps,o=e?.signals?e.signals.found:t.signals,a=[...u.found({crossings:t.crossings,signs:t.signs,...e?.lamps?{}:{lamps:s},...e?.signals?{}:{signals:o}})?[u.CREDIT]:[],...e?.lamps&&e.lamps.found.length>0?[e.lamps.credit]:[],...e?.signals&&e.signals.found.length>0?[e.signals.credit]:[]],{lamps:r,signals:i,credits:h,...c}=t;return{...c,...s?.length?{lamps:s}:{},...o?.length?{signals:o}:{},...a.length>0?{credits:a}:{}}}static today(){return new Date().toISOString().slice(0,10)}static later(t,e,s){return t?.answered(e,s).then(o=>({...o,...u.found(o)?{dates:{lamps:u.today()}}:{}}))}static found(t){return!!(t?.lamps?.length||t?.signals?.length||t?.crossings?.length||t?.signs?.length)}static query(t){const e=u.ON_ROAD;return`[out:json][timeout:25];(node["highway"="street_lamp"](${t});way["highway"]["lit"="yes"](${t});node["highway"~"${e}"](${t});node["traffic_sign"](${t});way["footway"="crossing"](${t}););out geom;(node._["highway"~"${e}"];node._["traffic_sign"];)->.kerb;way(bn.kerb)["highway"];out geom;`}static pending=new Map;async near(t,e){const s=this.ask(u.boxOf(t,e)),o=this.local(t,e);let n;const a=Symbol("late"),r=new Promise(i=>{n=setTimeout(()=>i(a),G.PATIENCE_MS)});try{const[i,h]=await Promise.all([Promise.race([s,r]),Promise.race([o,r])]),c=h===a?void 0:h;return i===a||i===void 0?{...u.withLocal({},c),incomplete:!0}:u.withLocal(u.from(i,t,e),c)}finally{clearTimeout(n)}}static RETRY_DELAYS_MS=[15e3,6e4,18e4,6e5];async answered(t,e){const s=u.boxOf(t,e);for(let o=0;;o++){const n=await this.ask(s);if(n)return u.withLocal(u.from(n,t,e),await this.local(t,e));if(o>=u.RETRY_DELAYS_MS.length)throw new Error("Overpass did not answer");await new Promise(a=>setTimeout(a,u.RETRY_DELAYS_MS[o]))}}ask(t){let e=u.pending.get(t);return e||(e=this.client.query(u.query(t)).catch(()=>{u.pending.delete(t)}),u.pending.set(t,e)),e}static boxOf(t,e){const s=e/u.METRES_PER_DEGREE,o=e/(u.METRES_PER_DEGREE*Math.cos(t.lat*Math.PI/180));return[t.lat-s,t.lng-o,t.lat+s,t.lng+o].map(n=>n.toFixed(6)).join(",")}static forget(){u.pending.clear(),u.localPending.clear()}static from(t,e,s){const o=G.lampsFrom(t,e,s),n=Math.cos(e.lat*Math.PI/180),a=(p,A)=>[(A-e.lng)*u.METRES_PER_DEGREE*n,(p-e.lat)*u.METRES_PER_DEGREE],r=(p,A)=>`${p.toFixed(7)},${A.toFixed(7)}`,i=new Map,h=new Set,c=[],l=[];for(const p of t.elements??[]){if(p.type==="node"){typeof p.lat=="number"&&typeof p.lon=="number"&&l.push(p);continue}if(p.type!=="way"||!p.geometry||p.geometry.length<2)continue;if(p.id!==void 0){if(h.has(p.id))continue;h.add(p.id)}const A=p.tags??{};if(A.footway==="crossing"&&c.push(p),!u.ROADS.has(A.highway??""))continue;const y=p.geometry.map(N=>a(N.lat,N.lon));p.geometry.forEach((N,x)=>{const $=r(N.lat,N.lon);i.set($,[...i.get($)??[],{way:p,points:y,index:x}])})}const f=[],M=[],d=[],g=new Set;for(const p of l){if(p.id!==void 0){if(g.has(p.id))continue;g.add(p.id)}const A=p.tags??{},y=a(p.lat,p.lon),N=i.get(r(p.lat,p.lon))??[],x=A.highway;if(x==="traffic_signals")for(const k of u.approaches(N,u.directionOf(A),!1))f.push(u.head(y,k,"vehicles"));if(x==="crossing"||x==="traffic_signals"&&A.crossing!==void 0){const k=N[0];if(k&&u.marked(A)){const P=u.directionAt(k);P&&M.push({eastM:u.round(y[0]),northM:u.round(y[1]),headingDeg:u.heading(P),widthM:q.widthOf(k.way.tags??{})}),P&&(A.crossing==="traffic_signals"||A["crossing:signals"]==="yes")&&f.push(...u.pedestrianHeads(y,P,k))}}if(x==="traffic_signals")continue;const $=x==="stop"?{face:"stop"}:x==="give_way"?{face:"give-way"}:u.faceOf(A);if(!$)continue;const z=A.traffic_sign?{code:A.traffic_sign}:{};if(N.length>0){const k=u.approaches(N,u.directionOf(A),!0)[0];if(k){const P=u.head(y,k,"vehicles");d.push({eastM:P.eastM,northM:P.northM,headingDeg:P.headingDeg,...$,...z})}continue}const Y=u.compassOf(A.direction);Y!==void 0&&d.push({eastM:u.round(y[0]),northM:u.round(y[1]),headingDeg:(Y+180)%360,...$,...z})}for(const p of c){const A=u.crossingAlong(p,a);A&&!M.some(y=>Math.hypot(y.eastM-A.eastM,y.northM-A.northM)<u.SAME_CROSSING_M)&&M.push(A)}const m=f.filter((p,A)=>!f.slice(0,A).some(y=>y.for===p.for&&Math.hypot(y.eastM-p.eastM,y.northM-p.northM)<u.SAME_HEAD_M&&Math.abs((y.headingDeg-p.headingDeg+540)%360-180)<u.SAME_HEAD_DEG)),E=(p,A)=>p.filter(y=>Math.hypot(y.eastM,y.northM)<=s).sort((y,N)=>Math.hypot(y.eastM,y.northM)-Math.hypot(N.eastM,N.northM)).slice(0,A),v={};o.length>0&&(v.lamps=o);const w={signals:E(m,u.MAX_SIGNALS),crossings:E(M,u.MAX_CROSSINGS),signs:E(d,u.MAX_SIGNS)};return w.signals.length>0&&(v.signals=w.signals),w.crossings.length>0&&(v.crossings=w.crossings),w.signs.length>0&&(v.signs=w.signs),v}static approaches(t,e,s){const o=[];for(const a of t){const r=a.way.tags??{},i=r.oneway==="yes"||r.oneway==="true"||r.oneway==="1"||r.junction==="roundabout"||r.highway==="motorway",h=r.oneway==="-1",{points:c,index:l}=a,f=(d,g)=>{let m=0;for(let E=Math.min(d,g);E<Math.max(d,g);E++)m+=Math.hypot(c[E+1][0]-c[E][0],c[E+1][1]-c[E][1]);return m},M=d=>{const g=c[l][0]-c[d][0],m=c[l][1]-c[d][1],E=Math.hypot(g,m);return E>0?[g/E,m/E]:void 0};if(l>0&&!h){const d=M(l-1);d&&o.push({approach:{unit:d,road:a},toEndM:f(l,c.length-1),forward:!0})}if(l<c.length-1&&!i){const d=M(l+1);d&&o.push({approach:{unit:d,road:a},toEndM:f(0,l),forward:!1})}}const n=e!==void 0&&t.length===1?o.filter(a=>a.forward===(e==="forward")):o;return!s||n.length<=1?n.map(a=>a.approach):[n.reduce((a,r)=>r.toEndM<a.toEndM?r:a).approach]}static head(t,e,s){const[o,n]=e.unit,a=q.widthOf(e.road.way.tags??{})/2+u.KERB_OFFSET_M,r=u.SETBACK_M,i=u.heading(e.unit);return{eastM:u.round(t[0]-o*r+n*a),northM:u.round(t[1]-n*r-o*a),headingDeg:(i+180)%360,for:s,phase:j.phaseOf(i)}}static pedestrianHeads(t,e,s){const o=q.widthOf(s.way.tags??{})/2+u.KERB_OFFSET_M,n=u.heading(e),a=j.phaseOf(n);return[1,-1].map(r=>({eastM:u.round(t[0]+e[1]*o*r),northM:u.round(t[1]-e[0]*o*r),headingDeg:(n+(r===1?270:90))%360,for:"pedestrians",phase:a}))}static crossingAlong(t,e){if(!u.marked(t.tags??{}))return;const s=t.geometry.map(h=>e(h.lat,h.lon)),[o,n]=s[0],[a,r]=s[s.length-1],i=Math.hypot(a-o,r-n);if(!(i<u.MIN_CROSSING_M))return{eastM:u.round((o+a)/2),northM:u.round((n+r)/2),headingDeg:(u.heading([(a-o)/i,(r-n)/i])+90)%360,widthM:Math.round(Math.min(i,u.MAX_CROSSING_M)*10)/10}}static marked(t){const e=t.crossing;return e!=="unmarked"&&e!=="no"&&e!=="informal"&&t["crossing:markings"]!=="no"}static directionAt(t){const{points:e,index:s}=t,[o,n]=s<e.length-1?[e[s],e[s+1]]:[e[s-1],e[s]],a=Math.hypot(n[0]-o[0],n[1]-o[1]);return a>0?[(n[0]-o[0])/a,(n[1]-o[1])/a]:void 0}static directionOf(t){const e=t["traffic_signals:direction"]??t["traffic_sign:direction"]??t.direction;return e==="forward"||e==="backward"?e:void 0}static compassOf(t){if(t===void 0)return;const e=Number.parseFloat(t);if(Number.isFinite(e)&&/^\s*-?\d/.test(t))return(e%360+360)%360;const o=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"].indexOf(t.trim().toUpperCase());return o<0?void 0:o*22.5}static faceOf(t){const e=t.traffic_sign;if(!e||e==="no"||e==="none")return;const s=e.split(/[;,]/).map(o=>o.trim());if(s.some(o=>/stop|:AB4\b|:206\b|:R1-1\b|:B2\b/i.test(o)))return{face:"stop"};if(s.some(o=>/give_way|yield|:AB3a\b|:205\b|:R1-2\b|:B1\b/i.test(o)))return{face:"give-way"};for(const o of s){const n=/maxspeed|:B14\b|:274\b|:C14\b|:R2-1\b/i.test(o)?Number.parseInt(/\[(\d+)\]/.exec(o)?.[1]??t.maxspeed??"",10):Number.NaN;if(Number.isFinite(n)&&n>0)return{face:"speed-limit",value:n}}return{face:"other"}}static heading([t,e]){return Math.round((Math.atan2(t,e)*180/Math.PI+360)%360*10)/10}static round(t){return Math.round(t*10)/10}}class nt{id="ign-lidar-hd";name="IGN LiDAR HD";attribution="Canopy and roofs © IGN, LiDAR HD (Licence Ouverte 2.0), as surveyed on a day the service does not give";creditUrl="https://geoservices.ign.fr/lidarhd";contemporary=!0;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","The LiDAR HD survey covers France only");const s=C.lidarRadius(e),[o,n,a,r,i]=await Promise.all([this.platform.lidar(t,s),this.platform.photo(t,s).catch(()=>{}),this.furniture?.near(t,e),this.platform.laserDate(t),this.platform.photoDate(t)]);return{trees:new H(o.heights,o.vegetation,o.size,o.size).trees({metresPerPixel:o.metresPerPixel,radiusM:s}),buildings:_.fit(R.fit(new D(o.heights,o.building,o.size,o.size).buildings({metresPerPixel:o.metresPerPixel,radiusM:s,maxBuildings:300}),o,n)),bridges:[],lines:[],...a,dates:{...r?{laser:r}:{},...n&&i?{photo:i}:{},...u.found(a)?{lamps:u.today()}:{}}}}}class O{static MAP_NATURES={Eglise:"church",Chapelle:"church",Monument:"monument","Tour, donjon":"monument","Fort, blockhaus, casemate":"monument","Arc de triomphe":"monument","Arène ou théâtre antique":"monument",Château:"old","Industriel, agricole ou commercial":"works",Serre:"works",Silo:"works"};static MAP_WORKS=new Set(["Industriel","Agricole","Annexe"]);static MAP_CLOSED_AT_NIGHT=new Set(["Commercial et services","Sportif"]);static OSM_CLOSED_AT_NIGHT=new Set(["retail","commercial","office","supermarket","kiosk","sports_hall","sports_centre","stadium","school","university","college","kindergarten","public","civic","government","train_station","transportation"]);static OSM_BUILDINGS={cathedral:"church",church:"church",chapel:"church",basilica:"church",temple:"church",mosque:"church",synagogue:"church",shrine:"church",religious:"church",castle:"old",palace:"old",fortress:"monument",bunker:"monument",triumphal_arch:"monument",industrial:"works",warehouse:"works",barn:"works",farm_auxiliary:"works",shed:"works",hangar:"works",garage:"works",garages:"works",greenhouse:"works",silo:"works",storage_tank:"works",cowshed:"works",stable:"works",sty:"works",manufacture:"works"};static OSM_HISTORIC={church:"church",chapel:"church",monastery:"old",castle:"old",manor:"old",fort:"monument",tower:"monument",monument:"monument",memorial:"monument",city_gate:"monument"};static OLD_BEFORE=1900;static GRAND_FROM_M=15;static GRAND_UP_TO_M=40;static TOWER_SLENDERNESS=2;static CHURCH_PITCH=.7;static CHURCH_ROOF_OF_WALLS=.35;static CHURCH_ROOF_COLOUR="#5a6068";static ofMap(t){const e=O.year(t.date_d_apparition),o=O.MAP_NATURES[String(t.nature??"")]??(t.usage_1==="Religieux"?"church":void 0)??(O.MAP_WORKS.has(String(t.usage_1??""))?"works":void 0)??O.ofYear(e)??O.grand(t),n=O.MAP_CLOSED_AT_NIGHT.has(String(t.usage_1??""));return{...o?{style:o}:{},...e!==void 0?{builtYear:e}:{},...n?{closedAtNight:!0}:{}}}static ofOsm(t){const e=O.year(t.start_date),s=t.historic&&t.historic!=="no"?O.OSM_HISTORIC[t.historic]??"old":void 0,o=t.amenity==="place_of_worship"?"church":void 0,n=O.OSM_BUILDINGS[t.building??""]??s??o??O.ofYear(e),a=O.OSM_CLOSED_AT_NIGHT.has(t.building??"")||t.shop!==void 0&&t.shop!=="no";return{...n?{style:n}:{},...e!==void 0?{builtYear:e}:{},...a?{closedAtNight:!0}:{}}}static year(t){const e=Number(/\b(\d{4})\b/.exec(String(t??""))?.[1]);return Number.isFinite(e)&&e>=1e3&&e<=2100?e:void 0}static fit(t){return t.map(e=>e.style==="church"?O.church(e):e)}static isTower(t){return t.heightM>=O.TOWER_SLENDERNESS*Math.max(t.widthM,t.lengthM)}static church(t){const e=t.roof?.color??O.CHURCH_ROOF_COLOUR;if(O.isTower(t))return{...t,roof:{shape:"flat",riseM:0,color:e}};if(t.roof&&t.roof.shape!=="flat")return t;const s=Math.round(Math.min(O.CHURCH_PITCH*t.lengthM,O.CHURCH_ROOF_OF_WALLS*t.heightM)*10)/10,o={shape:"gable",riseM:s,color:e};return{...t,heightM:Math.round((t.heightM+s)*10)/10,roof:o}}static ofYear(t){return t!==void 0&&t<O.OLD_BEFORE?"old":void 0}static grand(t){const e=Number(t.hauteur),s=Number(t.nombre_d_etages);if(!(Number.isFinite(s)&&s>0)&&!(t.usage_1==="Résidentiel"||t.date_d_apparition))return e>=O.GRAND_FROM_M&&e<=O.GRAND_UP_TO_M?"grand":void 0}}class b{static METRES_PER_DEGREE=111320;static NAMED_NATURES={Silo:"Silo"};static DEFAULT_HEIGHT_M=6;static FLOOR_HEIGHT_M=3;static FINE_M=.5;static COARSE_M=1;static MAX_CELLS=4e4;static RECTANGLE_FILL=.9;static buildings(t,e,s,o=12,n=300,a=[]){const r=[];for(const h of b.reached(t,a,e,s)){const c=h.feature,l=Number(c.properties.nombre_d_etages),f=Number(c.properties.hauteur),M=Number.isFinite(f)&&f>0?f:Number.isFinite(l)&&l>0?l*b.FLOOR_HEIGHT_M:b.DEFAULT_HEIGHT_M,{style:d,builtYear:g,closedAtNight:m}=O.ofMap(c.properties);for(const E of b.rectanglesOf(h.rings,M,o)){const v=_.of(c.properties.materiaux_des_murs,"wall"),w=_.of(c.properties.materiaux_de_la_toiture,"roof"),p=b.NAMED_NATURES[String(c.properties.nature??"")];r.push({...E,...p?{name:p}:{},...Number.isFinite(l)&&l>0?{floors:l}:{},...v?{wallMaterial:v}:{},...w?{roofMaterial:w}:{},...d?{style:d}:{},...g!==void 0?{builtYear:g}:{},...m?{closedAtNight:m}:{}})}}const i=h=>Math.hypot(h.eastM,h.northM);if(r.length>n){const h=c=>(c.heightM+6)*Math.sqrt(c.widthM*c.lengthM)/Math.max(i(c),50);r.sort((c,l)=>h(l)-h(c)),r.length=n}return r.sort((h,c)=>i(h)-i(c)),r}static named(t,e,s){const o=e.map(n=>({name:typeof n.properties.toponyme=="string"?n.properties.toponyme:"",rings:b.rings(n,s)})).filter(n=>n.name.length>0&&n.rings.length>0);return o.length===0?t:t.map(n=>{const a=o.find(r=>b.inside(n.eastM,n.northM,r.rings));return a?{...n,name:a.name}:n})}static reached(t,e,s,o){const n=t.map(i=>({feature:i,rings:b.rings(i,s)})).filter(i=>i.rings.length>0),a=n.map(i=>b.reach(i.rings)<=o),r=e.filter(i=>typeof i.properties.toponyme=="string"&&i.properties.toponyme.length>0).map(i=>b.rings(i,s)).filter(i=>i.length>0);if(r.length>0){const i=n.map(c=>{const l=c.rings[0],f=l.reduce((d,g)=>d+g.east,0)/l.length,M=l.reduce((d,g)=>d+g.north,0)/l.length;return r.findIndex(d=>b.inside(f,M,d))}),h=new Set(i.filter((c,l)=>c>=0&&a[l]));i.forEach((c,l)=>{h.has(c)&&(a[l]=!0)})}return n.filter((i,h)=>a[h])}static reach(t){if(b.inside(0,0,t))return 0;let e=1/0;for(const s of t)for(let o=0;o+1<s.length;o++){const n=s[o],a=s[o+1],r=a.east-n.east,i=a.north-n.north,h=r*r+i*i>0?Math.max(0,Math.min(1,-(n.east*r+n.north*i)/(r*r+i*i))):0;e=Math.min(e,Math.hypot(n.east+h*r,n.north+h*i))}return e}static inside(t,e,s){let o=0;for(const n of s)for(let a=0;a+1<n.length;a++){const r=n[a],i=n[a+1];r.north<=e!=i.north<=e&&r.east+(e-r.north)/(i.north-r.north)*(i.east-r.east)>t&&o++}return o%2===1}static rings(t,e){const s=t.geometry,o=s.type==="Polygon"?[s.coordinates]:s.type==="MultiPolygon"?s.coordinates:[],n=Math.cos(e.lat*Math.PI/180),a=[];for(const r of o)for(const i of r)a.push(i.map(([h,c])=>({east:(h-e.lng)*b.METRES_PER_DEGREE*n,north:(c-e.lat)*b.METRES_PER_DEGREE})));return a}static rectanglesOf(t,e,s){let o=1/0,n=-1/0,a=1/0,r=-1/0;for(const f of t)for(const M of f)o=Math.min(o,M.east),n=Math.max(n,M.east),a=Math.min(a,M.north),r=Math.max(r,M.north);let i=b.FINE_M;(n-o)*(r-a)/(i*i)>b.MAX_CELLS&&(i=b.COARSE_M);const h=[],c=[];for(let f=a+i/2;f<r;f+=i){const M=[];for(const d of t)for(let g=0;g+1<d.length;g++){const m=d[g],E=d[g+1];m.north<=f!=E.north<=f&&M.push(m.east+(f-m.north)/(E.north-m.north)*(E.east-m.east))}M.sort((d,g)=>d-g);for(let d=0;d+1<M.length;d+=2)for(let g=Math.ceil((M[d]-i/2)/i)*i+i/2;g<M[d+1];g+=i)h.push(g),c.push(f)}if(h.length*i*i<s)return[];const l=t.flatMap(f=>f.slice(0,-1).map((M,d)=>({from:M,to:f[d+1]})));return D.ofPoints(h,c,new Array(h.length).fill(e),i,s,b.RECTANGLE_FILL,l)}}class F{id="ign-lidar-topo";name="IGN LiDAR HD + BD TOPO";attribution="Canopy © IGN, LiDAR HD; buildings, bridges and lines © IGN, BD TOPO (Licence Ouverte 2.0), as surveyed on days the services do not give";creditUrl="https://geoservices.ign.fr/lidarhd";contemporary=!0;static BRIDGE_MARGIN_M=30;static MAX_BRIDGE_WINDOWS=8;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","The IGN's surveys cover France only");const s=C.radius(e),[o,n,a,r,i,h]=await Promise.allSettled([this.platform.lidar(t,s),this.platform.vectors(t,s,!0),this.platform.photo(t,s),this.furniture?.near(t,e)??Promise.resolve(void 0),this.platform.laserDate(t),this.platform.photoDate(t)]),c=C.lidarRadius(s);if(o.status==="rejected"&&n.status==="rejected")throw o.reason;const l=o.status==="fulfilled"?o.value:void 0,f=n.status==="fulfilled"?n.value:void 0,M=f!==void 0&&f.buildings.length===0&&f.bridges.length===0&&f.lines.length===0;if(o.status==="rejected"&&o.reason instanceof V&&o.reason.reason==="no-coverage"&&M)throw o.reason;return{trees:l?new H(l.heights,l.vegetation,l.size,l.size).trees({metresPerPixel:l.metresPerPixel,radiusM:c}):[],buildings:this.roofed(this.buildings(l,f,t,s),l,a.status==="fulfilled"?a.value:void 0),bridges:f?await this.bridges(f,t,s,l?.structures,c):[],lines:f?X.lines(f,t,s,l?.structures):[],...r.status==="fulfilled"?r.value:{},dates:{...o.status==="fulfilled"&&i.status==="fulfilled"&&i.value?{laser:i.value}:{},...a.status==="fulfilled"&&h.status==="fulfilled"&&h.value?{photo:h.value}:{},...f?.mapDate?{map:f.mapDate}:{},...r.status==="fulfilled"&&u.found(r.value)?{lamps:u.today()}:{}}}}async bridges(t,e,s,o,n){const a=X.bridges(t,e,s,o);let r=0;return Promise.all(a.map(async i=>{if(o!==void 0&&Math.hypot(i.eastM,i.northM)+i.lengthM/2<=n)return i;const h=i.lengthM/2+F.BRIDGE_MARGIN_M;if(r++>=F.MAX_BRIDGE_WINDOWS)return i;const c=ot(i.eastM,-i.northM,e.lat,e.lng);try{const l=await this.platform.lidar(c,h),f=X.bridges(t,c,h,l.structures).sort((M,d)=>Math.hypot(M.eastM,M.northM)-Math.hypot(d.eastM,d.northM))[0];return!f||Math.hypot(f.eastM,f.northM)>i.lengthM/2?i:{...f,eastM:X.tenth(f.eastM+i.eastM),northM:X.tenth(f.northM+i.northM)}}catch{return i}}))}roofed(t,e,s){return _.fit(O.fit(R.fit(t,e,s)))}buildings(t,e,s,o){const n=e?b.buildings(e.buildings,s,o,void 0,void 0,e.zones):[],a=n.length>0||t===void 0?n:new D(t.heights,t.building,t.size,t.size).buildings({metresPerPixel:t.metresPerPixel,radiusM:C.lidarRadius(o),maxBuildings:300});return e?b.named(a,e.zones,s):a}}class at{id="ign-bd-topo";name="IGN BD TOPO";attribution="Buildings, bridges and lines © IGN, BD TOPO (Licence Ouverte 2.0), as drawn on a day the service does not give";creditUrl="https://geoservices.ign.fr/bdtopo";contemporary=!0;platform;furniture;constructor(t={},e){this.platform=new C(t),this.furniture=e}covers(t,e){return C.covers(t,e)}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){if(!this.covers(t.lat,t.lng))throw new V("no-coverage","BD TOPO covers France only");const s=C.radius(e),[o,n,a,r]=await Promise.all([this.platform.vectors(t,s,!0),this.platform.photo(t,s).catch(()=>{}),this.furniture?.near(t,e),this.platform.photoDate(t)]);return{trees:[],buildings:_.fit(O.fit(R.fit(b.named(b.buildings(o.buildings,t,s,void 0,void 0,o.zones),o.zones,t),void 0,n))),bridges:X.bridges(o,t,s,void 0),lines:X.lines(o,t,s,void 0),...a,dates:{...o.mapDate?{map:o.mapDate}:{},...n&&r?{photo:r}:{},...u.found(a)?{lamps:u.today()}:{}}}}}class S{static ROOF_SHAPES={flat:"flat",gabled:"gable",gambrel:"gable",saltbox:"gable","half-hipped":"hip",hipped:"hip",pyramidal:"hip",mansard:"hip",round:"gable",dome:"dome",onion:"dome"};static WALL_MATERIALS={brick:"brick",stone:"stone",granite:"stone",sandstone:"stone",limestone:"stone",concrete:"concrete",cement_block:"block",block:"block",wood:"wood",timber_framing:"wood"};static ROOF_MATERIALS={roof_tiles:"tile",tiles:"tile",tile:"tile",slate:"slate",metal:"zinc",zinc:"zinc",tin:"zinc",copper:"zinc",concrete:"concrete",eternit:"other"};static COLOURS={white:"#e8e6e0",grey:"#8c8c8a",gray:"#8c8c8a",black:"#3a3a3a",red:"#a8483a",brown:"#6e4f38",beige:"#d6c9a8",yellow:"#d8c070",orange:"#c9773a",green:"#5f7a52",blue:"#506a8a",tan:"#c0a37a",cream:"#e6dcc0",pink:"#c99a96",silver:"#b4b6b6"};static height(t){const e=Number.parseFloat((t??"").replace(",","."));return Number.isFinite(e)&&e>=2&&e<=500?e:void 0}static levels(t){const e=Number.parseInt(t??"",10);return Number.isFinite(e)&&e>=1&&e<=150?e:void 0}static roofShape(t){return S.ROOF_SHAPES[(t??"").trim().toLowerCase()]}static wallMaterial(t){return S.WALL_MATERIALS[(t??"").trim().toLowerCase()]}static roofMaterial(t){return S.ROOF_MATERIALS[(t??"").trim().toLowerCase()]}static colour(t){const e=(t??"").trim().toLowerCase();return/^#[0-9a-f]{6}$/.test(e)?e:/^#[0-9a-f]{3}$/.test(e)?`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`:S.COLOURS[e]}}class W{id="osm-buildings";name="OpenStreetMap buildings";attribution="Buildings © OpenStreetMap contributors (ODbL), as drawn on the day of the data, which a recording is not";creditUrl="https://www.openstreetmap.org/copyright";contemporary=!0;static MAX_RADIUS_M=1500;static MIN_AREA_M2=12;static MAX_BUILDINGS=300;client;furniture;constructor(t={},e){this.client=new tt(t),this.furniture=e}covers(){return!0}later(t,e){return u.later(this.furniture,t,e)}async getSurroundings(t,e){const s=Math.min(e,W.MAX_RADIUS_M);let o;try{o=await this.client.query(`[out:json][timeout:30];(way["building"](around:${s},${t.lat},${t.lng});relation["building"]["type"="multipolygon"](around:${s},${t.lat},${t.lng}););out geom;`)}catch(r){throw new V("unreachable",r instanceof Error?r.message:String(r))}const n=await this.furniture?.near(t,e),a=(o.osm3s?.timestamp_osm_base??"").slice(0,10);return{trees:[],buildings:_.fit(O.fit(W.buildings(o,t,s))),bridges:[],lines:[],...n,dates:{.../^\d{4}-\d{2}-\d{2}$/.test(a)?{map:a}:{},...u.found(n)?{lamps:u.today()}:{}}}}static buildings(t,e,s){const o=[];for(const n of t.elements??[]){const a=W.ringsOf(n);if(a.length===0)continue;const r=n.tags??{},i=S.levels(r["building:levels"]),h=S.height(r.height),c={geometry:{type:"Polygon",coordinates:a},properties:{...h?{hauteur:h}:{},...i?{nombre_d_etages:i}:{}}};for(const l of b.buildings([c],e,s,W.MIN_AREA_M2,50))o.push(W.described(l,r,h!==void 0))}return o.sort((n,a)=>Math.hypot(n.eastM,n.northM)-Math.hypot(a.eastM,a.northM)),o.slice(0,W.MAX_BUILDINGS)}static ringsOf(t){const e=o=>{if(!o||o.length<4)return;const n=o.map(i=>[i.lon,i.lat]),a=n[0],r=n[n.length-1];return a[0]===r[0]&&a[1]===r[1]?n:void 0};if(t.type==="way"){const o=e(t.geometry);return o?[o]:[]}return(t.members??[]).filter(o=>o.role==="outer").map(o=>e(o.geometry)).filter(o=>o!==void 0).slice(0,1)}static described(t,e,s){const o=S.wallMaterial(e["building:material"]),n=S.roofMaterial(e["roof:material"]),a=S.colour(e["building:colour"]),r=S.colour(e["roof:colour"])??_.roofColor(n),i=S.roofShape(e["roof:shape"]),h=a?{color:a}:void 0;let c,l=t.heightM;if(i==="gable"||i==="hip"||i==="dome"){const g=S.height(e["roof:height"]),m=Math.round((g??Math.min(5,Math.max(1.5,.29*Math.min(t.widthM,t.lengthM))))*10)/10;s||(l=Math.round((t.heightM+m)*10)/10),c={shape:i,riseM:m,...e["roof:orientation"]==="across"?{ridge:"depth"}:{},...r?{color:r}:{}}}else(i==="flat"||r)&&(c={shape:"flat",riseM:0,...r?{color:r}:{}});const{style:f,builtYear:M,closedAtNight:d}=O.ofOsm(e);return{...t,heightM:l,...f?{style:f}:{},...M!==void 0?{builtYear:M}:{},...d?{closedAtNight:d}:{},...e.name?{name:e.name}:{},...o?{wallMaterial:o}:{},...n?{roofMaterial:n}:{},...h?{facade:h}:{},...c?{roof:c}:{}}}}class L{credit={name:"Ville de Paris, Éclairage public",url:"https://opendata.paris.fr/explore/dataset/eclairage-public/",licence:"ODbL",of:"lamps"};static BOUNDS={south:48.8156,north:48.9022,west:2.2241,east:2.4698};static ENDPOINT="https://opendata.paris.fr/api/explore/v2.1/catalog/datasets/eclairage-public/records";static PAGE=100;static MAX=150;static MAX_PAGES=4;static METRES_PER_DEGREE=111320;static SAME_COLUMN_M=.5;static MIN_HEIGHT_M=2;fetchImpl;constructor(t){this.fetchImpl=t??fetch.bind(globalThis)}covers(t,e){const s=L.BOUNDS;return t>=s.south&&t<=s.north&&e>=s.west&&e<=s.east}async lampsNear(t,e){const s=[];let o=[];for(let n=0;n<L.MAX_PAGES&&o.length<L.MAX;n++){const a=await this.fetchImpl(L.query(t,e,L.PAGE,n*L.PAGE));if(!a.ok)throw new Error(`opendata.paris.fr refused (${a.status})`);const r=(await a.json()).results??[];if(s.push(...r),o=L.lampsFrom(s,t),r.length<L.PAGE)break}return o.slice(0,L.MAX)}static query(t,e,s,o){const n=`geom'POINT(${t.lng.toFixed(6)} ${t.lat.toFixed(6)})'`,a=new URLSearchParams({select:"geo_point_2d,lib_ouvrag,lampe_temperature_couleur,lampe_flux,support_hauteur",where:`within_distance(geo_point_2d,${n},${Math.round(e)}m)`,order_by:`distance(geo_point_2d,${n})`,limit:String(s),offset:String(o)});return`${L.ENDPOINT}?${a}`}static lampsFrom(t,e){const s=Math.cos(e.lat*Math.PI/180),o=a=>{const r=typeof a=="number"?a:Number.parseFloat(a??"");return Number.isFinite(r)&&r>0?r:void 0},n=[];for(const a of t){const r=a.geo_point_2d;if(!r||a.lib_ouvrag==="Projecteur")continue;const i=Math.round((r.lon-e.lng)*L.METRES_PER_DEGREE*s*10)/10,h=Math.round((r.lat-e.lat)*L.METRES_PER_DEGREE*10)/10,c=o(a.lampe_flux),l=n.find(d=>Math.hypot(d.eastM-i,d.northM-h)<L.SAME_COLUMN_M);if(l){c!==void 0&&(l.lumens=(l.lumens??0)+c);continue}const f=o(a.lampe_temperature_couleur),M=o(a.support_hauteur);n.push({eastM:i,northM:h,...M!==void 0&&M>=L.MIN_HEIGHT_M?{heightM:M}:{},...f!==void 0?{colorTemperatureK:f}:{},...c!==void 0?{lumens:c}:{},...a.lib_ouvrag==="Console"?{mount:"wall"}:{}})}return n}}class T{constructor(t,e){this.roads=t,this.fetchImpl=e??fetch.bind(globalThis)}credit={name:"Ville de Paris, Signalisation lumineuse tricolore",url:"https://opendata.paris.fr/explore/dataset/signalisation-tricolore/",licence:"ODbL",of:"signals"};static BOUNDS={south:48.8156,north:48.9022,west:2.2241,east:2.4698};static ENDPOINT="https://opendata.paris.fr/api/explore/v2.1/catalog/datasets/signalisation-tricolore/records";static PAGE=100;static MAX_PAGES=5;static MAX=160;static METRES_PER_DEGREE=111320;static SAME_POST_M=.8;static SEARCH_M=15;static PEDESTRIAN_ALONG_M=.4;fetchImpl;covers(t,e){const s=T.BOUNDS;return t>=s.south&&t<=s.north&&e>=s.west&&e<=s.east}async signalsNear(t,e){const s=(e+T.SEARCH_M)/T.METRES_PER_DEGREE,o=s/Math.cos(t.lat*Math.PI/180),[n,a]=await Promise.all([this.lenses(t,e),this.roads.getRoads({south:t.lat-s,north:t.lat+s,west:t.lng-o,east:t.lng+o})]);return T.signalsFrom(n,a,t)}async lenses(t,e){const s=[];for(let o=0;o<T.MAX_PAGES;o++){const n=await this.fetchImpl(T.query(t,e,T.PAGE,o*T.PAGE));if(!n.ok)throw new Error(`opendata.paris.fr refused (${n.status})`);const a=(await n.json()).results??[];if(s.push(...a),a.length<T.PAGE)break}return s}static query(t,e,s,o){const n=`geom'POINT(${t.lng.toFixed(6)} ${t.lat.toFixed(6)})'`,a=new URLSearchParams({select:"geo_point_2d,lib_regime",where:`within_distance(geo_point_2d,${n},${Math.round(e)}m)`,order_by:`distance(geo_point_2d,${n})`,limit:String(s),offset:String(o)});return`${T.ENDPOINT}?${a}`}static signalsFrom(t,e,s){const o=Math.cos(s.lat*Math.PI/180),n=(h,c)=>[(c-s.lng)*T.METRES_PER_DEGREE*o,(h-s.lat)*T.METRES_PER_DEGREE],a=[];for(const h of t){if(!h.geo_point_2d)continue;const c=n(h.geo_point_2d.lat,h.geo_point_2d.lon),l=(h.lib_regime??"").toUpperCase(),f=/ROUGE|JAUNE|VERT/.test(l),M=/PASSEZ|ATTENDEZ/.test(l);if(!f&&!M)continue;let d=a.find(g=>Math.hypot(g.at[0]-c[0],g.at[1]-c[1])<T.SAME_POST_M);d||a.push(d={at:c,vehicles:0,pedestrians:0}),f&&d.vehicles++,M&&d.pedestrians++}const r=e.map(h=>({way:h,points:h.points.map(c=>n(c.lat,c.lng))})),i=[];for(const h of a){const c=T.nearestRoad(h.at,r);if(!c)continue;const[l,f]=c.unit,M=T.heading(c.unit),d=(h.at[0]-c.foot[0])*f-(h.at[1]-c.foot[1])*l>=0,g=c.way.direction,m=g==="forward"?M:g==="backward"?(M+180)%360:d?M:(M+180)%360,E=w=>Math.round(w*10)/10,v=w=>E((w%360+360)%360);if(h.vehicles>0&&i.push({eastM:E(h.at[0]),northM:E(h.at[1]),headingDeg:v(m+180),for:"vehicles",phase:j.phaseOf(m)}),h.pedestrians>0){const w=T.heading([c.foot[0]-h.at[0],c.foot[1]-h.at[1]]),p=h.vehicles>0?T.PEDESTRIAN_ALONG_M:0;i.push({eastM:E(h.at[0]+l*p),northM:E(h.at[1]+f*p),headingDeg:v(Number.isNaN(w)?M+90:w),for:"pedestrians",phase:j.phaseOf(M)})}}return i.sort((h,c)=>Math.hypot(h.eastM,h.northM)-Math.hypot(c.eastM,c.northM)).slice(0,T.MAX)}static nearestRoad(t,e){let s;for(const{way:o,points:n}of e)for(let a=1;a<n.length;a++){const[r,i]=n[a-1],[h,c]=n[a],l=Math.hypot(h-r,c-i);if(l===0)continue;const f=[(h-r)/l,(c-i)/l],M=Math.max(0,Math.min(l,(t[0]-r)*f[0]+(t[1]-i)*f[1])),d=[r+f[0]*M,i+f[1]*M],g=Math.hypot(t[0]-d[0],t[1]-d[1]);g<=T.SEARCH_M&&(!s||g<s.distance)&&(s={way:o,unit:f,foot:d,distance:g})}return s}static heading([t,e]){return t===0&&e===0?Number.NaN:Math.round((Math.atan2(t,e)*180/Math.PI+360)%360*10)/10}}const K=B.point("surroundings").provide(B.BUILT_IN,[{id:"ign-lidar-topo",name:"IGN LiDAR HD + BD TOPO",credit:"© IGN, LiDAR HD and BD TOPO, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>new I(new F({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"ign-lidar-hd",name:"IGN LiDAR HD",credit:"© IGN, LiDAR HD, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/lidarhd",create:()=>new I(new nt({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"ign-bd-topo",name:"IGN BD TOPO",credit:"© IGN, BD TOPO, Licence Ouverte 2.0; street lamps © OpenStreetMap contributors",creditUrl:"https://geoservices.ign.fr/bdtopo",create:()=>new I(new at({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))},{id:"osm-buildings",name:"OpenStreetMap buildings",credit:"Buildings and street lamps © OpenStreetMap contributors (ODbL)",creditUrl:"https://www.openstreetmap.org/copyright",create:()=>new I(new W({},new u({},U.TOWN_LAMPS,U.TOWN_SIGNALS)))}]);class U{static DEFAULT_ID=K[0].id;static WORLD_ID="osm-buildings";static TOWN_LAMPS=[new L];static TOWN_SIGNALS=[new T(new et)];static NONE="none";static byId(t){return t===U.NONE?void 0:K.find(e=>e.id===t)??K[0]}static providerFor(t,e,s){const o=U.byId(t)?.create();if(t!==void 0&&t!==U.DEFAULT_ID)return o?.covers(e,s)?o:void 0;const n=K.find(r=>r.id===U.WORLD_ID).create(),a=[o,n].filter(r=>r!==void 0&&r.covers(e,s));return a.length>1?new st(a):a[0]}}export{K as SURROUNDINGS_SOURCES,U as SurroundingsSources};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{aT as et,aU as g,aV as It,aW as Z,p as j,aX as N,aY as Dt,aZ as st,a_ as it}from"./ShareDialogElement-DLr5u_tk.js";import{C as ot}from"./ContrailGrowth-DwHS8If9.js";import{U as Ae}from"./upperAirSources-BGuLpdwu.js";import{p as V,r as Tt}from"./Decor-Dn-cvniW.js";import{l as at}from"./SaidPosition-CWiVNaNW.js";import"./rr0-ufoathome.mjs";import"./Sighting-CBpJpdm9.js";import"./VisualAids-DI-hEL46.js";import"./RecordingIssue-BlWT8Xsu.js";import"./Obstacles-v9SkfBD7.js";const Rt=.25,rt=.4,ct=6,X=12,Bt=3,lt=.2,vt=.2,ht=24,Nt=3,Ct=24,ut=1,_t=.7,Ht=1.5,wt=.8,yt=1.3,dt=.02,Pt=700,kt=-30,pt=.9,mt=5,Lt=25,Ft=.5,jt=.12,Mt=[.13,.31],Gt=.16,Ut=1.6,Kt=2,zt=3.6,At=1.1,Wt=.3,Vt=1e3,gt=.7,Xt=.7;class Y{context;constructor(t){this.context=t}noiseBuffer;roughBuffers=new Map;voices=new Map;bus;reverb;reverbOut;level=1;master;paused=!0;requested=[];headingDeg=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("AircraftAudio: Web Audio unavailable, aircraft stay silent:",t);return}}et.isLive(this.context)&&et.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t,e=0){this.requested=t,this.headingDeg=e,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);et.isLive(this.context)&&this.context.close(),this.context=void 0,this.master=void 0,this.bus=void 0}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested,a=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])a.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n);this.retarget(t,s,n)}}build(t,e){const a=t.createGain();a.gain.value=0;let n;const s=this.busOf(t);typeof t.createStereoPanner=="function"?(n=t.createStereoPanner(),a.connect(n).connect(s)):a.connect(s);const i=t.createGain(),o=e.character?.modulationDepth??0;i.gain.value=1-o/2;const r=t.createOscillator();r.type="sine";const l=t.createGain();l.gain.value=o/2,r.connect(l).connect(i.gain),i.connect(a);const c=t.createBufferSource();c.buffer=this.noise(t),c.loop=!0,c.loopStart=Math.random()*ct*.5;const u=[],d=[],h=[];for(const D of g.OCTAVES){const I=t.createBiquadFilter();I.type="bandpass",I.frequency.value=D,I.Q.value=ut;const H=t.createBiquadFilter();H.type="bandpass",H.frequency.value=D,H.Q.value=ut;const P=t.createGain();P.gain.value=0,c.connect(I).connect(H).connect(P).connect(i),u.push(I),d.push(H),h.push(P)}const p=[];for(const[D,I]of[[e.character?.toneHz,e.character?.toneShare],[e.character?.humHz,e.character?.humShare]])if(D!==void 0)for(let H=1;H<=Nt;H++){const P=t.createOscillator();P.type="sine",P.frequency.value=D*H;const tt=t.createGain();tt.gain.value=0,P.connect(tt).connect(a),p.push({oscillator:P,gain:tt,harmonic:H,baseHz:D,share:I??0})}const m=t.createGain();m.gain.value=0,m.connect(a.gain);const E=Mt.map(D=>{const I=t.createOscillator();return I.type="sine",I.frequency.value=D,I.connect(m),I}),O=t.createGain();O.gain.value=e.character?.roughness??lt;const B=t.createBufferSource();B.buffer=this.roughTable(t,Bt),B.loop=!0,B.loopStart=Math.random()*X*.5,B.connect(O).connect(i.gain);const v=t.createGain();v.gain.value=(e.character?.roughness??lt)*vt;const S=t.createBufferSource();S.buffer=this.roughTable(t,ht),S.loop=!0,S.loopStart=Math.random()*X*.5,S.connect(v).connect(i.gain);let F;const x=this.busOf(t)&&this.reverb;x&&(F=t.createGain(),F.gain.value=0,a.connect(F).connect(x));let L,_;if(!e.inside&&typeof t.createDelay=="function"){const D=t.createDelay(dt);D.delayTime.value=0;const I=t.createBiquadFilter();I.type="highshelf",I.frequency.value=Pt,I.gain.value=0;const H=t.createGain();H.gain.value=0,a.connect(D).connect(I).connect(H).connect(n??s);const P=t.createGain();P.gain.value=0,_=t.createBufferSource(),_.buffer=this.roughTable(t,ht),_.loop=!0,_.loopStart=Math.random()*X*.5,_.connect(P).connect(D.delayTime),L={delay:D,jitter:P,shelf:I,gain:H}}const k=[c,B,S,r,...p.map(D=>D.oscillator),...E,..._?[_]:[]];for(const D of k)D.start();const $={nodes:[a,i,l,O,v,m,...L?[L.delay,L.jitter,L.shelf,L.gain]:[],...p.map(D=>D.gain),...u,...d,...h,...F?[F]:[],...n?[n]:[],...k],sources:k,filters:u,seconds:d,gains:h,tones:p,lfo:r,lfoDepth:l,wander:E,wanderDepth:m,roughDepth:O,crackleDepth:v,beat:i,output:a,panner:n,send:F,echo:L};return this.voices.set(e.id,$),$}retarget(t,e,a){const n=t.currentTime,s=(p,m)=>p.setTargetAtTime(m,n,Rt),i=Math.min(Ht,Math.max(_t,a.dopplerRatio)),o=Math.min(yt,Math.max(wt,Math.sqrt(a.dopplerRatio))),r=t.sampleRate*.45,l=a.bandAmplitudes.map((p,m)=>p*Y.unweighting(g.OCTAVES[m])),c=Math.sqrt(l.reduce((p,m)=>p+m*m,0)),u=Math.min(1,Math.max(0,(a.distanceKm-mt)/(Lt-mt)));g.OCTAVES.forEach((p,m)=>{s(e.filters[m].frequency,Math.min(r,p*o)),s(e.seconds[m].frequency,Math.min(r,p*o)),s(e.gains[m].gain,l[m]*Math.sqrt(Vt/p))});const d=a.character;for(const{oscillator:p,gain:m,harmonic:E,baseHz:O,share:B}of e.tones){const v=O*E;s(p.frequency,v*i);const S=v*i;s(m.gain,S<r?B*Gt*l[Y.bandOf(S)]/E:0)}d?.modulationHz!==void 0&&s(e.lfo.frequency,d.modulationHz*i);const h=c>0?Y.saturated(c)/c:1;if(s(e.output.gain,h*(1-Wt*u)),s(e.wanderDepth.gain,h*jt*u/Mt.length),e.send&&s(e.send.gain,Y.reverbSend(a.distanceKm)),e.echo){const p=a.groundEcho;s(e.echo.gain.gain,p?.lowGain??0),p&&(s(e.echo.delay.delayTime,Math.min(dt,p.delayS)),s(e.echo.jitter.gain,p.jitterS),s(e.echo.shelf.gain,p.lowGain>0?Math.max(kt,20*Math.log10(Math.max(p.highGain,1e-6)/p.lowGain)):0))}if(e.panner){const p=(a.azimuthDeg-this.headingDeg)*Math.PI/180,m=a.inside?0:Math.max(-pt,Math.min(pt,Math.sin(p)))*(1-Ft*u);s(e.panner.pan,m)}}static saturated(t){const e=Xt*gt;if(t<=e)return t;const a=gt-e;return e+a*(1-Math.exp(-(t-e)/a))}static reverbSend(t){return Math.min(Ut,Math.sqrt(Math.max(0,t)/Kt))}static unweighting(t){return 10**(Math.min(Ct,Math.max(0,-g.aWeightingDb(t)))/20)}static bandOf(t){let e=0;return g.OCTAVES.forEach((a,n)=>{Math.abs(Math.log(t/a))<Math.abs(Math.log(t/g.OCTAVES[e]))&&(e=n)}),e}roughTable(t,e){const a=this.roughBuffers.get(e);if(a)return a;const n=Math.floor(t.sampleRate*X),s=t.createBuffer(1,n,t.sampleRate),i=s.getChannelData(0),o=Array.from({length:X*e},()=>(Math.random()*2-1)**3),r=t.sampleRate/e;for(let l=0;l<i.length;l++){const c=l/r,u=Math.floor(c),d=c-u,h=d*d*(3-2*d);i[l]=o[u%o.length]*(1-h)+o[(u+1)%o.length]*h}return this.roughBuffers.set(e,s),s}roomImpulse(t){const e=Math.floor(t.sampleRate*zt),a=t.createBuffer(2,e,t.sampleRate);for(let n=0;n<2;n++){const s=a.getChannelData(n);let i=0;for(let o=0;o<e;o++){const r=o/t.sampleRate,l=.6*Math.exp(-r/(At*2))+.04;i+=l*(Math.random()*2-1-i),s[o]=i*Math.exp(-r/At)}}return a}busOf(t){if(this.bus)return this.bus;const e=t.createGain();if(e.gain.value=this.level,e.connect(t.destination),this.master=e,typeof t.createConvolver=="function"){const a=t.createConvolver();a.buffer=this.roomImpulse(t);const n=t.createGain();n.gain.value=.9,a.connect(n),this.reverb=a,this.reverbOut=n}if(typeof t.createDynamicsCompressor=="function"){const a=t.createDynamicsCompressor();a.threshold.value=-6,a.knee.value=3,a.ratio.value=4,a.attack.value=.005,a.release.value=.25,a.connect(e),this.bus=a}else this.bus=e;return this.reverbOut?.connect(this.bus),this.bus}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const a=this.context;a&&(e.output.gain.setTargetAtTime(0,a.currentTime,rt/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},rt*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*ct,t.sampleRate),a=e.getChannelData(0);for(let n=0;n<a.length;n++)a[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class U{static TYPES={A318:["Airbus A318","airliner-narrow",34.1,31.4],A319:["Airbus A319","airliner-narrow",34.1,33.8],A320:["Airbus A320","airliner-narrow",34.1,37.6],A321:["Airbus A321","airliner-narrow",34.1,44.5],A19N:["Airbus A319neo","airliner-narrow",35.8,33.8],A20N:["Airbus A320neo","airliner-narrow",35.8,37.6],A21N:["Airbus A321neo","airliner-narrow",35.8,44.5],B737:["Boeing 737-700","airliner-narrow",34.3,33.6],B738:["Boeing 737-800","airliner-narrow",35.8,39.5],B739:["Boeing 737-900","airliner-narrow",35.8,42.1],B38M:["Boeing 737 MAX 8","airliner-narrow",35.9,39.5],B39M:["Boeing 737 MAX 9","airliner-narrow",35.9,42.2],B752:["Boeing 757-200","airliner-narrow",38,47.3],B753:["Boeing 757-300","airliner-narrow",38,54.4],B762:["Boeing 767-200","airliner-wide",47.6,48.5],B763:["Boeing 767-300","airliner-wide",47.6,54.9],B764:["Boeing 767-400","airliner-wide",51.9,61.4],B772:["Boeing 777-200","airliner-wide",60.9,63.7],B77L:["Boeing 777-200LR","airliner-wide",64.8,63.7],B77W:["Boeing 777-300ER","airliner-wide",64.8,73.9],B788:["Boeing 787-8","airliner-wide",60.1,56.7],B789:["Boeing 787-9","airliner-wide",60.1,62.8],B78X:["Boeing 787-10","airliner-wide",60.1,68.3],B744:["Boeing 747-400","airliner-wide",64.4,70.7],B748:["Boeing 747-8","airliner-wide",68.4,76.3],A306:["Airbus A300-600","airliner-wide",44.8,54.1],A310:["Airbus A310","airliner-wide",43.9,46.7],A332:["Airbus A330-200","airliner-wide",60.3,58.8],A333:["Airbus A330-300","airliner-wide",60.3,63.7],A338:["Airbus A330-800","airliner-wide",64,58.8],A339:["Airbus A330-900","airliner-wide",64,63.7],A343:["Airbus A340-300","airliner-wide",60.3,63.7],A346:["Airbus A340-600","airliner-wide",63.5,75.4],A359:["Airbus A350-900","airliner-wide",64.8,66.8],A35K:["Airbus A350-1000","airliner-wide",64.8,73.8],A388:["Airbus A380-800","airliner-wide",79.8,72.7],CONC:["Concorde","airliner-supersonic",25.6,61.7],DC3:["Douglas DC-3","piston-heavy",29,19.7],DC4:["Douglas DC-4","piston-heavy",35.8,28.6],P51:["North American P-51 Mustang","piston-heavy",11.3,9.8],E170:["Embraer 170","regional-jet",26,29.9],E75L:["Embraer 175","regional-jet",26,31.7],E75S:["Embraer 175","regional-jet",26,31.7],E190:["Embraer 190","regional-jet",28.7,36.2],E195:["Embraer 195","regional-jet",28.7,38.7],E290:["Embraer 190-E2","regional-jet",33.7,36.2],E295:["Embraer 195-E2","regional-jet",33.7,41.5],CRJ2:["Bombardier CRJ200","regional-jet",21.2,26.8],CRJ7:["Bombardier CRJ700","regional-jet",23.2,32.3],CRJ9:["Bombardier CRJ900","regional-jet",24.9,36.2],CRJX:["Bombardier CRJ1000","regional-jet",26.2,39.1],AT72:["ATR 72","regional-turboprop",27.1,27.2],AT76:["ATR 72-600","regional-turboprop",27.1,27.2],AT45:["ATR 42","regional-turboprop",24.6,22.7],DH8D:["Dash 8 Q400","regional-turboprop",28.4,32.8],DH8C:["Dash 8-300","regional-turboprop",27.4,25.7],SF34:["Saab 340","regional-turboprop",21.4,19.7],B190:["Beechcraft 1900","regional-turboprop",17.7,17.6],C25A:["Cessna CitationJet CJ2","business-jet",14.3,14.4],C56X:["Cessna Citation Excel","business-jet",17.2,16],C68A:["Cessna Citation Latitude","business-jet",22,18.9],C550:["Cessna Citation II","business-jet",15.8,14.4],E55P:["Embraer Phenom 300","business-jet",15.9,15.6],E50P:["Embraer Phenom 100","business-jet",12.3,12.8],GLF5:["Gulfstream G550","business-jet",28.5,29.4],FA7X:["Dassault Falcon 7X","business-jet",26.2,23.4],CL60:["Bombardier Challenger 600","business-jet",19.6,20.9],LJ45:["Learjet 45","business-jet",14.6,17.7],H25B:["Hawker 800","business-jet",15.7,15.6],C172:["Cessna 172","light-piston",11,8.3],C152:["Cessna 152","light-piston",10.2,7.3],C182:["Cessna 182","light-piston",10.9,8.8],P28A:["Piper Cherokee","light-piston",10.7,7.2],PA34:["Piper Seneca","light-piston",11.8,8.7],SR20:["Cirrus SR20","light-piston",10.9,7.9],SR22:["Cirrus SR22","light-piston",11.7,7.9],S22T:["Cirrus SR22T","light-piston",11.7,7.9],DA40:["Diamond DA40","light-piston",11.6,8.1],DA42:["Diamond DA42","light-piston",13.4,8.6],BE20:["Beechcraft King Air 200","turboprop-light",16.6,13.3],BE58:["Beechcraft Baron","light-piston",11.5,9.1],C208:["Cessna Caravan","turboprop-light",15.9,11.5],PC12:["Pilatus PC-12","turboprop-light",16.3,14.4],TBM9:["Daher TBM 900","turboprop-light",12.8,10.7],EC35:["Airbus H135","helicopter-light",10.2,12.1],EC45:["Airbus H145","helicopter-medium",11,13.6],AS50:["Airbus H125","helicopter-light",10.7,12.9],EC30:["Airbus H130","helicopter-light",10.7,12.6],B407:["Bell 407","helicopter-light",10.7,12.7],B06:["Bell 206","helicopter-light",10.2,12],B429:["Bell 429","helicopter-medium",10.9,13],B505:["Bell 505","helicopter-light",10.4,11.9],R44:["Robinson R44","helicopter-light",10.1,11.7],R22:["Robinson R22","helicopter-light",7.7,8.8],A109:["Agusta A109","helicopter-medium",11,13],A139:["Leonardo AW139","helicopter-medium",13.8,16.7],S92:["Sikorsky S-92","helicopter-heavy",17.2,20.9],H60:["Sikorsky UH-60 Black Hawk","helicopter-heavy",16.4,19.8],T38:["Northrop T-38 Talon","military-jet",7.7,14.1],HAWK:["BAE Hawk","military-jet",9.4,11.9],GLID:["Glider","glider",17,7],BALL:["Balloon","balloon",15,20],ULAC:["Ultralight","ultralight",9.5,6],C42:["Ikarus C42","ultralight",9.4,6.3],DRON:["Drone","unmanned",1,.6]};static CATEGORIES={A1:["Light aircraft","light-piston",11,8.3],A2:["Small aircraft","business-jet",15,15],A3:["Large aircraft","airliner-narrow",34.1,37.6],A4:["High-vortex large aircraft","airliner-narrow",38,47.3],A5:["Heavy aircraft","airliner-wide",60.3,63.7],A6:["High-performance aircraft","military-jet",8,14],A7:["Rotorcraft","helicopter-medium",10.7,12.7],B1:["Glider","glider",17,7],B2:["Lighter-than-air","balloon",15,20],B4:["Ultralight","ultralight",9.5,6],B6:["Unmanned aircraft","unmanned",1.5,1]};static GENERIC={name:"Airliner",kind:"airliner-narrow",spanM:34.1,lengthM:37.6,basis:"nothing"};static of(t){const e=t?.type?.toUpperCase(),a=e?U.TYPES[e]:void 0;if(a)return{code:e,name:a[0],kind:a[1],spanM:a[2],lengthM:a[3],basis:"type"};const n=t?.category?U.CATEGORIES[t.category]:void 0;return n?{name:n[0],kind:n[1],spanM:n[2],lengthM:n[3],basis:"category"}:{...U.GENERIC}}static isHelicopter(t){return t.kind.startsWith("helicopter")}}class C{static DUSK_SUN_ELEVATION_DEG=-.83;static ALWAYS=new Set(["airliner-narrow","airliner-wide","airliner-supersonic","regional-turboprop","regional-jet","business-jet"]);static NONE=new Set(["glider","balloon"]);static BRIGHTNESS={"light-piston":[.5,.2,.5],"turboprop-light":[.7,.4,.8],ultralight:[.4,.2,.4],unmanned:[0,.05,0],"helicopter-light":[1,1,1],"helicopter-medium":[1,1,1],"helicopter-heavy":[1,1,1],"military-jet":[1,1,1]};static LANDING_LIGHTS_BELOW_FT=1e4;static LANDING_INTENSITY=600;static LANDING_BEAM_DEG=10;static LANDING_COLOR="#fff1dc";static LANDING_BRIGHTNESS={"airliner-narrow":1,"airliner-wide":1,"airliner-supersonic":1,"regional-jet":.6,"regional-turboprop":.6,"business-jet":.4,"turboprop-light":.2,"light-piston":.1,ultralight:.05,"helicopter-light":.1,"helicopter-medium":.2,"helicopter-heavy":.2};static lampsOn(t,e){if(C.NONE.has(t))return{navigation:!1,beacon:!1,strobes:!1};if(C.ALWAYS.has(t))return{navigation:!0,beacon:!0,strobes:!0};const a=e<C.DUSK_SUN_ELEVATION_DEG;return t==="unmanned"?{navigation:!1,beacon:!1,strobes:a}:{navigation:a,beacon:a,strobes:a}}static lights(t,e){const a=C.lampsOn(t.kind,e),n=t.kind.startsWith("helicopter"),s=It.find(h=>h.id===(n?"helicopter":"airliner")).create(),[i,o]=n?[5,7]:[17,18],r=t.spanM/2/i,l=t.lengthM/2/o,[c,u,d]=C.BRIGHTNESS[t.kind]??[1,1,1];return s.filter(h=>h.id.startsWith("nav")?a.navigation:h.id.startsWith("strobe")?a.strobes:h.id.startsWith("beacon")?a.beacon:!0).filter(h=>!(h.id.startsWith("beacon")&&!a.beacon)).map(h=>{const p=h.id.startsWith("nav")?c:h.id.startsWith("strobe")?u:d;return{...h,offsetM:{x:h.offsetM.x*r,y:h.offsetM.y,z:h.offsetM.z*l},intensity:(h.intensity??1)*p}}).filter(h=>(h.intensity??1)>0)}static landingLights(t,e,a){const n=C.LANDING_BRIGHTNESS[t.kind]??0;if(n===0||!C.lampsOn(t.kind,e).navigation)return[];const s=c=>c<C.LANDING_LIGHTS_BELOW_FT;if(!a.some(c=>s(c.altitudeFt)))return[];const i=C.LANDING_INTENSITY*n,o=a.flatMap((c,u)=>u>0&&s(c.altitudeFt)!==s(a[u-1].altitudeFt)?[{t:c.t,intensity:s(c.altitudeFt)?i:0}]:[]),r=t.spanM/34,l=t.lengthM/36;return[-1,1].map(c=>({id:c<0?"landing-left":"landing-right",offsetM:{x:c*5*r,y:-1,z:3*l},color:C.LANDING_COLOR,intensity:s(a[0].altitudeFt)?i:0,pattern:{kind:"steady"},beamDeg:C.LANDING_BEAM_DEG,keyframes:o}))}static bodyColor(t){return t.kind==="military-jet"?"#8a8e94":t.kind.startsWith("helicopter")?"#c8ccd1":t.kind==="unmanned"?"#2c2e33":"#dde0e4"}}class J{static FAMILIES={"amvlab-a320":["A318","A319","A320","A321","A19N","A20N","A21N"],"amvlab-b737":["B732","B733","B734","B735","B736","B737","B738","B739","B37M","B38M","B39M","B3XM"],"amvlab-a350":["A359","A35K"],"amvlab-a380":["A388"],"amvlab-b787":["B788","B789","B78X"]};static BY_TYPE=new Map(Object.entries(J.FAMILIES).flatMap(([t,e])=>e.map(a=>[a,t])));static idOf(t){return t?J.BY_TYPE.get(t.toUpperCase()):void 0}}class R{static ID_PREFIX=Z.ID_PREFIX;static MAX_OBJECTS=40;static FT_TO_M=.3048;static DEG=Math.PI/180;static from(t,e,a,n=R.MAX_OBJECTS,s={}){return new Yt(t,e,a,n,s).build()}static idOf(t,e){return Z.idOf(t,e)}static keyOf(t){return Z.keyOf(t)}static HEIGHT_OVER_LENGTH=.29;static sizeOf(t){return{widthM:t.spanM,lengthM:t.lengthM,heightM:t.lengthM*R.HEIGHT_OVER_LENGTH}}static offsetOf(t,e){const a=j.seenFrom(t,{lat:e.lat,lng:e.lng,heightM:e.altitudeFt*R.FT_TO_M}),n=a.distanceKm*1e3,s=n*Math.cos(a.altitudeDeg*R.DEG);return{eastM:s*Math.sin(a.azimuthDeg*R.DEG),northM:s*Math.cos(a.azimuthDeg*R.DEG),upM:n*Math.sin(a.altitudeDeg*R.DEG),altitudeDeg:a.altitudeDeg,distanceKm:a.distanceKm}}static segments(t){const e=[];let a=[];for(const n of t.points){const s=a[a.length-1];s&&n.t-s.t>N.MAX_GAP_S*1e3&&(e.push(a),a=[]),a.push(n)}return e.push(a),e.filter(n=>n.length>=2)}static bearingDeg(t,e){return(Math.atan2(e.eastM-t.eastM,e.northM-t.northM)/R.DEG+360)%360}}class Yt{constructor(t,e,a,n,s){this.tracks=t,this.observer=e,this.startMs=a,this.maxObjects=n,this.options=s}build(){const t=[];for(const a of this.tracks){const n=R.keyOf(a),s=this.options.models?.get(n)??U.of(void 0);R.segments(a).forEach((i,o)=>{const r=i.map(h=>({point:h,at:R.offsetOf(this.observer,h)}));if(!r.some(h=>h.at.altitudeDeg>=0))return;const l=r.map((h,p)=>({t:h.point.t-this.startMs,eastM:h.at.eastM,northM:h.at.northM,altitudeM:h.at.upM,headingDeg:h.point.trackDeg??(p+1<r.length?R.bearingDeg(h.at,r[p+1].at):R.bearingDeg(r[p-1].at,h.at))})),c=R.idOf(a,o),u=r[Math.floor(r.length/2)].point,d=this.options.sunElevationAt?.(u)??90;t.push({object:{id:c,kind:"aircraft",eastM:l[0].eastM,northM:l[0].northM,headingDeg:l[0].headingDeg,sizeM:R.sizeOf(s),model:J.idOf(s.code)?{id:J.idOf(s.code)}:void 0,color:C.bodyColor(s),lights:[...C.lights(s,d),...C.landingLights(s,d,i.map(h=>({t:h.t-this.startMs,altitudeFt:h.altitudeFt})))],track:l},presence:{fromMs:l[0].t,untilMs:l[l.length-1].t},flight:{icao:a.icao,nonIcao:a.nonIcao,points:i},closestKm:Math.min(...r.map(h=>h.at.distanceKm))})})}t.sort((a,n)=>a.closestKm-n.closestKm);const e=t.slice(0,this.maxObjects);return{objects:e.map(a=>a.object),presence:new Map(e.map(a=>[a.object.id,a.presence])),flights:new Map(e.map(a=>[a.object.id,a.flight])),total:t.length,shown:e.length}}}const qt=[[20,0],[120,0],[130,1.5],[140,4],[150,7.5],[160,7.5]],Jt=[[20,1.5],[40,1],[60,1],[80,0],[120,0],[130,1],[140,1],[150,-3],[160,-6.5],[170,-12]],bt=.16,xt=1,$t=[[0,-2],[10,-1],[20,0],[40,0],[50,-2],[60,-4.5],[70,-7.5],[80,-11],[90,-15],[100,-19.5],[110,-25]],Zt=[[60,-15.8],[70,-11.5],[80,-8],[90,-5],[100,-2.7],[110,-1.2],[120,-.3],[130,0],[140,-2],[150,-6],[160,-10],[170,-15],[180,-20]],Qt=1.5,Et=-40,te=1.5,ee={takeoff:{jetMps:300,flightMps:80,jetShare:[1,1,.9,.6,.3,.1,0,0]},overflight:{jetMps:280,flightMps:130,jetShare:[1,1,.9,.6,.3,.1,0,0]},approach:{jetMps:180,flightMps:70,jetShare:[.6,.5,.4,.2,.1,0,0,0]}};class w{static bandsDb(t,e,a=340){const n=ee[e],s=w.fan(t)-w.fan(90),i=.62*Math.max(0,n.jetMps-n.flightMps)/a,o=-30*Math.log10(1+i/(1+i**5)**.2*Math.cos(t*Math.PI/180));return g.OCTAVES.map((r,l)=>{const c=o+w.jetRemainder(t,r*te/n.jetMps),u=n.jetShare[l];return 10*Math.log10(u*10**(c/10)+(1-u)*10**(s/10))})}static loudestDb(t){const e=w.loudest.get(t);if(e)return e;const a=g.OCTAVES.map(()=>-1/0);for(let n=0;n<=180;n+=5)w.bandsDb(n,t).forEach((s,i)=>a[i]=Math.max(a[i],s));return w.loudest.set(t,a),a}static loudest=new Map;static angleDeg(t,e){const a=t.reduce((s,i,o)=>s+i*e[o],0),n=Math.hypot(...t)*Math.hypot(...e);return n===0?90:Math.acos(Math.min(1,Math.max(-1,a/n)))*180/Math.PI}static fan(t){const e=w.read($t,t,!0),a=w.read(Zt,t,!0)+Qt;return 10*Math.log10(10**(e/10)+10**(a/10))}static jetRemainder(t,e){const a=Math.min(1,Math.max(0,Math.log(e/bt)/Math.log(xt/bt)));return(1-a)*w.read(qt,t)+a*w.read(Jt,t)}static read(t,e,a=!1){const[n,s]=[t[0],t[1]],[i,o]=[t[t.length-2],t[t.length-1]];if(e<=n[0])return a?Math.max(Et,n[1]+(s[1]-n[1])/(s[0]-n[0])*(e-n[0])):n[1];if(e>=o[0])return a?Math.max(Et,o[1]+(o[1]-i[1])/(o[0]-i[0])*(e-o[0])):o[1];for(let r=1;r<t.length;r++){const[l,c]=[t[r-1],t[r]];if(e<=c[0])return l[1]+(c[1]-l[1])*(e-l[0])/(c[0]-l[0])}return o[1]}}class A{static GRASS={flowResistivityKPa:200,earHeightM:1.6};static COHERENCE=.4;static JITTER_S=1e-4;static ECHO_UNDER_S=5e-4;static ECHO_FROM_S=.0015;static LOW_HZ=125;static HIGH_HZ=2e3;static AIR_DENSITY=1.2;static reflection(t,e,a=A.GRASS){const[n,s]=A.impedance(t,a);return A.reflected(n,s,Math.sin(Math.max(0,e)*Math.PI/180))}static impedance(t,e=A.GRASS){const a=A.AIR_DENSITY*t/(e.flowResistivityKPa*1e3);return[1+.0571*a**-.754,-.087*a**-.732]}static reflected(t,e,a){const[n,s,i,o]=[t*a-1,e*a,t*a+1,e*a],r=i*i+o*o;return{re:(n*i+s*o)/r,im:(s*i-n*o)/r}}static delayS(t,e=A.GRASS,a=340){return 2*e.earHeightM*Math.sin(Math.max(0,t)*Math.PI/180)/a}static excessDb(t,e=A.GRASS,a=340){const n=`${e.flowResistivityKPa}|${e.earHeightM}|${a}`;let s=A.overheads.get(n);return s||A.overheads.set(n,s=A.bandsDb(90,e,a)),A.bandsDb(t,e,a).map((i,o)=>i-s[o])}static echo(t,e=A.GRASS,a=340){const n=A.delayS(t,e,a);if(n<=A.ECHO_UNDER_S)return;const s=Math.min(1,(n-A.ECHO_UNDER_S)/(A.ECHO_FROM_S-A.ECHO_UNDER_S)),i=s*s*(3-2*s),o=r=>{const l=A.reflection(r,t,e);return i*A.COHERENCE*Math.hypot(l.re,l.im)};return{delayS:n,lowGain:o(A.LOW_HZ),highGain:o(A.HIGH_HZ),jitterS:A.JITTER_S}}static overheads=new Map;static thirds=g.OCTAVES.map(t=>[-1,0,1].map(e=>{const a=t*2**(e/3);return{middle:a,from:a*2**(-1/6),to:a*2**(1/6)}}));static impedances=new Map;static bandsDb(t,e,a){const n=A.delayS(t,e,a),s=A.COHERENCE,i=Math.sin(Math.max(0,t)*Math.PI/180);let o=A.impedances.get(e.flowResistivityKPa);return o||A.impedances.set(e.flowResistivityKPa,o=A.thirds.map(r=>r.map(l=>A.impedance(l.middle,e)))),A.thirds.map((r,l)=>{let c=0;return r.forEach((u,d)=>{const h=A.reflected(o[l][d][0],o[l][d][1],i),p=2*Math.PI*n*(u.to-u.from),[m,E]=p<1e-9?[1,0]:[(Math.sin(2*Math.PI*u.to*n)-Math.sin(2*Math.PI*u.from*n))/p,(Math.cos(2*Math.PI*u.from*n)-Math.cos(2*Math.PI*u.to*n))/p];c+=1+h.re*h.re+h.im*h.im+2*s*(h.re*m+h.im*E)}),10*Math.log10(c/r.length)})}}const q={takeoff:{shapeDb:[10,3,-3,-2,-2,-2,5,4],levelDb:0},approach:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:-8}},ae={takeoff:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:0},approach:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:-8}},Ot=[{id:"turbofan-narrow-body",name:"Turbofan airliner, narrow-body",kinds:["airliner-narrow"],totalDbA:148,shapeDb:[-32,-17,-9,-6,-5,-7,-12,-22],character:{toneHz:1800,toneShare:.3,humHz:90,humShare:.7},regimes:q},{id:"turbojet-supersonic",name:"Supersonic turbojet airliner",kinds:["airliner-supersonic"],totalDbA:169.5,shapeDb:[-22,-13,-9,-6,-6,-9,-15,-25],character:{humHz:100,humShare:.7},regimes:ae},{id:"turbofan-wide-body",name:"Turbofan airliner, wide-body",kinds:["airliner-wide"],totalDbA:151,shapeDb:[-28,-14,-7,-4,-3,-6,-12,-22],character:{toneHz:1200,toneShare:.3,humHz:70,humShare:.7},regimes:q},{id:"regional-jet",name:"Regional jet",kinds:["regional-jet"],totalDbA:144,shapeDb:[-32,-17,-9,-5,-4,-6,-11,-21],character:{toneHz:1900,toneShare:.3,humHz:95,humShare:.7},regimes:q},{id:"business-jet",name:"Business jet",kinds:["business-jet"],totalDbA:141,shapeDb:[-30,-15,-8,-4,-3,-4,-9,-19],character:{toneHz:2500,toneShare:.25,humHz:110,humShare:.7},regimes:q},{id:"turboprop",name:"Turboprop",kinds:["regional-turboprop","turboprop-light"],totalDbA:138,shapeDb:[-14,-9,-8,-6,-8,-13,-20,-28],character:{toneHz:80,toneShare:.5}},{id:"light-piston",name:"Light piston aircraft",kinds:["light-piston"],totalDbA:130,shapeDb:[-20,-10,-3,-6,-10,-20,-27,-42],character:{toneHz:80,toneShare:.4,modulationHz:80,modulationDepth:.4}},{id:"piston-heavy",name:"Heavy piston aircraft",kinds:["piston-heavy"],totalDbA:140,shapeDb:[-31,-12,-11,-9,-7,-6,-7,-11],character:{toneHz:84,toneShare:.4,modulationHz:84,modulationDepth:.36}},{id:"ultralight",name:"Ultralight",kinds:["ultralight"],totalDbA:124,shapeDb:[-16,-8,-5,-4,-9,-15,-23,-31],character:{toneHz:140,toneShare:.4}},{id:"helicopter-light",name:"Light helicopter",kinds:["helicopter-light"],totalDbA:134,shapeDb:[-15,-8,-4,-3,-6,-10,-16,-24],character:{modulationHz:20,modulationDepth:.5}},{id:"helicopter-medium",name:"Medium helicopter",kinds:["helicopter-medium"],totalDbA:138,shapeDb:[-14,-7,-4,-3,-6,-10,-16,-24],character:{modulationHz:22,modulationDepth:.5}},{id:"helicopter-heavy",name:"Heavy helicopter",kinds:["helicopter-heavy"],totalDbA:144,shapeDb:[-12,-6,-4,-4,-7,-11,-17,-25],character:{modulationHz:17,modulationDepth:.5}},{id:"military-jet",name:"Military jet",kinds:["military-jet"],totalDbA:152,shapeDb:[-26,-12,-6,-3,-2,-3,-7,-15]},{id:"glider",name:"Glider",kinds:["glider"],totalDbA:85,shapeDb:[-30,-22,-15,-10,-8,-8,-14,-22]},{id:"balloon",name:"Hot-air balloon",kinds:["balloon"],totalDbA:100,shapeDb:[-25,-15,-9,-5,-3,-6,-12,-20]},{id:"unmanned",name:"Unmanned aircraft",kinds:["unmanned"],totalDbA:88,shapeDb:[-40,-30,-20,-12,-6,-3,-3,-8],character:{toneHz:450,toneShare:1}}],ft=(b,t)=>b.map(e=>e+t-g.sumDb(b));function ne(b,t){if(!b)return;const e=t.toneRatio??1,a=t.toneGain??1;return{...b,...b.toneHz!==void 0?{toneHz:b.toneHz*e,toneShare:Math.min(1,(b.toneShare??0)*a)}:{},...b.humHz!==void 0?{humHz:b.humHz*e,humShare:Math.min(1,(b.humShare??0)*a)}:{}}}const St=Ot.map(b=>{const t=b.regimes===q?"turbofan":void 0,e={id:b.id,name:b.name,soundPowerA:ft(b.shapeDb,b.totalDbA),character:b.character,directivity:t};if(!b.regimes)return e;const a={overflight:e};for(const[n,s]of Object.entries(b.regimes))a[n]={id:`${b.id}-${n}`,name:`${b.name}, ${n}`,soundPowerA:ft(b.shapeDb.map((i,o)=>i+s.shapeDb[o]),b.totalDbA+s.levelDb),character:ne(b.character,s),directivity:t};return{...e,regimes:a}});class M{static DEFAULT_AMBIENT_DB_A=35;static DETECTION_MARGIN_DB=3;static AMBIENT_SHAPE_DB=Dt.OUTDOOR_SHAPE_DB;static HEARING_FLOOR_DB_A=0;static ITERATIONS=30;static CONVERGED_MS=.5;static VELOCITY_STEP_MS=500;static CLIMB_MPS=2.5;static DESCENT_MPS=1.5;static LOW_M=3e3;static CLIMB_SPAN_MS=3e4;static noiseOfKind(t){const e=Ot.find(a=>a.kinds.includes(t));return St.find(a=>a.id===(e?.id??"turbofan-narrow-body"))}static bandsAt(t,e,a=g.STANDARD){const n=20*Math.log10(Math.max(e*1e3,1))+11;return g.OCTAVES.map((s,i)=>t.soundPowerA[i]-n-g.absorptionDbPerKm(s,a)*e)}static couldBeHeard(t,e,a=M.DEFAULT_AMBIENT_DB_A,n=g.STANDARD,s){const i=M.ambientBands(a,s);return Object.entries(t.regimes??{overflight:t}).some(([r,l])=>M.bandsAt(l,e,n).map((c,u)=>c+(l.directivity==="turbofan"?w.loudestDb(r)[u]:0)).some((c,u)=>c>=Math.max(i[u]+M.DETECTION_MARGIN_DB,M.HEARING_FLOOR_DB_A)))}static ambientBands(t,e=M.AMBIENT_SHAPE_DB){const a=g.sumDb(e);return e.map(n=>t+n-a)}static heardAt(t,e,a,n={}){const s=n.air??g.STANDARD,i=g.speedOfSound(s.temperatureC),o=t.points[t.points.length-1]?.t;if(o===void 0)return;let r=Math.min(a,o),l=N.positionAt(t,r);if(!l)return;let c=j.seenFrom(e,l.geo);for(let _=0;_<M.ITERATIONS;_++){const k=a-c.distanceKm*1e3*1e3/i,$=Math.abs(k-r);if(r=k,l=N.positionAt(t,r),!l)return;if(c=j.seenFrom(e,l.geo),$<M.CONVERGED_MS)break}const u=N.positionAt(t,a),d=u?j.seenFrom(e,u.geo):c,h=M.regimeAt(t,r,e),p=M.inRegime(n.noise??St[0],h),m=n.ambientDbA??M.DEFAULT_AMBIENT_DB_A,E=M.ambientBands(m,n.ambientShapeDb),O=M.emissionAngle(t,e,r),B=p.directivity==="turbofan"?w.bandsDb(O,h,i):void 0,v=n.ground===null?g.OCTAVES.map(()=>0):A.excessDb(c.altitudeDeg,n.ground,i),S=M.bandsAt(p,c.distanceKm,s).map((_,k)=>_+(B?.[k]??0)+v[k]),F=S.map((_,k)=>_>=Math.max(E[k]+M.DETECTION_MARGIN_DB,M.HEARING_FLOOR_DB_A)),x=S.indexOf(Math.max(...S)),L=F.lastIndexOf(!0);return{track:t,audible:F.some(Boolean),levelDbA:g.sumDb(S),bandsDbA:S,ambientDbA:m,delayS:(a-r)/1e3,emittedAtMs:r,sound:c,seen:d,lagDeg:M.angleBetween(c,d),dopplerRatio:M.doppler(t,e,r,i),dominantHz:g.OCTAVES[x],cutoffHz:L<0?void 0:g.OCTAVES[L],regime:h,noise:p,emissionAngleDeg:O}}static emissionAngle(t,e,a){const n=M.VELOCITY_STEP_MS,s=N.positionAt(t,a-n),i=N.positionAt(t,a+n),o=N.positionAt(t,a);if(!s||!i||!o)return 90;const r=d=>{const h=j.seenFrom(e,d),p=h.altitudeDeg*Math.PI/180,m=h.azimuthDeg*Math.PI/180,E=h.distanceKm*1e3;return[E*Math.cos(p)*Math.sin(m),E*Math.cos(p)*Math.cos(m),E*Math.sin(p)]},[l,c,u]=[r(s.geo),r(i.geo),r(o.geo)];return w.angleDeg(c.map((d,h)=>d-l[h]),u.map(d=>-d))}static regimeAt(t,e,a){const n=M.CLIMB_SPAN_MS,s=N.positionAt(t,e-n)??N.positionAt(t,e),i=N.positionAt(t,e+n)??N.positionAt(t,e),o=N.positionAt(t,e);if(!s||!i||!o)return"overflight";const r=(Math.min(e+n,t.points[t.points.length-1].t)-Math.max(e-n,t.points[0].t))/1e3;if(r<=0)return"overflight";const l=(i.altitudeFt-s.altitudeFt)*.3048/r;return o.altitudeFt*.3048-a.heightM>M.LOW_M?"overflight":l>M.CLIMB_MPS?"takeoff":l<-1.5?"approach":"overflight"}static inRegime(t,e){return t.regimes?.[e]??t}static profile(t,e,a,n,s=2e3,i={}){const o=[];let r,l,c=a;for(let u=a;u<=n;u+=s){const d=M.heardAt(t,e,u,i);d&&(!l||d.levelDbA>l.levelDbA)&&(l=d,c=u),d?.audible?r?r.untilMs=u:o.push(r={fromMs:u,untilMs:u}):r=void 0}return{track:t,audible:o,peakDbA:l?.levelDbA??-1/0,peakAtMs:c,peakDelayS:l?.delayS??0}}static angleBetween(t,e){const a=c=>{const u=c.altitudeDeg*Math.PI/180,d=c.azimuthDeg*Math.PI/180;return[Math.cos(u)*Math.sin(d),Math.cos(u)*Math.cos(d),Math.sin(u)]},[n,s,i]=a(t),[o,r,l]=a(e);return Math.acos(Math.min(1,Math.max(-1,n*o+s*r+i*l)))*180/Math.PI}static doppler(t,e,a,n){const s=M.VELOCITY_STEP_MS,i=N.positionAt(t,a-s),o=N.positionAt(t,a+s);if(!i||!o)return 1;const r=j.seenFrom(e,i.geo).distanceKm*1e3,l=j.seenFrom(e,o.geo).distanceKm*1e3;return 1/(1-(r-l)/(2*s/1e3)/n)}}class pe{static at(t,e,a,n,s={}){const i=N.seenFrom(t,a,n);if(!i)return;const o=U.of(e),r=M.heardAt(t,a,n,{noise:M.noiseOfKind(o.kind),...s});return{hex:`${t.nonIcao?"~":""}${t.icao.toString(16).padStart(6,"0")}`,registration:e?.registration,typeCode:o.code??e?.type,name:o.basis==="nothing"?void 0:o.name,kind:o.kind,basis:o.basis,military:e?.military===!0,restricted:e?.restricted===!0,altitudeFt:i.altitudeFt,groundSpeedKt:i.groundSpeedKt,trackDeg:i.trackDeg,sky:i.sky,angularRateDegPerS:i.angularRateDegPerS,hearing:r&&{audible:r.audible,levelDbA:r.levelDbA,ambientDbA:r.ambientDbA,delayS:r.delayS,lagDeg:r.lagDeg,dopplerRatio:r.dopplerRatio,cutoffHz:r.cutoffHz,dominantHz:r.dominantHz}}}}class T{static REFERENCE_AMPLITUDE=.02;static MASKING_RANGE_DB=6;static KNEE_DB=20;static COMPRESSION_RATIO=1;static EXPANSION_RATIO=1.8;static HEADROOM_DB=Dt.HEADROOM_DB;static DEFAULT_MAX_VOICES=4;static candidates(t,e,a,n,s={}){const i=new Set;for(const[o,r]of t){const l=M.noiseOfKind(U.of(e.get(a(r))).kind);let c=1/0;for(const u of r.points)c=Math.min(c,j.seenFrom(n,{lat:u.lat,lng:u.lng,heightM:u.altitudeFt*.3048}).distanceKm);M.couldBeHeard(l,c,s.ambientDbA,s.air,s.ambientShapeDb)&&i.add(o)}return i}static voices(t,e,a,n,s,i,o={}){const r=[];for(const l of t){const c=e.get(l);if(!c||o.only?.(l)===!1)continue;const u=o.kindOf?.(l)??U.of(a.get(n(c))).kind,d=o.noiseOf?.(l)??M.noiseOfKind(u),h=M.heardAt(c,s,i,{...o,noise:d});if(!h?.audible)continue;const p=o.throughDb,m=p?h.bandsDbA.map((E,O)=>E-(p[O]??0)):h.bandsDbA;p&&!T.noticed(m,h.ambientDbA,o.ambientShapeDb)||r.push({id:l,kind:u,bandAmplitudes:T.bandAmplitudes(m,h.ambientDbA,o.referenceAmplitude,{ambientShapeDb:o.ambientShapeDb,expandUnderKnee:o.expandUnderKnee}),levelDbA:p?g.sumDb(m):h.levelDbA,distanceKm:h.sound.distanceKm,dopplerRatio:h.dopplerRatio,azimuthDeg:h.sound.azimuthDeg,elevationDeg:h.sound.altitudeDeg,character:h.noise.character,groundEcho:o.ground===null?void 0:A.echo(h.sound.altitudeDeg,o.ground,g.speedOfSound((o.air??g.STANDARD).temperatureC))})}return r.sort((l,c)=>c.levelDbA-l.levelDbA).slice(0,o.maxVoices??T.DEFAULT_MAX_VOICES)}static noticed(t,e,a){const n=M.ambientBands(e,a);return t.some((s,i)=>s>=n[i]+M.DETECTION_MARGIN_DB)}static bandAmplitudes(t,e,a=T.REFERENCE_AMPLITUDE,n={}){const s=M.ambientBands(e,n.ambientShapeDb),i=n.expandUnderKnee===!1?1:T.EXPANSION_RATIO,o=M.DETECTION_MARGIN_DB,r=g.sumDb(t),l=r-e,c=l>=T.KNEE_DB?T.KNEE_DB+(l-T.KNEE_DB)/T.COMPRESSION_RATIO:T.KNEE_DB-(T.KNEE_DB-l)*i,u=a*10**((c-T.HEADROOM_DB)/20);return t.map((d,h)=>{const p=Math.min(1,Math.max(0,(d-s[h]-o+T.MASKING_RANGE_DB)/(2*T.MASKING_RANGE_DB)));return p*p*(3-2*p)*u*10**((d-r)/20)})}static BANDS_HZ=g.OCTAVES}class Q{static RUMBLE_BELOW_HZ=500;static DULL_BELOW_HZ=2e3;static PITCH_NOTICED=.03;static text(t,e,a,n){const s=(d,h=0)=>d.toLocaleString(n,{maximumFractionDigits:h}),i=(d,h)=>d.replace(/\{(\w+)\}/g,(p,m)=>h[m]??`{${m}}`),o=[],r=[t.registration,t.name].filter(Boolean).join(" · ");o.push(r||i(e.unnamed,{hex:t.hex}));const l=[i(e.altitude,{value:s(Math.round(t.altitudeFt/100)*100)}),t.groundSpeedKt===void 0?void 0:i(e.speed,{value:s(Math.round(t.groundSpeedKt))}),t.trackDeg===void 0?void 0:i(e.heading,{value:s(Math.round(t.trackDeg))})].filter(Boolean);o.push(l.join(" · ")),o.push(i(e.position,{distance:s(t.sky.distanceKm,t.sky.distanceKm<10?1:0),elevation:s(Math.round(t.sky.altitudeDeg)),bearing:a(t.sky.azimuthDeg)}));const c=t.hearing;if(!c)o.push(e.soundUnknown);else if(!c.audible)o.push(i(e.inaudible,{level:s(Math.round(c.levelDbA)),ambient:s(Math.round(c.ambientDbA))}));else{const d=c.cutoffHz??0,h=d<=Q.RUMBLE_BELOW_HZ?e.rumble:d<=Q.DULL_BELOW_HZ?e.muffled:e.broad,p=c.dopplerRatio-1,m=Math.abs(p)<Q.PITCH_NOTICED?"":i(p>0?e.pitchHigher:e.pitchLower,{percent:s(Math.round(Math.abs(p)*100))});o.push(i(e.heard,{level:s(Math.round(c.levelDbA)),delay:s(Math.round(c.delayS)),lag:s(Math.round(c.lagDeg)),character:i(h,{cutoff:s(d)}),pitch:m}))}t.contrail&&o.push(i(t.contrail.persistent?e.contrailPersistent:e.contrailShort,{rhi:s(Math.round(t.contrail.iceRelativeHumidity*100))}));const u=[t.military?e.military:void 0,t.restricted?e.restricted:void 0].filter(Boolean);return u.length>0&&o.push(u.join(" · ")),o.push(e.candidate),o.join(`
|
|
1
|
+
import{aT as et,aU as g,aV as It,aW as Z,p as j,aX as N,aY as Dt,aZ as st,a_ as it}from"./ShareDialogElement-ClhewPap.js";import{C as ot}from"./ContrailGrowth-DwHS8If9.js";import{U as Ae}from"./upperAirSources-BGuLpdwu.js";import{p as V,r as Tt}from"./Decor-Dn-cvniW.js";import{l as at}from"./SaidPosition-CWiVNaNW.js";import"./rr0-ufoathome.mjs";import"./Sighting-CBpJpdm9.js";import"./VisualAids-DI-hEL46.js";import"./RecordingIssue-BlWT8Xsu.js";import"./Obstacles-v9SkfBD7.js";const Rt=.25,rt=.4,ct=6,X=12,Bt=3,lt=.2,vt=.2,ht=24,Nt=3,Ct=24,ut=1,_t=.7,Ht=1.5,wt=.8,yt=1.3,dt=.02,Pt=700,kt=-30,pt=.9,mt=5,Lt=25,Ft=.5,jt=.12,Mt=[.13,.31],Gt=.16,Ut=1.6,Kt=2,zt=3.6,At=1.1,Wt=.3,Vt=1e3,gt=.7,Xt=.7;class Y{context;constructor(t){this.context=t}noiseBuffer;roughBuffers=new Map;voices=new Map;bus;reverb;reverbOut;level=1;master;paused=!0;requested=[];headingDeg=0;resume(){if(!this.context){if(typeof AudioContext>"u")return;try{this.context=new AudioContext}catch(t){console.warn("AircraftAudio: Web Audio unavailable, aircraft stay silent:",t);return}}et.isLive(this.context)&&et.unlock(this.context),this.apply()}setLevel(t){this.level=t,this.master&&(this.master.gain.value=t)}setPaused(t){t!==this.paused&&(this.paused=t,this.apply())}setVoices(t,e=0){this.requested=t,this.headingDeg=e,this.apply()}dispose(){for(const t of[...this.voices.keys()])this.release(t);et.isLive(this.context)&&this.context.close(),this.context=void 0,this.master=void 0,this.bus=void 0}apply(){const t=this.context;if(!t)return;const e=this.paused?[]:this.requested,a=new Set(e.map(n=>n.id));for(const n of[...this.voices.keys()])a.has(n)||this.release(n);for(const n of e){const s=this.voices.get(n.id)??this.build(t,n);this.retarget(t,s,n)}}build(t,e){const a=t.createGain();a.gain.value=0;let n;const s=this.busOf(t);typeof t.createStereoPanner=="function"?(n=t.createStereoPanner(),a.connect(n).connect(s)):a.connect(s);const i=t.createGain(),o=e.character?.modulationDepth??0;i.gain.value=1-o/2;const r=t.createOscillator();r.type="sine";const l=t.createGain();l.gain.value=o/2,r.connect(l).connect(i.gain),i.connect(a);const c=t.createBufferSource();c.buffer=this.noise(t),c.loop=!0,c.loopStart=Math.random()*ct*.5;const u=[],d=[],h=[];for(const D of g.OCTAVES){const I=t.createBiquadFilter();I.type="bandpass",I.frequency.value=D,I.Q.value=ut;const H=t.createBiquadFilter();H.type="bandpass",H.frequency.value=D,H.Q.value=ut;const P=t.createGain();P.gain.value=0,c.connect(I).connect(H).connect(P).connect(i),u.push(I),d.push(H),h.push(P)}const p=[];for(const[D,I]of[[e.character?.toneHz,e.character?.toneShare],[e.character?.humHz,e.character?.humShare]])if(D!==void 0)for(let H=1;H<=Nt;H++){const P=t.createOscillator();P.type="sine",P.frequency.value=D*H;const tt=t.createGain();tt.gain.value=0,P.connect(tt).connect(a),p.push({oscillator:P,gain:tt,harmonic:H,baseHz:D,share:I??0})}const m=t.createGain();m.gain.value=0,m.connect(a.gain);const E=Mt.map(D=>{const I=t.createOscillator();return I.type="sine",I.frequency.value=D,I.connect(m),I}),O=t.createGain();O.gain.value=e.character?.roughness??lt;const B=t.createBufferSource();B.buffer=this.roughTable(t,Bt),B.loop=!0,B.loopStart=Math.random()*X*.5,B.connect(O).connect(i.gain);const v=t.createGain();v.gain.value=(e.character?.roughness??lt)*vt;const S=t.createBufferSource();S.buffer=this.roughTable(t,ht),S.loop=!0,S.loopStart=Math.random()*X*.5,S.connect(v).connect(i.gain);let F;const x=this.busOf(t)&&this.reverb;x&&(F=t.createGain(),F.gain.value=0,a.connect(F).connect(x));let L,_;if(!e.inside&&typeof t.createDelay=="function"){const D=t.createDelay(dt);D.delayTime.value=0;const I=t.createBiquadFilter();I.type="highshelf",I.frequency.value=Pt,I.gain.value=0;const H=t.createGain();H.gain.value=0,a.connect(D).connect(I).connect(H).connect(n??s);const P=t.createGain();P.gain.value=0,_=t.createBufferSource(),_.buffer=this.roughTable(t,ht),_.loop=!0,_.loopStart=Math.random()*X*.5,_.connect(P).connect(D.delayTime),L={delay:D,jitter:P,shelf:I,gain:H}}const k=[c,B,S,r,...p.map(D=>D.oscillator),...E,..._?[_]:[]];for(const D of k)D.start();const $={nodes:[a,i,l,O,v,m,...L?[L.delay,L.jitter,L.shelf,L.gain]:[],...p.map(D=>D.gain),...u,...d,...h,...F?[F]:[],...n?[n]:[],...k],sources:k,filters:u,seconds:d,gains:h,tones:p,lfo:r,lfoDepth:l,wander:E,wanderDepth:m,roughDepth:O,crackleDepth:v,beat:i,output:a,panner:n,send:F,echo:L};return this.voices.set(e.id,$),$}retarget(t,e,a){const n=t.currentTime,s=(p,m)=>p.setTargetAtTime(m,n,Rt),i=Math.min(Ht,Math.max(_t,a.dopplerRatio)),o=Math.min(yt,Math.max(wt,Math.sqrt(a.dopplerRatio))),r=t.sampleRate*.45,l=a.bandAmplitudes.map((p,m)=>p*Y.unweighting(g.OCTAVES[m])),c=Math.sqrt(l.reduce((p,m)=>p+m*m,0)),u=Math.min(1,Math.max(0,(a.distanceKm-mt)/(Lt-mt)));g.OCTAVES.forEach((p,m)=>{s(e.filters[m].frequency,Math.min(r,p*o)),s(e.seconds[m].frequency,Math.min(r,p*o)),s(e.gains[m].gain,l[m]*Math.sqrt(Vt/p))});const d=a.character;for(const{oscillator:p,gain:m,harmonic:E,baseHz:O,share:B}of e.tones){const v=O*E;s(p.frequency,v*i);const S=v*i;s(m.gain,S<r?B*Gt*l[Y.bandOf(S)]/E:0)}d?.modulationHz!==void 0&&s(e.lfo.frequency,d.modulationHz*i);const h=c>0?Y.saturated(c)/c:1;if(s(e.output.gain,h*(1-Wt*u)),s(e.wanderDepth.gain,h*jt*u/Mt.length),e.send&&s(e.send.gain,Y.reverbSend(a.distanceKm)),e.echo){const p=a.groundEcho;s(e.echo.gain.gain,p?.lowGain??0),p&&(s(e.echo.delay.delayTime,Math.min(dt,p.delayS)),s(e.echo.jitter.gain,p.jitterS),s(e.echo.shelf.gain,p.lowGain>0?Math.max(kt,20*Math.log10(Math.max(p.highGain,1e-6)/p.lowGain)):0))}if(e.panner){const p=(a.azimuthDeg-this.headingDeg)*Math.PI/180,m=a.inside?0:Math.max(-pt,Math.min(pt,Math.sin(p)))*(1-Ft*u);s(e.panner.pan,m)}}static saturated(t){const e=Xt*gt;if(t<=e)return t;const a=gt-e;return e+a*(1-Math.exp(-(t-e)/a))}static reverbSend(t){return Math.min(Ut,Math.sqrt(Math.max(0,t)/Kt))}static unweighting(t){return 10**(Math.min(Ct,Math.max(0,-g.aWeightingDb(t)))/20)}static bandOf(t){let e=0;return g.OCTAVES.forEach((a,n)=>{Math.abs(Math.log(t/a))<Math.abs(Math.log(t/g.OCTAVES[e]))&&(e=n)}),e}roughTable(t,e){const a=this.roughBuffers.get(e);if(a)return a;const n=Math.floor(t.sampleRate*X),s=t.createBuffer(1,n,t.sampleRate),i=s.getChannelData(0),o=Array.from({length:X*e},()=>(Math.random()*2-1)**3),r=t.sampleRate/e;for(let l=0;l<i.length;l++){const c=l/r,u=Math.floor(c),d=c-u,h=d*d*(3-2*d);i[l]=o[u%o.length]*(1-h)+o[(u+1)%o.length]*h}return this.roughBuffers.set(e,s),s}roomImpulse(t){const e=Math.floor(t.sampleRate*zt),a=t.createBuffer(2,e,t.sampleRate);for(let n=0;n<2;n++){const s=a.getChannelData(n);let i=0;for(let o=0;o<e;o++){const r=o/t.sampleRate,l=.6*Math.exp(-r/(At*2))+.04;i+=l*(Math.random()*2-1-i),s[o]=i*Math.exp(-r/At)}}return a}busOf(t){if(this.bus)return this.bus;const e=t.createGain();if(e.gain.value=this.level,e.connect(t.destination),this.master=e,typeof t.createConvolver=="function"){const a=t.createConvolver();a.buffer=this.roomImpulse(t);const n=t.createGain();n.gain.value=.9,a.connect(n),this.reverb=a,this.reverbOut=n}if(typeof t.createDynamicsCompressor=="function"){const a=t.createDynamicsCompressor();a.threshold.value=-6,a.knee.value=3,a.ratio.value=4,a.attack.value=.005,a.release.value=.25,a.connect(e),this.bus=a}else this.bus=e;return this.reverbOut?.connect(this.bus),this.bus}release(t){const e=this.voices.get(t);if(!e)return;this.voices.delete(t);const a=this.context;a&&(e.output.gain.setTargetAtTime(0,a.currentTime,rt/3),setTimeout(()=>{for(const n of e.sources)try{n.stop()}catch{}for(const n of e.nodes)n.disconnect()},rt*1e3*3))}noise(t){if(this.noiseBuffer)return this.noiseBuffer;const e=t.createBuffer(1,t.sampleRate*ct,t.sampleRate),a=e.getChannelData(0);for(let n=0;n<a.length;n++)a[n]=Math.random()*2-1;return this.noiseBuffer=e,e}}class U{static TYPES={A318:["Airbus A318","airliner-narrow",34.1,31.4],A319:["Airbus A319","airliner-narrow",34.1,33.8],A320:["Airbus A320","airliner-narrow",34.1,37.6],A321:["Airbus A321","airliner-narrow",34.1,44.5],A19N:["Airbus A319neo","airliner-narrow",35.8,33.8],A20N:["Airbus A320neo","airliner-narrow",35.8,37.6],A21N:["Airbus A321neo","airliner-narrow",35.8,44.5],B737:["Boeing 737-700","airliner-narrow",34.3,33.6],B738:["Boeing 737-800","airliner-narrow",35.8,39.5],B739:["Boeing 737-900","airliner-narrow",35.8,42.1],B38M:["Boeing 737 MAX 8","airliner-narrow",35.9,39.5],B39M:["Boeing 737 MAX 9","airliner-narrow",35.9,42.2],B752:["Boeing 757-200","airliner-narrow",38,47.3],B753:["Boeing 757-300","airliner-narrow",38,54.4],B762:["Boeing 767-200","airliner-wide",47.6,48.5],B763:["Boeing 767-300","airliner-wide",47.6,54.9],B764:["Boeing 767-400","airliner-wide",51.9,61.4],B772:["Boeing 777-200","airliner-wide",60.9,63.7],B77L:["Boeing 777-200LR","airliner-wide",64.8,63.7],B77W:["Boeing 777-300ER","airliner-wide",64.8,73.9],B788:["Boeing 787-8","airliner-wide",60.1,56.7],B789:["Boeing 787-9","airliner-wide",60.1,62.8],B78X:["Boeing 787-10","airliner-wide",60.1,68.3],B744:["Boeing 747-400","airliner-wide",64.4,70.7],B748:["Boeing 747-8","airliner-wide",68.4,76.3],A306:["Airbus A300-600","airliner-wide",44.8,54.1],A310:["Airbus A310","airliner-wide",43.9,46.7],A332:["Airbus A330-200","airliner-wide",60.3,58.8],A333:["Airbus A330-300","airliner-wide",60.3,63.7],A338:["Airbus A330-800","airliner-wide",64,58.8],A339:["Airbus A330-900","airliner-wide",64,63.7],A343:["Airbus A340-300","airliner-wide",60.3,63.7],A346:["Airbus A340-600","airliner-wide",63.5,75.4],A359:["Airbus A350-900","airliner-wide",64.8,66.8],A35K:["Airbus A350-1000","airliner-wide",64.8,73.8],A388:["Airbus A380-800","airliner-wide",79.8,72.7],CONC:["Concorde","airliner-supersonic",25.6,61.7],DC3:["Douglas DC-3","piston-heavy",29,19.7],DC4:["Douglas DC-4","piston-heavy",35.8,28.6],P51:["North American P-51 Mustang","piston-heavy",11.3,9.8],E170:["Embraer 170","regional-jet",26,29.9],E75L:["Embraer 175","regional-jet",26,31.7],E75S:["Embraer 175","regional-jet",26,31.7],E190:["Embraer 190","regional-jet",28.7,36.2],E195:["Embraer 195","regional-jet",28.7,38.7],E290:["Embraer 190-E2","regional-jet",33.7,36.2],E295:["Embraer 195-E2","regional-jet",33.7,41.5],CRJ2:["Bombardier CRJ200","regional-jet",21.2,26.8],CRJ7:["Bombardier CRJ700","regional-jet",23.2,32.3],CRJ9:["Bombardier CRJ900","regional-jet",24.9,36.2],CRJX:["Bombardier CRJ1000","regional-jet",26.2,39.1],AT72:["ATR 72","regional-turboprop",27.1,27.2],AT76:["ATR 72-600","regional-turboprop",27.1,27.2],AT45:["ATR 42","regional-turboprop",24.6,22.7],DH8D:["Dash 8 Q400","regional-turboprop",28.4,32.8],DH8C:["Dash 8-300","regional-turboprop",27.4,25.7],SF34:["Saab 340","regional-turboprop",21.4,19.7],B190:["Beechcraft 1900","regional-turboprop",17.7,17.6],C25A:["Cessna CitationJet CJ2","business-jet",14.3,14.4],C56X:["Cessna Citation Excel","business-jet",17.2,16],C68A:["Cessna Citation Latitude","business-jet",22,18.9],C550:["Cessna Citation II","business-jet",15.8,14.4],E55P:["Embraer Phenom 300","business-jet",15.9,15.6],E50P:["Embraer Phenom 100","business-jet",12.3,12.8],GLF5:["Gulfstream G550","business-jet",28.5,29.4],FA7X:["Dassault Falcon 7X","business-jet",26.2,23.4],CL60:["Bombardier Challenger 600","business-jet",19.6,20.9],LJ45:["Learjet 45","business-jet",14.6,17.7],H25B:["Hawker 800","business-jet",15.7,15.6],C172:["Cessna 172","light-piston",11,8.3],C152:["Cessna 152","light-piston",10.2,7.3],C182:["Cessna 182","light-piston",10.9,8.8],P28A:["Piper Cherokee","light-piston",10.7,7.2],PA34:["Piper Seneca","light-piston",11.8,8.7],SR20:["Cirrus SR20","light-piston",10.9,7.9],SR22:["Cirrus SR22","light-piston",11.7,7.9],S22T:["Cirrus SR22T","light-piston",11.7,7.9],DA40:["Diamond DA40","light-piston",11.6,8.1],DA42:["Diamond DA42","light-piston",13.4,8.6],BE20:["Beechcraft King Air 200","turboprop-light",16.6,13.3],BE58:["Beechcraft Baron","light-piston",11.5,9.1],C208:["Cessna Caravan","turboprop-light",15.9,11.5],PC12:["Pilatus PC-12","turboprop-light",16.3,14.4],TBM9:["Daher TBM 900","turboprop-light",12.8,10.7],EC35:["Airbus H135","helicopter-light",10.2,12.1],EC45:["Airbus H145","helicopter-medium",11,13.6],AS50:["Airbus H125","helicopter-light",10.7,12.9],EC30:["Airbus H130","helicopter-light",10.7,12.6],B407:["Bell 407","helicopter-light",10.7,12.7],B06:["Bell 206","helicopter-light",10.2,12],B429:["Bell 429","helicopter-medium",10.9,13],B505:["Bell 505","helicopter-light",10.4,11.9],R44:["Robinson R44","helicopter-light",10.1,11.7],R22:["Robinson R22","helicopter-light",7.7,8.8],A109:["Agusta A109","helicopter-medium",11,13],A139:["Leonardo AW139","helicopter-medium",13.8,16.7],S92:["Sikorsky S-92","helicopter-heavy",17.2,20.9],H60:["Sikorsky UH-60 Black Hawk","helicopter-heavy",16.4,19.8],T38:["Northrop T-38 Talon","military-jet",7.7,14.1],HAWK:["BAE Hawk","military-jet",9.4,11.9],GLID:["Glider","glider",17,7],BALL:["Balloon","balloon",15,20],ULAC:["Ultralight","ultralight",9.5,6],C42:["Ikarus C42","ultralight",9.4,6.3],DRON:["Drone","unmanned",1,.6]};static CATEGORIES={A1:["Light aircraft","light-piston",11,8.3],A2:["Small aircraft","business-jet",15,15],A3:["Large aircraft","airliner-narrow",34.1,37.6],A4:["High-vortex large aircraft","airliner-narrow",38,47.3],A5:["Heavy aircraft","airliner-wide",60.3,63.7],A6:["High-performance aircraft","military-jet",8,14],A7:["Rotorcraft","helicopter-medium",10.7,12.7],B1:["Glider","glider",17,7],B2:["Lighter-than-air","balloon",15,20],B4:["Ultralight","ultralight",9.5,6],B6:["Unmanned aircraft","unmanned",1.5,1]};static GENERIC={name:"Airliner",kind:"airliner-narrow",spanM:34.1,lengthM:37.6,basis:"nothing"};static of(t){const e=t?.type?.toUpperCase(),a=e?U.TYPES[e]:void 0;if(a)return{code:e,name:a[0],kind:a[1],spanM:a[2],lengthM:a[3],basis:"type"};const n=t?.category?U.CATEGORIES[t.category]:void 0;return n?{name:n[0],kind:n[1],spanM:n[2],lengthM:n[3],basis:"category"}:{...U.GENERIC}}static isHelicopter(t){return t.kind.startsWith("helicopter")}}class C{static DUSK_SUN_ELEVATION_DEG=-.83;static ALWAYS=new Set(["airliner-narrow","airliner-wide","airliner-supersonic","regional-turboprop","regional-jet","business-jet"]);static NONE=new Set(["glider","balloon"]);static BRIGHTNESS={"light-piston":[.5,.2,.5],"turboprop-light":[.7,.4,.8],ultralight:[.4,.2,.4],unmanned:[0,.05,0],"helicopter-light":[1,1,1],"helicopter-medium":[1,1,1],"helicopter-heavy":[1,1,1],"military-jet":[1,1,1]};static LANDING_LIGHTS_BELOW_FT=1e4;static LANDING_INTENSITY=600;static LANDING_BEAM_DEG=10;static LANDING_COLOR="#fff1dc";static LANDING_BRIGHTNESS={"airliner-narrow":1,"airliner-wide":1,"airliner-supersonic":1,"regional-jet":.6,"regional-turboprop":.6,"business-jet":.4,"turboprop-light":.2,"light-piston":.1,ultralight:.05,"helicopter-light":.1,"helicopter-medium":.2,"helicopter-heavy":.2};static lampsOn(t,e){if(C.NONE.has(t))return{navigation:!1,beacon:!1,strobes:!1};if(C.ALWAYS.has(t))return{navigation:!0,beacon:!0,strobes:!0};const a=e<C.DUSK_SUN_ELEVATION_DEG;return t==="unmanned"?{navigation:!1,beacon:!1,strobes:a}:{navigation:a,beacon:a,strobes:a}}static lights(t,e){const a=C.lampsOn(t.kind,e),n=t.kind.startsWith("helicopter"),s=It.find(h=>h.id===(n?"helicopter":"airliner")).create(),[i,o]=n?[5,7]:[17,18],r=t.spanM/2/i,l=t.lengthM/2/o,[c,u,d]=C.BRIGHTNESS[t.kind]??[1,1,1];return s.filter(h=>h.id.startsWith("nav")?a.navigation:h.id.startsWith("strobe")?a.strobes:h.id.startsWith("beacon")?a.beacon:!0).filter(h=>!(h.id.startsWith("beacon")&&!a.beacon)).map(h=>{const p=h.id.startsWith("nav")?c:h.id.startsWith("strobe")?u:d;return{...h,offsetM:{x:h.offsetM.x*r,y:h.offsetM.y,z:h.offsetM.z*l},intensity:(h.intensity??1)*p}}).filter(h=>(h.intensity??1)>0)}static landingLights(t,e,a){const n=C.LANDING_BRIGHTNESS[t.kind]??0;if(n===0||!C.lampsOn(t.kind,e).navigation)return[];const s=c=>c<C.LANDING_LIGHTS_BELOW_FT;if(!a.some(c=>s(c.altitudeFt)))return[];const i=C.LANDING_INTENSITY*n,o=a.flatMap((c,u)=>u>0&&s(c.altitudeFt)!==s(a[u-1].altitudeFt)?[{t:c.t,intensity:s(c.altitudeFt)?i:0}]:[]),r=t.spanM/34,l=t.lengthM/36;return[-1,1].map(c=>({id:c<0?"landing-left":"landing-right",offsetM:{x:c*5*r,y:-1,z:3*l},color:C.LANDING_COLOR,intensity:s(a[0].altitudeFt)?i:0,pattern:{kind:"steady"},beamDeg:C.LANDING_BEAM_DEG,keyframes:o}))}static bodyColor(t){return t.kind==="military-jet"?"#8a8e94":t.kind.startsWith("helicopter")?"#c8ccd1":t.kind==="unmanned"?"#2c2e33":"#dde0e4"}}class J{static FAMILIES={"amvlab-a320":["A318","A319","A320","A321","A19N","A20N","A21N"],"amvlab-b737":["B732","B733","B734","B735","B736","B737","B738","B739","B37M","B38M","B39M","B3XM"],"amvlab-a350":["A359","A35K"],"amvlab-a380":["A388"],"amvlab-b787":["B788","B789","B78X"]};static BY_TYPE=new Map(Object.entries(J.FAMILIES).flatMap(([t,e])=>e.map(a=>[a,t])));static idOf(t){return t?J.BY_TYPE.get(t.toUpperCase()):void 0}}class R{static ID_PREFIX=Z.ID_PREFIX;static MAX_OBJECTS=40;static FT_TO_M=.3048;static DEG=Math.PI/180;static from(t,e,a,n=R.MAX_OBJECTS,s={}){return new Yt(t,e,a,n,s).build()}static idOf(t,e){return Z.idOf(t,e)}static keyOf(t){return Z.keyOf(t)}static HEIGHT_OVER_LENGTH=.29;static sizeOf(t){return{widthM:t.spanM,lengthM:t.lengthM,heightM:t.lengthM*R.HEIGHT_OVER_LENGTH}}static offsetOf(t,e){const a=j.seenFrom(t,{lat:e.lat,lng:e.lng,heightM:e.altitudeFt*R.FT_TO_M}),n=a.distanceKm*1e3,s=n*Math.cos(a.altitudeDeg*R.DEG);return{eastM:s*Math.sin(a.azimuthDeg*R.DEG),northM:s*Math.cos(a.azimuthDeg*R.DEG),upM:n*Math.sin(a.altitudeDeg*R.DEG),altitudeDeg:a.altitudeDeg,distanceKm:a.distanceKm}}static segments(t){const e=[];let a=[];for(const n of t.points){const s=a[a.length-1];s&&n.t-s.t>N.MAX_GAP_S*1e3&&(e.push(a),a=[]),a.push(n)}return e.push(a),e.filter(n=>n.length>=2)}static bearingDeg(t,e){return(Math.atan2(e.eastM-t.eastM,e.northM-t.northM)/R.DEG+360)%360}}class Yt{constructor(t,e,a,n,s){this.tracks=t,this.observer=e,this.startMs=a,this.maxObjects=n,this.options=s}build(){const t=[];for(const a of this.tracks){const n=R.keyOf(a),s=this.options.models?.get(n)??U.of(void 0);R.segments(a).forEach((i,o)=>{const r=i.map(h=>({point:h,at:R.offsetOf(this.observer,h)}));if(!r.some(h=>h.at.altitudeDeg>=0))return;const l=r.map((h,p)=>({t:h.point.t-this.startMs,eastM:h.at.eastM,northM:h.at.northM,altitudeM:h.at.upM,headingDeg:h.point.trackDeg??(p+1<r.length?R.bearingDeg(h.at,r[p+1].at):R.bearingDeg(r[p-1].at,h.at))})),c=R.idOf(a,o),u=r[Math.floor(r.length/2)].point,d=this.options.sunElevationAt?.(u)??90;t.push({object:{id:c,kind:"aircraft",eastM:l[0].eastM,northM:l[0].northM,headingDeg:l[0].headingDeg,sizeM:R.sizeOf(s),model:J.idOf(s.code)?{id:J.idOf(s.code)}:void 0,color:C.bodyColor(s),lights:[...C.lights(s,d),...C.landingLights(s,d,i.map(h=>({t:h.t-this.startMs,altitudeFt:h.altitudeFt})))],track:l},presence:{fromMs:l[0].t,untilMs:l[l.length-1].t},flight:{icao:a.icao,nonIcao:a.nonIcao,points:i},closestKm:Math.min(...r.map(h=>h.at.distanceKm))})})}t.sort((a,n)=>a.closestKm-n.closestKm);const e=t.slice(0,this.maxObjects);return{objects:e.map(a=>a.object),presence:new Map(e.map(a=>[a.object.id,a.presence])),flights:new Map(e.map(a=>[a.object.id,a.flight])),total:t.length,shown:e.length}}}const qt=[[20,0],[120,0],[130,1.5],[140,4],[150,7.5],[160,7.5]],Jt=[[20,1.5],[40,1],[60,1],[80,0],[120,0],[130,1],[140,1],[150,-3],[160,-6.5],[170,-12]],bt=.16,xt=1,$t=[[0,-2],[10,-1],[20,0],[40,0],[50,-2],[60,-4.5],[70,-7.5],[80,-11],[90,-15],[100,-19.5],[110,-25]],Zt=[[60,-15.8],[70,-11.5],[80,-8],[90,-5],[100,-2.7],[110,-1.2],[120,-.3],[130,0],[140,-2],[150,-6],[160,-10],[170,-15],[180,-20]],Qt=1.5,Et=-40,te=1.5,ee={takeoff:{jetMps:300,flightMps:80,jetShare:[1,1,.9,.6,.3,.1,0,0]},overflight:{jetMps:280,flightMps:130,jetShare:[1,1,.9,.6,.3,.1,0,0]},approach:{jetMps:180,flightMps:70,jetShare:[.6,.5,.4,.2,.1,0,0,0]}};class w{static bandsDb(t,e,a=340){const n=ee[e],s=w.fan(t)-w.fan(90),i=.62*Math.max(0,n.jetMps-n.flightMps)/a,o=-30*Math.log10(1+i/(1+i**5)**.2*Math.cos(t*Math.PI/180));return g.OCTAVES.map((r,l)=>{const c=o+w.jetRemainder(t,r*te/n.jetMps),u=n.jetShare[l];return 10*Math.log10(u*10**(c/10)+(1-u)*10**(s/10))})}static loudestDb(t){const e=w.loudest.get(t);if(e)return e;const a=g.OCTAVES.map(()=>-1/0);for(let n=0;n<=180;n+=5)w.bandsDb(n,t).forEach((s,i)=>a[i]=Math.max(a[i],s));return w.loudest.set(t,a),a}static loudest=new Map;static angleDeg(t,e){const a=t.reduce((s,i,o)=>s+i*e[o],0),n=Math.hypot(...t)*Math.hypot(...e);return n===0?90:Math.acos(Math.min(1,Math.max(-1,a/n)))*180/Math.PI}static fan(t){const e=w.read($t,t,!0),a=w.read(Zt,t,!0)+Qt;return 10*Math.log10(10**(e/10)+10**(a/10))}static jetRemainder(t,e){const a=Math.min(1,Math.max(0,Math.log(e/bt)/Math.log(xt/bt)));return(1-a)*w.read(qt,t)+a*w.read(Jt,t)}static read(t,e,a=!1){const[n,s]=[t[0],t[1]],[i,o]=[t[t.length-2],t[t.length-1]];if(e<=n[0])return a?Math.max(Et,n[1]+(s[1]-n[1])/(s[0]-n[0])*(e-n[0])):n[1];if(e>=o[0])return a?Math.max(Et,o[1]+(o[1]-i[1])/(o[0]-i[0])*(e-o[0])):o[1];for(let r=1;r<t.length;r++){const[l,c]=[t[r-1],t[r]];if(e<=c[0])return l[1]+(c[1]-l[1])*(e-l[0])/(c[0]-l[0])}return o[1]}}class A{static GRASS={flowResistivityKPa:200,earHeightM:1.6};static COHERENCE=.4;static JITTER_S=1e-4;static ECHO_UNDER_S=5e-4;static ECHO_FROM_S=.0015;static LOW_HZ=125;static HIGH_HZ=2e3;static AIR_DENSITY=1.2;static reflection(t,e,a=A.GRASS){const[n,s]=A.impedance(t,a);return A.reflected(n,s,Math.sin(Math.max(0,e)*Math.PI/180))}static impedance(t,e=A.GRASS){const a=A.AIR_DENSITY*t/(e.flowResistivityKPa*1e3);return[1+.0571*a**-.754,-.087*a**-.732]}static reflected(t,e,a){const[n,s,i,o]=[t*a-1,e*a,t*a+1,e*a],r=i*i+o*o;return{re:(n*i+s*o)/r,im:(s*i-n*o)/r}}static delayS(t,e=A.GRASS,a=340){return 2*e.earHeightM*Math.sin(Math.max(0,t)*Math.PI/180)/a}static excessDb(t,e=A.GRASS,a=340){const n=`${e.flowResistivityKPa}|${e.earHeightM}|${a}`;let s=A.overheads.get(n);return s||A.overheads.set(n,s=A.bandsDb(90,e,a)),A.bandsDb(t,e,a).map((i,o)=>i-s[o])}static echo(t,e=A.GRASS,a=340){const n=A.delayS(t,e,a);if(n<=A.ECHO_UNDER_S)return;const s=Math.min(1,(n-A.ECHO_UNDER_S)/(A.ECHO_FROM_S-A.ECHO_UNDER_S)),i=s*s*(3-2*s),o=r=>{const l=A.reflection(r,t,e);return i*A.COHERENCE*Math.hypot(l.re,l.im)};return{delayS:n,lowGain:o(A.LOW_HZ),highGain:o(A.HIGH_HZ),jitterS:A.JITTER_S}}static overheads=new Map;static thirds=g.OCTAVES.map(t=>[-1,0,1].map(e=>{const a=t*2**(e/3);return{middle:a,from:a*2**(-1/6),to:a*2**(1/6)}}));static impedances=new Map;static bandsDb(t,e,a){const n=A.delayS(t,e,a),s=A.COHERENCE,i=Math.sin(Math.max(0,t)*Math.PI/180);let o=A.impedances.get(e.flowResistivityKPa);return o||A.impedances.set(e.flowResistivityKPa,o=A.thirds.map(r=>r.map(l=>A.impedance(l.middle,e)))),A.thirds.map((r,l)=>{let c=0;return r.forEach((u,d)=>{const h=A.reflected(o[l][d][0],o[l][d][1],i),p=2*Math.PI*n*(u.to-u.from),[m,E]=p<1e-9?[1,0]:[(Math.sin(2*Math.PI*u.to*n)-Math.sin(2*Math.PI*u.from*n))/p,(Math.cos(2*Math.PI*u.from*n)-Math.cos(2*Math.PI*u.to*n))/p];c+=1+h.re*h.re+h.im*h.im+2*s*(h.re*m+h.im*E)}),10*Math.log10(c/r.length)})}}const q={takeoff:{shapeDb:[10,3,-3,-2,-2,-2,5,4],levelDb:0},approach:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:-8}},ae={takeoff:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:0},approach:{shapeDb:[0,0,0,0,0,0,0,0],levelDb:-8}},Ot=[{id:"turbofan-narrow-body",name:"Turbofan airliner, narrow-body",kinds:["airliner-narrow"],totalDbA:148,shapeDb:[-32,-17,-9,-6,-5,-7,-12,-22],character:{toneHz:1800,toneShare:.3,humHz:90,humShare:.7},regimes:q},{id:"turbojet-supersonic",name:"Supersonic turbojet airliner",kinds:["airliner-supersonic"],totalDbA:169.5,shapeDb:[-22,-13,-9,-6,-6,-9,-15,-25],character:{humHz:100,humShare:.7},regimes:ae},{id:"turbofan-wide-body",name:"Turbofan airliner, wide-body",kinds:["airliner-wide"],totalDbA:151,shapeDb:[-28,-14,-7,-4,-3,-6,-12,-22],character:{toneHz:1200,toneShare:.3,humHz:70,humShare:.7},regimes:q},{id:"regional-jet",name:"Regional jet",kinds:["regional-jet"],totalDbA:144,shapeDb:[-32,-17,-9,-5,-4,-6,-11,-21],character:{toneHz:1900,toneShare:.3,humHz:95,humShare:.7},regimes:q},{id:"business-jet",name:"Business jet",kinds:["business-jet"],totalDbA:141,shapeDb:[-30,-15,-8,-4,-3,-4,-9,-19],character:{toneHz:2500,toneShare:.25,humHz:110,humShare:.7},regimes:q},{id:"turboprop",name:"Turboprop",kinds:["regional-turboprop","turboprop-light"],totalDbA:138,shapeDb:[-14,-9,-8,-6,-8,-13,-20,-28],character:{toneHz:80,toneShare:.5}},{id:"light-piston",name:"Light piston aircraft",kinds:["light-piston"],totalDbA:130,shapeDb:[-20,-10,-3,-6,-10,-20,-27,-42],character:{toneHz:80,toneShare:.4,modulationHz:80,modulationDepth:.4}},{id:"piston-heavy",name:"Heavy piston aircraft",kinds:["piston-heavy"],totalDbA:140,shapeDb:[-31,-12,-11,-9,-7,-6,-7,-11],character:{toneHz:84,toneShare:.4,modulationHz:84,modulationDepth:.36}},{id:"ultralight",name:"Ultralight",kinds:["ultralight"],totalDbA:124,shapeDb:[-16,-8,-5,-4,-9,-15,-23,-31],character:{toneHz:140,toneShare:.4}},{id:"helicopter-light",name:"Light helicopter",kinds:["helicopter-light"],totalDbA:134,shapeDb:[-15,-8,-4,-3,-6,-10,-16,-24],character:{modulationHz:20,modulationDepth:.5}},{id:"helicopter-medium",name:"Medium helicopter",kinds:["helicopter-medium"],totalDbA:138,shapeDb:[-14,-7,-4,-3,-6,-10,-16,-24],character:{modulationHz:22,modulationDepth:.5}},{id:"helicopter-heavy",name:"Heavy helicopter",kinds:["helicopter-heavy"],totalDbA:144,shapeDb:[-12,-6,-4,-4,-7,-11,-17,-25],character:{modulationHz:17,modulationDepth:.5}},{id:"military-jet",name:"Military jet",kinds:["military-jet"],totalDbA:152,shapeDb:[-26,-12,-6,-3,-2,-3,-7,-15]},{id:"glider",name:"Glider",kinds:["glider"],totalDbA:85,shapeDb:[-30,-22,-15,-10,-8,-8,-14,-22]},{id:"balloon",name:"Hot-air balloon",kinds:["balloon"],totalDbA:100,shapeDb:[-25,-15,-9,-5,-3,-6,-12,-20]},{id:"unmanned",name:"Unmanned aircraft",kinds:["unmanned"],totalDbA:88,shapeDb:[-40,-30,-20,-12,-6,-3,-3,-8],character:{toneHz:450,toneShare:1}}],ft=(b,t)=>b.map(e=>e+t-g.sumDb(b));function ne(b,t){if(!b)return;const e=t.toneRatio??1,a=t.toneGain??1;return{...b,...b.toneHz!==void 0?{toneHz:b.toneHz*e,toneShare:Math.min(1,(b.toneShare??0)*a)}:{},...b.humHz!==void 0?{humHz:b.humHz*e,humShare:Math.min(1,(b.humShare??0)*a)}:{}}}const St=Ot.map(b=>{const t=b.regimes===q?"turbofan":void 0,e={id:b.id,name:b.name,soundPowerA:ft(b.shapeDb,b.totalDbA),character:b.character,directivity:t};if(!b.regimes)return e;const a={overflight:e};for(const[n,s]of Object.entries(b.regimes))a[n]={id:`${b.id}-${n}`,name:`${b.name}, ${n}`,soundPowerA:ft(b.shapeDb.map((i,o)=>i+s.shapeDb[o]),b.totalDbA+s.levelDb),character:ne(b.character,s),directivity:t};return{...e,regimes:a}});class M{static DEFAULT_AMBIENT_DB_A=35;static DETECTION_MARGIN_DB=3;static AMBIENT_SHAPE_DB=Dt.OUTDOOR_SHAPE_DB;static HEARING_FLOOR_DB_A=0;static ITERATIONS=30;static CONVERGED_MS=.5;static VELOCITY_STEP_MS=500;static CLIMB_MPS=2.5;static DESCENT_MPS=1.5;static LOW_M=3e3;static CLIMB_SPAN_MS=3e4;static noiseOfKind(t){const e=Ot.find(a=>a.kinds.includes(t));return St.find(a=>a.id===(e?.id??"turbofan-narrow-body"))}static bandsAt(t,e,a=g.STANDARD){const n=20*Math.log10(Math.max(e*1e3,1))+11;return g.OCTAVES.map((s,i)=>t.soundPowerA[i]-n-g.absorptionDbPerKm(s,a)*e)}static couldBeHeard(t,e,a=M.DEFAULT_AMBIENT_DB_A,n=g.STANDARD,s){const i=M.ambientBands(a,s);return Object.entries(t.regimes??{overflight:t}).some(([r,l])=>M.bandsAt(l,e,n).map((c,u)=>c+(l.directivity==="turbofan"?w.loudestDb(r)[u]:0)).some((c,u)=>c>=Math.max(i[u]+M.DETECTION_MARGIN_DB,M.HEARING_FLOOR_DB_A)))}static ambientBands(t,e=M.AMBIENT_SHAPE_DB){const a=g.sumDb(e);return e.map(n=>t+n-a)}static heardAt(t,e,a,n={}){const s=n.air??g.STANDARD,i=g.speedOfSound(s.temperatureC),o=t.points[t.points.length-1]?.t;if(o===void 0)return;let r=Math.min(a,o),l=N.positionAt(t,r);if(!l)return;let c=j.seenFrom(e,l.geo);for(let _=0;_<M.ITERATIONS;_++){const k=a-c.distanceKm*1e3*1e3/i,$=Math.abs(k-r);if(r=k,l=N.positionAt(t,r),!l)return;if(c=j.seenFrom(e,l.geo),$<M.CONVERGED_MS)break}const u=N.positionAt(t,a),d=u?j.seenFrom(e,u.geo):c,h=M.regimeAt(t,r,e),p=M.inRegime(n.noise??St[0],h),m=n.ambientDbA??M.DEFAULT_AMBIENT_DB_A,E=M.ambientBands(m,n.ambientShapeDb),O=M.emissionAngle(t,e,r),B=p.directivity==="turbofan"?w.bandsDb(O,h,i):void 0,v=n.ground===null?g.OCTAVES.map(()=>0):A.excessDb(c.altitudeDeg,n.ground,i),S=M.bandsAt(p,c.distanceKm,s).map((_,k)=>_+(B?.[k]??0)+v[k]),F=S.map((_,k)=>_>=Math.max(E[k]+M.DETECTION_MARGIN_DB,M.HEARING_FLOOR_DB_A)),x=S.indexOf(Math.max(...S)),L=F.lastIndexOf(!0);return{track:t,audible:F.some(Boolean),levelDbA:g.sumDb(S),bandsDbA:S,ambientDbA:m,delayS:(a-r)/1e3,emittedAtMs:r,sound:c,seen:d,lagDeg:M.angleBetween(c,d),dopplerRatio:M.doppler(t,e,r,i),dominantHz:g.OCTAVES[x],cutoffHz:L<0?void 0:g.OCTAVES[L],regime:h,noise:p,emissionAngleDeg:O}}static emissionAngle(t,e,a){const n=M.VELOCITY_STEP_MS,s=N.positionAt(t,a-n),i=N.positionAt(t,a+n),o=N.positionAt(t,a);if(!s||!i||!o)return 90;const r=d=>{const h=j.seenFrom(e,d),p=h.altitudeDeg*Math.PI/180,m=h.azimuthDeg*Math.PI/180,E=h.distanceKm*1e3;return[E*Math.cos(p)*Math.sin(m),E*Math.cos(p)*Math.cos(m),E*Math.sin(p)]},[l,c,u]=[r(s.geo),r(i.geo),r(o.geo)];return w.angleDeg(c.map((d,h)=>d-l[h]),u.map(d=>-d))}static regimeAt(t,e,a){const n=M.CLIMB_SPAN_MS,s=N.positionAt(t,e-n)??N.positionAt(t,e),i=N.positionAt(t,e+n)??N.positionAt(t,e),o=N.positionAt(t,e);if(!s||!i||!o)return"overflight";const r=(Math.min(e+n,t.points[t.points.length-1].t)-Math.max(e-n,t.points[0].t))/1e3;if(r<=0)return"overflight";const l=(i.altitudeFt-s.altitudeFt)*.3048/r;return o.altitudeFt*.3048-a.heightM>M.LOW_M?"overflight":l>M.CLIMB_MPS?"takeoff":l<-1.5?"approach":"overflight"}static inRegime(t,e){return t.regimes?.[e]??t}static profile(t,e,a,n,s=2e3,i={}){const o=[];let r,l,c=a;for(let u=a;u<=n;u+=s){const d=M.heardAt(t,e,u,i);d&&(!l||d.levelDbA>l.levelDbA)&&(l=d,c=u),d?.audible?r?r.untilMs=u:o.push(r={fromMs:u,untilMs:u}):r=void 0}return{track:t,audible:o,peakDbA:l?.levelDbA??-1/0,peakAtMs:c,peakDelayS:l?.delayS??0}}static angleBetween(t,e){const a=c=>{const u=c.altitudeDeg*Math.PI/180,d=c.azimuthDeg*Math.PI/180;return[Math.cos(u)*Math.sin(d),Math.cos(u)*Math.cos(d),Math.sin(u)]},[n,s,i]=a(t),[o,r,l]=a(e);return Math.acos(Math.min(1,Math.max(-1,n*o+s*r+i*l)))*180/Math.PI}static doppler(t,e,a,n){const s=M.VELOCITY_STEP_MS,i=N.positionAt(t,a-s),o=N.positionAt(t,a+s);if(!i||!o)return 1;const r=j.seenFrom(e,i.geo).distanceKm*1e3,l=j.seenFrom(e,o.geo).distanceKm*1e3;return 1/(1-(r-l)/(2*s/1e3)/n)}}class pe{static at(t,e,a,n,s={}){const i=N.seenFrom(t,a,n);if(!i)return;const o=U.of(e),r=M.heardAt(t,a,n,{noise:M.noiseOfKind(o.kind),...s});return{hex:`${t.nonIcao?"~":""}${t.icao.toString(16).padStart(6,"0")}`,registration:e?.registration,typeCode:o.code??e?.type,name:o.basis==="nothing"?void 0:o.name,kind:o.kind,basis:o.basis,military:e?.military===!0,restricted:e?.restricted===!0,altitudeFt:i.altitudeFt,groundSpeedKt:i.groundSpeedKt,trackDeg:i.trackDeg,sky:i.sky,angularRateDegPerS:i.angularRateDegPerS,hearing:r&&{audible:r.audible,levelDbA:r.levelDbA,ambientDbA:r.ambientDbA,delayS:r.delayS,lagDeg:r.lagDeg,dopplerRatio:r.dopplerRatio,cutoffHz:r.cutoffHz,dominantHz:r.dominantHz}}}}class T{static REFERENCE_AMPLITUDE=.02;static MASKING_RANGE_DB=6;static KNEE_DB=20;static COMPRESSION_RATIO=1;static EXPANSION_RATIO=1.8;static HEADROOM_DB=Dt.HEADROOM_DB;static DEFAULT_MAX_VOICES=4;static candidates(t,e,a,n,s={}){const i=new Set;for(const[o,r]of t){const l=M.noiseOfKind(U.of(e.get(a(r))).kind);let c=1/0;for(const u of r.points)c=Math.min(c,j.seenFrom(n,{lat:u.lat,lng:u.lng,heightM:u.altitudeFt*.3048}).distanceKm);M.couldBeHeard(l,c,s.ambientDbA,s.air,s.ambientShapeDb)&&i.add(o)}return i}static voices(t,e,a,n,s,i,o={}){const r=[];for(const l of t){const c=e.get(l);if(!c||o.only?.(l)===!1)continue;const u=o.kindOf?.(l)??U.of(a.get(n(c))).kind,d=o.noiseOf?.(l)??M.noiseOfKind(u),h=M.heardAt(c,s,i,{...o,noise:d});if(!h?.audible)continue;const p=o.throughDb,m=p?h.bandsDbA.map((E,O)=>E-(p[O]??0)):h.bandsDbA;p&&!T.noticed(m,h.ambientDbA,o.ambientShapeDb)||r.push({id:l,kind:u,bandAmplitudes:T.bandAmplitudes(m,h.ambientDbA,o.referenceAmplitude,{ambientShapeDb:o.ambientShapeDb,expandUnderKnee:o.expandUnderKnee}),levelDbA:p?g.sumDb(m):h.levelDbA,distanceKm:h.sound.distanceKm,dopplerRatio:h.dopplerRatio,azimuthDeg:h.sound.azimuthDeg,elevationDeg:h.sound.altitudeDeg,character:h.noise.character,groundEcho:o.ground===null?void 0:A.echo(h.sound.altitudeDeg,o.ground,g.speedOfSound((o.air??g.STANDARD).temperatureC))})}return r.sort((l,c)=>c.levelDbA-l.levelDbA).slice(0,o.maxVoices??T.DEFAULT_MAX_VOICES)}static noticed(t,e,a){const n=M.ambientBands(e,a);return t.some((s,i)=>s>=n[i]+M.DETECTION_MARGIN_DB)}static bandAmplitudes(t,e,a=T.REFERENCE_AMPLITUDE,n={}){const s=M.ambientBands(e,n.ambientShapeDb),i=n.expandUnderKnee===!1?1:T.EXPANSION_RATIO,o=M.DETECTION_MARGIN_DB,r=g.sumDb(t),l=r-e,c=l>=T.KNEE_DB?T.KNEE_DB+(l-T.KNEE_DB)/T.COMPRESSION_RATIO:T.KNEE_DB-(T.KNEE_DB-l)*i,u=a*10**((c-T.HEADROOM_DB)/20);return t.map((d,h)=>{const p=Math.min(1,Math.max(0,(d-s[h]-o+T.MASKING_RANGE_DB)/(2*T.MASKING_RANGE_DB)));return p*p*(3-2*p)*u*10**((d-r)/20)})}static BANDS_HZ=g.OCTAVES}class Q{static RUMBLE_BELOW_HZ=500;static DULL_BELOW_HZ=2e3;static PITCH_NOTICED=.03;static text(t,e,a,n){const s=(d,h=0)=>d.toLocaleString(n,{maximumFractionDigits:h}),i=(d,h)=>d.replace(/\{(\w+)\}/g,(p,m)=>h[m]??`{${m}}`),o=[],r=[t.registration,t.name].filter(Boolean).join(" · ");o.push(r||i(e.unnamed,{hex:t.hex}));const l=[i(e.altitude,{value:s(Math.round(t.altitudeFt/100)*100)}),t.groundSpeedKt===void 0?void 0:i(e.speed,{value:s(Math.round(t.groundSpeedKt))}),t.trackDeg===void 0?void 0:i(e.heading,{value:s(Math.round(t.trackDeg))})].filter(Boolean);o.push(l.join(" · ")),o.push(i(e.position,{distance:s(t.sky.distanceKm,t.sky.distanceKm<10?1:0),elevation:s(Math.round(t.sky.altitudeDeg)),bearing:a(t.sky.azimuthDeg)}));const c=t.hearing;if(!c)o.push(e.soundUnknown);else if(!c.audible)o.push(i(e.inaudible,{level:s(Math.round(c.levelDbA)),ambient:s(Math.round(c.ambientDbA))}));else{const d=c.cutoffHz??0,h=d<=Q.RUMBLE_BELOW_HZ?e.rumble:d<=Q.DULL_BELOW_HZ?e.muffled:e.broad,p=c.dopplerRatio-1,m=Math.abs(p)<Q.PITCH_NOTICED?"":i(p>0?e.pitchHigher:e.pitchLower,{percent:s(Math.round(Math.abs(p)*100))});o.push(i(e.heard,{level:s(Math.round(c.levelDbA)),delay:s(Math.round(c.delayS)),lag:s(Math.round(c.lagDeg)),character:i(h,{cutoff:s(d)}),pitch:m}))}t.contrail&&o.push(i(t.contrail.persistent?e.contrailPersistent:e.contrailShort,{rhi:s(Math.round(t.contrail.iceRelativeHumidity*100))}));const u=[t.military?e.military:void 0,t.restricted?e.restricted:void 0].filter(Boolean);return u.length>0&&o.push(u.join(" · ")),o.push(e.candidate),o.join(`
|
|
2
2
|
`)}}class nt{static EFFICIENCY={"airliner-narrow":.34,"airliner-wide":.38,"regional-jet":.32,"business-jet":.3,"military-jet":.22,unknown:.34};static efficiencyOf(t){return nt.EFFICIENCY[t]}}class f{static EMISSION_INDEX_WATER=1.25;static COMBUSTION_HEAT=432e5;static AIR_HEAT_CAPACITY=1004;static MOLAR_MASS_RATIO=.622;static FT_TO_M=.3048;static TROPOPAUSE_M=11e3;static TROPOPAUSE_HPA=226.32;static ISOTHERMAL_SCALE_HEIGHT_M=6341.62;static pressureAtAltitudeFt(t){const e=t*f.FT_TO_M;return e<=f.TROPOPAUSE_M?1013.25*(1-225577e-10*e)**5.25588:f.TROPOPAUSE_HPA*Math.exp(-(e-f.TROPOPAUSE_M)/f.ISOTHERMAL_SCALE_HEIGHT_M)}static saturationOverWaterPa(t){const e=t+273.15;return Math.exp(54.842763-6763.22/e-4.21*Math.log(e)+367e-6*e+Math.tanh(.0415*(e-218.8))*(53.878-1331.22/e-9.44523*Math.log(e)+.014025*e))}static saturationOverIcePa(t){const e=t+273.15;return Math.exp(9.550426-5723.265/e+3.53068*Math.log(e)-.00728332*e)}static iceRelativeHumidity(t,e){return e*f.saturationOverWaterPa(t)/f.saturationOverIcePa(t)}static mixingSlope(t,e){return f.EMISSION_INDEX_WATER*f.AIR_HEAT_CAPACITY*t*100/(f.MOLAR_MASS_RATIO*f.COMBUSTION_HEAT*(1-e))}static criticalTemperatureC(t,e){const a=Math.log(f.mixingSlope(t,e)-.053);return-46.46+9.43*a+.72*a*a}static requiredHumidity(t,e,a){const n=f.criticalTemperatureC(t,e);return(f.mixingSlope(t,e)*(a-n)+f.saturationOverWaterPa(n))/f.saturationOverWaterPa(a)}static evaluate(t,e){const a=f.criticalTemperatureC(t.pressureHpa,e),n=f.requiredHumidity(t.pressureHpa,e,t.temperatureC),s=f.iceRelativeHumidity(t.temperatureC,t.relativeHumidity),i=t.temperatureC<a&&t.relativeHumidity>=n;return{forms:i,persistent:i&&s>=1,criticalTemperatureC:a,requiredHumidity:n,iceRelativeHumidity:s}}}class G{static HOLD_MS=36e5;static DEG=Math.PI/180;static GAS_CONSTANT_OVER_GRAVITY=287.05/9.80665;static at(t,e,a){if(t.length===0)return;const n=t[0],s=t[t.length-1];if(e<n.t-G.HOLD_MS||e>s.t+G.HOLD_MS)return;const i=t.findIndex(h=>h.t>e),o=i===0?t[0]:t[(i===-1?t.length:i)-1],r=i===-1||i===0?o:t[i],l=G.atLevel(o,a),c=G.atLevel(r,a);if(!l||!c)return;const u=r.t>o.t?Math.min(1,Math.max(0,(e-o.t)/(r.t-o.t))):0,d=(h,p)=>h+(p-h)*u;return{pressureHpa:a,temperatureC:d(l.temperatureC,c.temperatureC),relativeHumidity:d(l.relativeHumidity,c.relativeHumidity),driftEastMs:d(l.driftEastMs,c.driftEastMs),driftNorthMs:d(l.driftNorthMs,c.driftNorthMs),shearPerS:d(l.shearPerS,c.shearPerS)}}static atLevel(t,e){const a=t.levels;for(let n=0;n+1<a.length;n++){const s=a[n],i=a[n+1];if(e>s.pressureHpa||e<i.pressureHpa)continue;const o=(Math.log(s.pressureHpa)-Math.log(e))/(Math.log(s.pressureHpa)-Math.log(i.pressureHpa)),r=(h,p)=>h+(p-h)*o,l=h=>{const p=h.windFromDeg*G.DEG;return{east:-h.windSpeedMs*Math.sin(p),north:-h.windSpeedMs*Math.cos(p)}},c=l(s),u=l(i),d=G.GAS_CONSTANT_OVER_GRAVITY*((s.temperatureC+i.temperatureC)/2+273.15)*Math.log(s.pressureHpa/i.pressureHpa);return{pressureHpa:e,temperatureC:r(s.temperatureC,i.temperatureC),relativeHumidity:r(s.relativeHumidity,i.relativeHumidity),driftEastMs:r(c.east,u.east),driftNorthMs:r(c.north,u.north),shearPerS:Math.hypot(u.east-c.east,u.north-c.north)/d}}}}class K{static MIN_ALTITUDE_FT=2e4;static DENSE_MS=3e5;static SPARSE_STEP_MS=6e4;static SATURATION_HORIZON_MS=3*36e5;static SATURATION_STEP_MS=6e5;static PRESSURE_STEP_HPA=5;static plan(t,e,a,n){if(a.length===0)return[];const s=[],i=new Map,o=(r,l,c)=>{const u=Math.round(l/K.PRESSURE_STEP_HPA)*K.PRESSURE_STEP_HPA,d=K.SATURATION_STEP_MS,h=Math.floor(r/d)*d,p=`${u}|${h}`,m=i.get(p);if(m!==void 0)return m+(h-r)/1e3;let E=1/0;for(let O=d;O<=K.SATURATION_HORIZON_MS;O+=d){const B=G.at(a,h+O,u);if(!B)break;if(f.evaluate(B,c).iceRelativeHumidity<1){E=O/1e3;break}}return i.set(p,E),E+(h-r)/1e3};for(const r of t.objects){const l=t.flights.get(r.id),c=r.track;if(!l||!c||c.length!==l.points.length)continue;const u=e?.get(Z.keyOf(l))??U.of(void 0),d=nt.efficiencyOf(u.kind);if(d===void 0)continue;const h=[];let p=-1/0;c.forEach((m,E)=>{if(m.t<-K.DENSE_MS&&E+1<c.length&&m.t-p<K.SPARSE_STEP_MS)return;p=m.t;const O=l.points[E],B=f.pressureAtAltitudeFt(O.altitudeFt),v=G.at(a,n+m.t,B),S=v&&f.evaluate(v,d);h.push({tMs:m.t,eastM:m.eastM,northM:m.northM,upM:m.altitudeM??0,forms:S?.forms??!1,persistent:S?.persistent??!1,lifetimeS:S?ot.lifetimeS(S.iceRelativeHumidity):0,driftEastMs:v?.driftEastMs??0,driftNorthMs:v?.driftNorthMs??0,shearPerS:v?.shearPerS??ot.TYPICAL_SHEAR_PER_S,iceRelativeHumidity:S?.iceRelativeHumidity??0,saturatedForS:S?.persistent?o(n+m.t,B,d):0})}),h.some((m,E)=>m.forms&&h[E+1]?.forms)&&s.push({id:r.id,spanM:u.spanM,points:h})}return s}}class y{static DEFAULT_KIND=V.DEFAULT_KIND;static STEP_MS=1e3;static LEAD_MS=12e4;static FT_PER_M=1/.3048;static ID_PREFIX="decor:";tracks=new Map;static kindOf(t,e){return V.kindOf(t,e)}static flies(t){return V.flies(t)}static ridden(t,e,a,n=()=>{}){const s=st.originOf(t);if(s)for(const i of t.decor){const o=V.kindOf(i,n(i));if(!o)continue;const r=i.sizeM,l=Math.max(r?.widthM??0,r?.lengthM??0,r?.heightM??0)/2;if(l<=0)continue;const c=y.pointAt(i,e,s),{distanceKm:u}=j.seenFrom(a,{lat:c.lat,lng:c.lng,heightM:c.altitudeFt/y.FT_PER_M});if(u*1e3<=l)return{decor:i,kind:o}}}voices(t,e,a,n={},s=()=>{}){const i=st.originOf(t);if(!i)return[];const o=new Map,r=new Map,l=Math.max(t.observerTrack.duration,(t.event.durationSeconds??0)*1e3),c=y.ridden(t,e,a,s)?.decor;for(const u of t.decor){const d=u===c?void 0:V.kindOf(u,s(u));if(!d)continue;const h=`${y.ID_PREFIX}${u.id}`;o.set(h,this.trackOf(u,h,i,l)),r.set(h,d)}for(const u of this.tracks.keys())o.has(u)||this.tracks.delete(u);return o.size===0?[]:T.voices(new Set(o.keys()),o,new Map,u=>String(u.icao),a,e,{...n,kindOf:u=>r.get(u)})}trackOf(t,e,a,n){const s=JSON.stringify([t.track,t.eastM,t.northM,t.headingDeg,a.lat,a.lng,n]),i=this.tracks.get(e);if(i?.key===s)return i.track;const o=[];for(let d=0;d<=n;d+=y.STEP_MS)o.push(y.pointAt(t,d,a));(o.length===0||o[o.length-1].t<n)&&o.push(y.pointAt(t,n,a));const r=o[0],l=o[1]??r,c=d=>(l[d]-r[d])/(l.t-r.t||1);for(let d=y.STEP_MS*10;d<=y.LEAD_MS;d+=y.STEP_MS*10)o.unshift({t:-d,lat:r.lat-c("lat")*d,lng:r.lng-c("lng")*d,altitudeFt:Math.max(0,r.altitudeFt-c("altitudeFt")*d)});const u={icao:y.hash(e),nonIcao:!0,points:o};return this.tracks.set(e,{key:s,track:u}),u}static pointAt(t,e,a){const n=Tt(t,e),s=at(n.eastM,-n.northM,a.lat,a.lng);return{t:e,lat:s.lat,lng:s.lng,altitudeFt:n.altitudeM*y.FT_PER_M}}static hash(t){let e=0;for(let a=0;a<t.length;a++)e=e*31+t.charCodeAt(a)>>>0;return e}}class z{static CABIN_DB_A={"airliner-wide":76,"airliner-narrow":78,"regional-jet":78,"business-jet":82,"regional-turboprop":84,"turboprop-light":88,"light-piston":92,"piston-heavy":90,"military-jet":95,ultralight:95,"helicopter-light":95,"helicopter-medium":96,"helicopter-heavy":98,glider:70,balloon:60};static JET_CABINS=["airliner-narrow","airliner-wide","airliner-supersonic","regional-jet","business-jet"];static JET_CABIN_SHAPE_DB=[-3,-4,-13,-24,-33,-36,-42,-55];static DEFAULT_DB_A=78;static voice(t,e={}){const a=it.aircraftOf(t);if(!a)return;const n=M.noiseOfKind(a),s=it.insulationDb(t),i=z.JET_CABINS.includes(a)&&t?.windowsOpen!==!0?z.JET_CABIN_SHAPE_DB.map((c,u)=>c+g.aWeightingDb(g.OCTAVES[u])):n.soundPowerA.map((c,u)=>c-s[u]),o=g.sumDb(i),r=z.levelDbA(a,t?.noise),l=i.map(c=>c-o+r);return{id:"observer:cabin",kind:a,bandAmplitudes:T.bandAmplitudes(l,e.ambientDbA??0,e.referenceAmplitude,{ambientShapeDb:e.ambientShapeDb,expandUnderKnee:e.expandUnderKnee}),levelDbA:r,inside:!0,distanceKm:0,dopplerRatio:1,azimuthDeg:0,elevationDeg:0,character:n.character}}static levelDbA(t,e){return(z.CABIN_DB_A[t]??z.DEFAULT_DB_A)+20*Math.log10(Math.max(e??1,.01))}}class W{static STEP_MS=250;static FT_PER_M=1/.3048;static ID_PREFIX="body:";tracks=new Map;static noiseOf(t){const e=M.noiseOfKind(t.kind),a=t.quieterDb??0;return a===0?e:{...e,id:`${e.id}-${a}dB`,soundPowerA:e.soundPowerA.map(n=>n-a)}}voices(t,e,a,n,s,i,o={}){const r=new Map,l=new Map,c=new Map;for(const d of t){if(!d.sound)continue;const h=`${W.ID_PREFIX}${d.id}`,p=this.trackOf(d,h,e,n,i);p&&(r.set(h,p),l.set(h,d.sound.kind),c.set(h,W.noiseOf(d.sound)))}for(const d of this.tracks.keys())r.has(d)||this.tracks.delete(d);if(r.size===0)return[];const u=at(a.eastM,-a.northM,n.lat,n.lng);return T.voices(new Set(r.keys()),r,new Map,d=>String(d.icao),{lat:u.lat,lng:u.lng,heightM:a.upM},s,{...o,kindOf:d=>l.get(d),noiseOf:d=>c.get(d)})}trackOf(t,e,a,n,s){const i=`${n.lat},${n.lng},${s}`,o=this.tracks.get(e);if(o&&o.body===t&&o.origin===i)return o.track;const r=[];for(let c=-12e4;c<=s;c+=W.STEP_MS){const u=a(t,c);if(!u)continue;const d=at(u.eastM,-u.northM,n.lat,n.lng);r.push({t:c,lat:d.lat,lng:d.lng,altitudeFt:u.upM*W.FT_PER_M})}if(r.length<2)return;const l={icao:W.hash(e),nonIcao:!0,points:r};return this.tracks.set(e,{body:t,origin:i,track:l}),l}static hash(t){let e=0;for(let a=0;a<t.length;a++)e=e*31+t.charCodeAt(a)>>>0;return e}}export{Y as AircraftAudio,K as AircraftContrails,U as AircraftModels,Dt as AmbientNoise,W as BodyHearing,z as CabinHearing,y as DecorAircraftHearing,R as TrafficDecor,pe as TrafficInfos,T as TrafficSound,Q as TrafficTooltip,Ae as UPPER_AIR_SOURCES};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rr0/ufoathome",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.196.0",
|
|
5
5
|
"description": "UFO@home — record and replay a UFO sighting's shape, movement and appearance",
|
|
6
6
|
"author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={caseHeading:"Case",eventsHeading:"History",kindObservation:"Observation",kindReading:"Reading",kindInterview:"Interview",openEvent:"Open this event alone",toggleEvent:"Show beside the others, or put away",groupReadings:"Group the readings under their observation",alsoAbout:"Also about",foldReadings:"Fold its readings away",unfoldReadings:"Unfold its readings",interpretationOf:"Reading of",passagesHeading:"Told in",byAuthor:"by",linkAnd:"and",caseSummary:"What this case says of itself",editCase:"Edit this case",shareCase:"Share this case"};export{e as caseMessages_en};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={caseHeading:"Caso",eventsHeading:"Historial",kindObservation:"Observación",kindReading:"Lectura",kindInterview:"Entrevista",openEvent:"Abrir solo este evento",toggleEvent:"Mostrar junto a los demás, o quitar",groupReadings:"Agrupar las lecturas por observación",alsoAbout:"También trata de",foldReadings:"Plegar sus lecturas",unfoldReadings:"Desplegar sus lecturas",interpretationOf:"Lectura de",passagesHeading:"Relatado en",byAuthor:"por",linkAnd:"y",caseSummary:"Lo que este caso dice de sí mismo",editCase:"Editar este caso",shareCase:"Compartir este caso"};export{e as caseMessages_es};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={caseHeading:"Dossier",eventsHeading:"Historique",kindObservation:"Observation",kindReading:"Lecture",kindInterview:"Interview",openEvent:"Ouvrir cet événement seul",toggleEvent:"Afficher à côté des autres, ou retirer",groupReadings:"Regrouper les lectures par observation",alsoAbout:"Porte aussi sur",foldReadings:"Replier ses lectures",unfoldReadings:"Déplier ses lectures",interpretationOf:"Lecture de",passagesHeading:"Relaté dans",byAuthor:"par",linkAnd:"et",caseSummary:"Ce que ce dossier dit de lui-même",editCase:"Modifier ce dossier",shareCase:"Partager ce dossier"};export{e as caseMessages_fr};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={caseHeading:"Caso",eventsHeading:"Cronologia",kindObservation:"Osservazione",kindReading:"Lettura",kindInterview:"Intervista",openEvent:"Apri solo questo evento",toggleEvent:"Mostra accanto agli altri, o togli",groupReadings:"Raggruppa le letture per osservazione",alsoAbout:"Riguarda anche",foldReadings:"Chiudi le sue letture",unfoldReadings:"Apri le sue letture",interpretationOf:"Lettura di",passagesHeading:"Raccontato in",byAuthor:"di",linkAnd:"e",caseSummary:"Ciò che questo caso dice di sé",editCase:"Modificare questo caso",shareCase:"Condividi questo caso"};export{e as caseMessages_it};
|