Skip to content

Commit

Permalink
Revert "Use share operator for mapCenter"
Browse files Browse the repository at this point in the history
This reverts commit 42f939a.
  • Loading branch information
ar-jan committed Oct 4, 2024
1 parent 42f939a commit af012a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 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, share } from 'rxjs';
import { Observable, forkJoin, of } from 'rxjs';
import { Results } from './results';
import { GeoDocument, GeoLocation } from './search-results';
import { Params } from '@angular/router';
Expand All @@ -21,6 +21,8 @@ interface MapData {


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

constructor(
store: Store,
query: QueryModel,
Expand All @@ -37,15 +39,17 @@ export class MapDataResults extends Results<MapDataParameters, MapData> {
return of({ geoDocuments: [], mapCenter: null });
}

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

return forkJoin({
geoDocuments: this.visualizationService.getGeoData(
field.name,
this.query,
this.query.corpus
),
mapCenter: mapCenter$
mapCenter: getGeoCentroid$
});
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ export class ApiService {
return this.http.post<GeoDocument[]>(url, data);
}

public geoCentroid(data: {corpus: string, field: string}): Observable<GeoLocation> {
public geoCentroid(data: {corpus: string, field: string}): Promise<GeoLocation> {
const url = this.apiRoute(this.visApiURL, 'geo_centroid');
return this.http.post<GeoLocation>(url, data);
return this.http.post<GeoLocation>(url, data).toPromise();
}

public ngramTasks(data: NGramRequestParameters): Promise<TaskResult> {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/services/visualization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class VisualizationService {
});
}

public getGeoCentroid(fieldName: string, corpus: Corpus):
Observable<GeoLocation> {
public async getGeoCentroid(fieldName: string, corpus: Corpus):
Promise<GeoLocation> {
return this.apiService.geoCentroid({
corpus: corpus.name,
field: fieldName,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/visualization/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MapComponent implements OnChanges {

@Output() mapError = new EventEmitter();

mapCenter: GeoLocation;
mapCenter: GeoLocation | null;
results: GeoDocument[];

isLoading$ = new BehaviorSubject<boolean>(false);
Expand Down

0 comments on commit af012a4

Please sign in to comment.