Skip to content

Commit

Permalink
Fix tooltip in Treatment overview (#1909)
Browse files Browse the repository at this point in the history
* redo projarea id for tooltip
  • Loading branch information
lastminutediorama authored Nov 15, 2024
1 parent 71aa1a5 commit dcfbfd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<ng-container *ngIf="mouseLngLat">
<app-map-tooltip
[lngLat]="mouseLngLat"
*ngIf="activeProjectArea$ | async; let activeProjectArea">
*ngIf="hoveredProjectArea$ | async; let curProjectArea">
<mat-icon class="material-symbols-outlined">medication</mat-icon>
{{ getTreatedStandsTotal(activeProjectArea.prescriptions) }}
{{ getTreatedStandsTotal(curProjectArea.prescriptions) }}
/
{{ activeProjectArea.total_stand_count }}
{{ curProjectArea.total_stand_count }}
</app-map-tooltip>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import { AsyncPipe, NgIf } from '@angular/common';
import { MapTooltipComponent } from '../map-tooltip/map-tooltip.component';
import { BASE_COLORS, LABEL_PAINT } from '../map.styles';
import { getTreatedStandsTotal } from '../prescriptions';
import { TreatmentProjectArea } from '@types';
import {
combineLatest,
Observable,
distinctUntilChanged,
Subject,
map,
} from 'rxjs';

type MapLayerData = {
readonly name: string;
Expand Down Expand Up @@ -53,7 +61,18 @@ export class MapProjectAreasComponent implements OnInit {
fillColor: any;
getTreatedStandsTotal = getTreatedStandsTotal;

activeProjectArea$ = this.treatmentsState.activeProjectArea$;
hoveredProjectAreaId$ = new Subject<number>();
hoveredProjectArea$: Observable<TreatmentProjectArea | undefined> =
combineLatest([
this.summary$,
this.hoveredProjectAreaId$.pipe(distinctUntilChanged()),
]).pipe(
map(([summary, projectAreaId]) => {
return summary?.project_areas.find(
(p: TreatmentProjectArea) => p.project_area_id === projectAreaId
);
})
);

readonly tilesUrl =
environment.martin_server + 'project_areas_by_scenario/{z}/{x}/{y}';
Expand Down Expand Up @@ -123,10 +142,15 @@ export class MapProjectAreasComponent implements OnInit {
}

setProjectAreaTooltip(e: MapMouseEvent) {
// if I have a project area ID im transitioning to the project area view.
// if I have a project area ID im transitioning to the project area view,
// so we won't set a tooltip here
if (this.treatmentsState.getProjectAreaId()) {
return;
}
const hoveredProjectAreaId = this.getProjectAreaIdFromFeatures(e.point);
if (hoveredProjectAreaId) {
this.hoveredProjectAreaId$.next(hoveredProjectAreaId);
}
this.mouseLngLat = e.lngLat;
}

Expand Down

0 comments on commit dcfbfd5

Please sign in to comment.