1+ import fs from 'node:fs' ;
2+ import path from 'node:path' ;
3+
14import { TZDate } from '@date-fns/tz' ;
25import { VectorTile } from 'mapbox-vector-tile' ;
36
@@ -13,12 +16,20 @@ import { fetchResponse } from './fetch-timeout';
1316
1417async function getTile ( x : number , y : number , z : number ) : Promise < Map < string , AirspaceTyped > > {
1518 const airspaces = new Map < string , AirspaceTyped > ( ) ;
16- const url = getAirspaceTileUrl ( x , y , z , 'cloud' ) ;
17- const response = await fetchResponse ( url ) ;
18- if ( ! response . ok ) {
19- throw new Error ( `Error reading the tile ${ url } ` ) ;
19+ let buffer : ArrayBuffer ;
20+
21+ const filename = path . join ( __dirname , '../../../..' , `apps/fxc-tiles/src/assets/airspaces/tiles/${ z } /${ x } /${ y } .pbf` ) ;
22+ if ( fs . existsSync ( filename ) ) {
23+ buffer = fs . readFileSync ( filename ) ;
24+ } else {
25+ const url = getAirspaceTileUrl ( x , y , z , 'cloud' ) ;
26+ const response = await fetchResponse ( url ) ;
27+ if ( ! response . ok ) {
28+ throw new Error ( `Error reading the tile ${ url } ` ) ;
29+ }
30+ buffer = await response . arrayBuffer ( ) ;
2031 }
21- const buffer = await response . arrayBuffer ( ) ;
32+
2233 const aspLayer = new VectorTile ( new Uint8Array ( buffer ) ) . layers . asp ;
2334 for ( let i = 0 ; i < aspLayer . length ; i ++ ) {
2435 const feature = aspLayer . feature ( i ) ;
@@ -48,7 +59,7 @@ describe('Time dependent Airspace', () => {
4859 "topLabel": "3281ft GND",
4960 "topM": 1000,
5061 "topRefGnd": true,
51- "type": 3 ,
62+ "type": 29 ,
5263 }
5364 ` ) ;
5465 expect ( airspaces . get ( 'TMA CLERMONT 2.1 (VOL LIBRE)' ) ) . toMatchInlineSnapshot ( `
0 commit comments