Skip to content

Commit

Permalink
fix(journey-maps): allow deselecting pois even without popups
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Dickinson <“christopher.dickinson@sbb.ch”>
  • Loading branch information
2 people authored and github-actions committed Aug 10, 2023
1 parent 8f9fc9e commit 5986080
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
Expand All @@ -15,7 +14,6 @@ import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import {
SbbDeselectableFeatureDataType,
SbbFeatureData,
SbbFeatureDataType,
SbbFeaturesClickEventData,
Expand Down Expand Up @@ -44,11 +42,10 @@ import { SBB_ZONE_LAYER } from '../../services/map/map-zone-service';
providers: [SbbMapSelectionEvent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SbbFeatureEventListener implements OnChanges, OnDestroy, OnInit {
export class SbbFeatureEventListener implements OnChanges, OnDestroy {
@Input() listenerOptions: SbbListenerOptions;
@Input() map: MapLibreMap | null;
@Input() poiOptions?: SbbPointsOfInterestOptions;
@Input() onFeaturesUnselect: Subject<SbbDeselectableFeatureDataType[]>;

@Output() featureSelectionsChange: EventEmitter<SbbFeaturesSelectEventData> =
new EventEmitter<SbbFeaturesSelectEventData>();
Expand Down Expand Up @@ -84,12 +81,6 @@ export class SbbFeatureEventListener implements OnChanges, OnDestroy, OnInit {
readonly mapSelectionEventService: SbbMapSelectionEvent,
) {}

ngOnInit(): void {
this.onFeaturesUnselect.pipe(takeUntil(this._destroyed)).subscribe((types) => {
this.unselectFeaturesOfType(types);
});
}

ngOnDestroy(): void {
this._destroyed.next();
this._destroyed.complete();
Expand Down Expand Up @@ -338,24 +329,4 @@ export class SbbFeatureEventListener implements OnChanges, OnDestroy, OnInit {
this.featureSelectionsChange.next(this.mapSelectionEventService.findSelectedFeatures());
}
}

// only used for POI-features at the moment
unselectFeaturesOfType(types: SbbDeselectableFeatureDataType[]) {
const selectedFeaturesOfTypes = this.overlayFeatures.filter((feature) =>
types.some((type) => feature.featureDataType === type),
);

if (selectedFeaturesOfTypes.length > 0) {
// unselect given features
this.overlayVisible = false;
this.mapSelectionEventService.toggleSelection(selectedFeaturesOfTypes);
this.featureSelectionsChange.next({ features: [] });

// remove unselected features from list
this.overlayFeatures = this.overlayFeatures.filter((feature) =>
types.some((type) => feature.featureDataType !== type),
);
this._cd.detectChanges();
}
}
}
1 change: 0 additions & 1 deletion src/journey-maps/angular/journey-maps.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
(featuresHoverChange)="featuresHoverChange.next($event)"
(featuresClick)="featuresClick.next($event); handleMarkerOrClusterClick($event.features)"
(featureSelectionsChange)="selectedFeaturesChange.next($event)"
[onFeaturesUnselect]="onFeaturesUnselectEvent"
></sbb-feature-event-listener>
<sbb-marker-details
[selectedMarker]="selectedMarker"
Expand Down
6 changes: 2 additions & 4 deletions src/journey-maps/angular/journey-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ export class SbbJourneyMaps implements OnInit, AfterViewInit, OnDestroy, OnChang
this._map?.zoomOut();
}

onFeaturesUnselectEvent: Subject<SbbDeselectableFeatureDataType[]> = new Subject();

/**
* Unselects all elements on the map that are of one of the `SbbFeatureDataType`s passed in as a parameter.
* Currently, we only support 'MARKER' and 'POI'.
Expand All @@ -465,15 +463,15 @@ export class SbbJourneyMaps implements OnInit, AfterViewInit, OnDestroy, OnChang
}
// unselect pois
if (types.includes('POI')) {
this.onFeaturesUnselectEvent.next(['POI']);
this._unselectPoi();
}
}

/**
* Programmatically select a POI by providing the SBB-ID of the POI.
* Only works for POIs that are currently visible in the map's viewport.
*/
setSelectedPoi(sbbId: string) {
setSelectedPoi(sbbId: string | undefined) {
if (!!sbbId) {
this._selectOrDeselectPoi(sbbId, true);
} else {
Expand Down

0 comments on commit 5986080

Please sign in to comment.