11import type { AirspaceString , AirspaceTyped , Class , LatLon , Point , Type } from '@flyxc/common' ;
22import {
33 AIRSPACE_TILE_SIZE ,
4+ applyTimeRule ,
45 getAirspaceCategory ,
56 getAirspaceColor ,
67 getAirspaceTileUrl ,
@@ -37,6 +38,7 @@ export async function getAirspaceList(
3738 gndAltitude : number ,
3839 showClasses : Class [ ] ,
3940 showTypes : Type [ ] ,
41+ date : Date ,
4042) : Promise < string > {
4143 const tileZoom = Math . min ( zoom , MAX_AIRSPACE_TILE_ZOOM ) ;
4244 const { tile : tileCoords , px } = pixelCoordinates ( latLon , tileZoom , AIRSPACE_TILE_SIZE ) ;
@@ -62,7 +64,7 @@ export async function getAirspaceList(
6264 const info : string [ ] = [ ] ;
6365 for ( let i = 0 ; i < layer . length ; i ++ ) {
6466 const f = layer . feature ( i ) ;
65- const airspace = toTypedAirspace ( f . properties as AirspaceString ) ;
67+ const airspace = applyTimeRule ( toTypedAirspace ( f . properties as AirspaceString ) , date ) ;
6668 const floor = airspace . floorM + ( airspace . floorRefGnd ? gndAltitude : 0 ) ;
6769 const top = airspace . topM + ( airspace . topRefGnd ? gndAltitude : 0 ) ;
6870 const onlyConsiderFloor = gndAltitude == 0 ;
@@ -99,6 +101,8 @@ export class AspMapType {
99101 classes : Class [ ] = [ ] ;
100102 types : Type [ ] = [ ] ;
101103 active_ = true ;
104+ date = new Date ( ) ;
105+
102106 // FetchInfo indexed by fetch key.
103107 fetchInfoMap : Map < number , FetchInfo > = new Map ( ) ;
104108
@@ -126,7 +130,18 @@ export class AspMapType {
126130 }
127131
128132 getTile ( coord : google . maps . Point , zoom : number , doc : Document ) : HTMLElement {
129- return getTile ( coord , zoom , zoom , doc , this . altitude , this . classes , this . types , this . active , this . fetchInfoMap ) ;
133+ return getTile (
134+ coord ,
135+ zoom ,
136+ zoom ,
137+ doc ,
138+ this . altitude ,
139+ this . classes ,
140+ this . types ,
141+ this . active ,
142+ this . fetchInfoMap ,
143+ this . date ,
144+ ) ;
130145 }
131146
132147 // @ts -ignore
@@ -168,6 +183,10 @@ export class AspMapType {
168183 this . types = types ;
169184 }
170185
186+ setDate ( date : Date ) : void {
187+ this . date = date ;
188+ }
189+
171190 // minZoom and maxZoom are not taken into account by the Google Maps API for overlay map types.
172191 // We need to manually activate the layers for the current zoom level.
173192 setCurrentZoom ( zoom : number ) : void {
@@ -204,6 +223,7 @@ export class AspZoomMapType extends AspMapType {
204223 this . types ,
205224 this . active ,
206225 this . fetchInfoMap ,
226+ this . date ,
207227 ) ;
208228 }
209229}
@@ -220,6 +240,7 @@ function getTile(
220240 showTypes : Type [ ] ,
221241 active : boolean ,
222242 fetchInfoMap : Map < number , FetchInfo > ,
243+ date : Date ,
223244) : HTMLElement {
224245 if ( ! active ) {
225246 return doc . createElement ( 'div' ) ;
@@ -262,7 +283,7 @@ function getTile(
262283 return ;
263284 }
264285 const vectorTile = new VectorTile ( new Uint8Array ( buffer ) ) ;
265- renderTiles ( fetchKey , fetchInfoMap , vectorTile , altitude , showClasses , showTypes , mapZoom , tileZoom ) ;
286+ renderTiles ( fetchKey , fetchInfoMap , vectorTile , altitude , showClasses , showTypes , mapZoom , tileZoom , date ) ;
266287 } )
267288 . catch ( ( e ) => {
268289 // AbortError are expected when aborting a request.
@@ -288,6 +309,7 @@ function renderTiles(
288309 showTypes : Type [ ] ,
289310 mapZoom : number ,
290311 tileZoom : number ,
312+ date : Date ,
291313) {
292314 const fetchInfo = fetchInfoMap . get ( fetchKey ) ;
293315 if ( fetchInfo == null ) {
@@ -320,7 +342,7 @@ function renderTiles(
320342
321343 for ( let i = 0 ; i < vectorTile . layers . asp . length ; i ++ ) {
322344 const f = vectorTile . layers . asp . feature ( i ) ;
323- const airspace = toTypedAirspace ( f . properties as any ) ;
345+ const airspace = applyTimeRule ( toTypedAirspace ( f . properties as any ) , date ) ;
324346 const ratio = renderSize / f . extent ;
325347 if (
326348 f . type === 3 &&
0 commit comments