Skip to content

Commit

Permalink
fix bug with selecting stands on direct impacts map (#2060)
Browse files Browse the repository at this point in the history
  • Loading branch information
pflopez authored Jan 6, 2025
1 parent 7eeacba commit 38b1bc6
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { SINGLE_STAND_SELECTED, STANDS_CELL_PAINT } from '../map.styles';
import { environment } from '../../../environments/environment';
import { DEFAULT_SLOT, ImpactsMetricSlot, SLOT_PALETTES } from '../metrics';
import { map } from 'rxjs';
import { map, switchMap, take } from 'rxjs';
import { DirectImpactsStateService } from '../direct-impacts.state.service';
import { TreatmentsState } from '../treatments.state';
import { filter } from 'rxjs/operators';
Expand Down Expand Up @@ -85,10 +85,7 @@ export class MapStandsTxResultComponent implements OnInit {
map((stand) => stand.id)
);

private point: Point | null = null;

setActiveStand(event: MapMouseEvent) {
this.point = event.point;
this.setActiveStandFromPoint(event.point);
this.hideTooltip();
}
Expand All @@ -103,10 +100,22 @@ export class MapStandsTxResultComponent implements OnInit {
ngOnInit(): void {
this.paint = this.generatePaint(DEFAULT_SLOT);
this.directImpactsStateService.standsTxSourceLoaded$
.pipe(untilDestroyed(this))
.subscribe(() => {
if (this.point) {
this.setActiveStandFromPoint(this.point);
.pipe(
untilDestroyed(this),
switchMap((s) => this.activeStandId$.pipe(take(1)))
)
.subscribe((standId) => {
if (standId) {
const sourceFeatures = this.mapLibreMap.querySourceFeatures(
'stands_by_tx_result',
{
sourceLayer: 'stands_by_tx_result',
filter: ['==', ['get', 'id'], standId], // Filter for the specific stand ID
}
);
if (sourceFeatures[0]) {
this.directImpactsStateService.setActiveStand(sourceFeatures[0]);
}
}
});
}
Expand Down

0 comments on commit 38b1bc6

Please sign in to comment.