Skip to content

Commit

Permalink
Use mapCenter observable in MapDataResults
Browse files Browse the repository at this point in the history
  • Loading branch information
ar-jan committed Oct 4, 2024
1 parent af012a4 commit 68d961e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions frontend/src/app/models/map-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, forkJoin, of } from 'rxjs';
import { map, of, Observable, switchMap, withLatestFrom } from 'rxjs';
import { Results } from './results';
import { GeoDocument, GeoLocation } from './search-results';
import { Params } from '@angular/router';
Expand All @@ -21,7 +21,7 @@ interface MapData {


export class MapDataResults extends Results<MapDataParameters, MapData> {
private mapCenter: GeoLocation | null = null;
private mapCenter$: Observable<GeoLocation>;

constructor(
store: Store,
Expand All @@ -30,6 +30,13 @@ export class MapDataResults extends Results<MapDataParameters, MapData> {
) {
super(store, query, ['visualizedField']);
this.connectToStore();
this.mapCenter$ = this.state$.pipe(
map(state => state.field),
switchMap(field => field
? this.visualizationService.getGeoCentroid(field.name, this.query.corpus)
: of(null)
)
);
this.getResults();
}

Expand All @@ -39,18 +46,19 @@ export class MapDataResults extends Results<MapDataParameters, MapData> {
return of({ geoDocuments: [], mapCenter: null });
}

const getGeoCentroid$ = this.mapCenter
? of(this.mapCenter)
: this.visualizationService.getGeoCentroid(field.name, this.query.corpus);
const geoDocuments$ = this.visualizationService.getGeoData(
field.name,
this.query,
this.query.corpus
);

return forkJoin({
geoDocuments: this.visualizationService.getGeoData(
field.name,
this.query,
this.query.corpus
),
mapCenter: getGeoCentroid$
});
return geoDocuments$.pipe(
withLatestFrom(this.mapCenter$),
map(([geoDocuments, mapCenter]) => ({
geoDocuments,
mapCenter
}))
);
}

protected stateToStore(state: MapDataParameters): Params {
Expand Down

0 comments on commit 68d961e

Please sign in to comment.