Skip to content

Commit

Permalink
fix(map-swipe): Swipe properties of layers not updating with layerMan…
Browse files Browse the repository at this point in the history
…agerUpdates when mapSwipe panel is active

closes #5332
  • Loading branch information
FilipLeitner committed Oct 14, 2024
1 parent cf1b8d6 commit ffb57ea
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions projects/hslayers/components/map-swipe/map-swipe.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Injectable, NgZone} from '@angular/core';
import {buffer, filter, first, map} from 'rxjs';
import {Observable, merge} from 'rxjs';
import {buffer, filter, first, map, switchMap, take} from 'rxjs/operators';

import {Layer} from 'ol/layer';
import {Source} from 'ol/source';
Expand Down Expand Up @@ -78,18 +79,28 @@ export class HsMapSwipeService {
}
});

this.hsEventBusService.layerManagerUpdates
//Stream used to update layers while mapSwipe panel is active
const isMapSwipe$ = this.getLayerUpdateWithCurrentPanel().pipe(
filter(({panel}) => panel === 'mapSwipe'),
map(({layer}) => [layer]),
);
//Stream used to update layers while mapSwipe panel is not active
const isNotMapSwipe$ = this.getLayerUpdateWithCurrentPanel().pipe(
filter(({panel}) => panel !== 'mapSwipe'),
map(({layer}) => layer),
//buffer layerManagerUpdates until mapSwipe panel is opened
buffer(
this.hsLayoutService.mainpanel$.pipe(filter((p) => p === 'mapSwipe')),
),
);

merge(isMapSwipe$, isNotMapSwipe$)
.pipe(
//Buffer layerManagerUpdates until mapSwipe panel is opened
buffer(
this.hsLayoutService.mainpanel$.pipe(filter((p) => p === 'mapSwipe')),
),
//Do not accept empty array
filter((layers) => layers.length > 0),
filter((layers) => layers?.length > 0),
map((layers) => this.removeDuplicateUpdates(layers as Layer<Source>[])),
)
.subscribe((filteredLayers) => {
this.fillSwipeLayers(filteredLayers);
.subscribe((layers) => {
this.fillSwipeLayers(layers);
});

this.hsLayerEditorService.layerTitleChange.subscribe(({layer}) => {
Expand All @@ -100,6 +111,25 @@ export class HsMapSwipeService {
});
}

/**
* Get layer manager update along with the current mainPanel
*/
private getLayerUpdateWithCurrentPanel(): Observable<{
layer: Layer<Source>;
panel: string;
}> {
return this.hsEventBusService.layerManagerUpdates.pipe(
//filter out nulls
filter((layer): layer is Layer<Source> => !!layer),
switchMap((layer) =>
this.hsLayoutService.mainpanel$.pipe(
take(1),
map((panel) => ({layer, panel})),
),
),
);
}

/**
* Remove duplicate layerManagerUpdates to get one update per layer
*/
Expand Down

0 comments on commit ffb57ea

Please sign in to comment.