diff --git a/src/app/components/map/displacement-layers/displacement-layers.component.ts b/src/app/components/map/displacement-layers/displacement-layers.component.ts index 826b18e85..d680a4493 100644 --- a/src/app/components/map/displacement-layers/displacement-layers.component.ts +++ b/src/app/components/map/displacement-layers/displacement-layers.component.ts @@ -3,6 +3,10 @@ import { SubSink } from 'subsink'; import { MapService } from '@services'; import * as models from '@models'; +import { Store } from '@ngrx/store'; +import { AppState } from '@store'; +import { getFlightDirections } from '@store/filters'; +import { distinctUntilChanged, map } from 'rxjs'; @Component({ @@ -20,6 +24,7 @@ export class DisplacementLayersComponent implements OnInit, OnDestroy { constructor( private mapService: MapService, + private store$: Store, ) { } ngOnInit() { @@ -30,10 +35,22 @@ export class DisplacementLayersComponent implements OnInit, OnDestroy { } ) ); + this.subs.add( + this.store$.select(getFlightDirections).pipe( + map(flightDirs => flightDirs[0] ?? models.FlightDirection.ASCENDING), + distinctUntilChanged(), + ).subscribe(flightDir => { + this.flightDir = flightDir; + if (!!this.displacementOverview) { + this.setDisplacementLayer(this.flightDir, this.displacementOverview) + } + } + ) + ) } public onUpdatePriority(isChecked: boolean): void { - if(isChecked) { + if (isChecked) { this.mapService.enablePriority(); } else { diff --git a/src/app/components/results-menu/timeseries-results-menu/timeseries-results-menu.component.ts b/src/app/components/results-menu/timeseries-results-menu/timeseries-results-menu.component.ts index 160de008e..4d0fd6c45 100644 --- a/src/app/components/results-menu/timeseries-results-menu/timeseries-results-menu.component.ts +++ b/src/app/components/results-menu/timeseries-results-menu/timeseries-results-menu.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, Input, OnDestroy, ViewChild, ElementRef, computed, signal } from '@angular/core'; -import { first, Observable, Subject, withLatestFrom } from 'rxjs'; +import { distinctUntilChanged, first, map, Observable, Subject, withLatestFrom } from 'rxjs'; import { ResizeEvent } from 'angular-resizable-element'; import { Store } from '@ngrx/store'; @@ -66,6 +66,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy { public breakpoint: Breakpoints; public breakpoints = Breakpoints; private subs = new SubSink(); + private flightDirection: models.FlightDirection = models.FlightDirection.ASCENDING; // public pointHistory = []; @@ -100,6 +101,17 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy { ngOnInit(): void { this.pointHistoryService.clearPoints(); + this.subs.add( + this.store$.select(filtersStore.getFlightDirections).pipe( + map(flightDirs => flightDirs[0] ?? models.FlightDirection.ASCENDING), + distinctUntilChanged(), + ).subscribe( + flightDir => { + this.flightDirection = flightDir; + this.updateChart() + } + ) + ) this.subs.add( this.screenSize.breakpoint$.subscribe( point => this.breakpoint = point @@ -147,7 +159,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy { previous_points?.forEach((point, idx) => { let allPointsData = []; this.pointHistoryService.addPoint(point.getGeometry(), idx + 1); - this.netcdfService.getTimeSeries(point.getGeometry()).pipe(first()).subscribe( data => { + this.netcdfService.getTimeSeries(point.getGeometry(), this.flightDirection).pipe(first()).subscribe( data => { allPointsData.push(data); // this.chartData.next(allPointsData); this.maxRange = this.temporalRange = this.getMaxRange(allPointsData); @@ -199,7 +211,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy { public updateChart(): void { let allPointsData = []; for (const series of this.chartStates) { - this.netcdfService.getTimeSeries(series.geoemetry).pipe(first()).subscribe(data => { + this.netcdfService.getTimeSeries(series.geoemetry, this.flightDirection).pipe(first()).subscribe(data => { allPointsData.push(data); // this.chartData.next(allPointsData); this.temporalRange = this.getMaxRange(allPointsData); diff --git a/src/app/services/netcdf-service.service.ts b/src/app/services/netcdf-service.service.ts index c2cb84215..2a4046252 100644 --- a/src/app/services/netcdf-service.service.ts +++ b/src/app/services/netcdf-service.service.ts @@ -10,6 +10,7 @@ import ImageSource from 'ol/source/Image'; import Feature from 'ol/Feature'; import Geometry from 'ol/geom/Geometry'; import WKT from 'ol/format/WKT'; +import { FlightDirection } from '@models'; // import { timeseriesChartItemState } from '@models'; @Injectable({ @@ -23,7 +24,8 @@ export class NetcdfService { public layers: { feature: Feature, browse: ImageLayer }[] = [] // private data = [] - private cache = {}; + private ascendingCache = {} + private descendingCache = {} private totalKeys = []; private maxCacheSize = 10; private csvHeaders = 'series, longitude, latitude, date (mm/dd/yr), short wavelength displacement, source file' @@ -32,20 +34,25 @@ export class NetcdfService { private http: HttpClient, private browseOverlayService: BrowseOverlayService, // private mapService: MapService - private wktService: WktService + private wktService: WktService, + // private store$: Store, ) { } public cacheUpdated = new Subject(); - - public getCache() { - return this.cache + private getTargetCache(flightDir: FlightDirection) { + return flightDir === FlightDirection.ASCENDING ? this.ascendingCache : this.descendingCache; + } + public getCache(flightDir: FlightDirection = FlightDirection.ASCENDING) { + return this.getTargetCache(flightDir) } public removeFromCache(wkt: string): void { - if (this.cache.hasOwnProperty(wkt)) { - delete this.cache[wkt]; + for (const cache of [this.ascendingCache, this.descendingCache]) { + if (cache.hasOwnProperty(wkt)) { + delete cache[wkt]; + } } this.cacheUpdated.next(wkt); } @@ -82,15 +89,19 @@ export class NetcdfService { return output } - public getTimeSeries(geometry): Observable { + public getTimeSeries(geometry, flightDirection =FlightDirection.ASCENDING): Observable { let format = new WKT(); let wktRepresenation = format.writeGeometry(geometry); let index_id = wktRepresenation; console.log(`getting ${index_id}`) - if (this.cache.hasOwnProperty(index_id)) { - console.log('cache hit', of(this.cache[index_id])); - return of(this.cache[index_id]) + + let target_cache = this.getTargetCache(flightDirection) + + + if (target_cache.hasOwnProperty(index_id)) { + console.log('cache hit', of(target_cache[index_id])); + return of(target_cache[index_id]) } else { return this.http.post(`${this.url}${this.timeSeriesEndpoint}`, { "wkt": wktRepresenation, @@ -99,11 +110,11 @@ export class NetcdfService { first(), map(response => { (response as any).aoi = wktRepresenation; - this.cache[index_id] = response; + target_cache[index_id] = response; this.totalKeys.push(index_id); if (this.totalKeys.length > this.maxCacheSize) { let deleted = this.totalKeys.splice(0); - delete this.cache[deleted[0]]; + delete target_cache[deleted[0]]; } console.log('cache miss', response); this.cacheUpdated.next(index_id)