@@ -52,7 +52,7 @@ import {
52
52
isEqual ,
53
53
flatMapDeep ,
54
54
} from 'lodash' ;
55
- import { debounceTime , takeUntil } from 'rxjs' ;
55
+ import { BehaviorSubject , concatMap , debounceTime , takeUntil } from 'rxjs' ;
56
56
import { MapPopupService } from './map-popup/map-popup.service' ;
57
57
import { Platform } from '@angular/cdk/platform' ;
58
58
import { ContextService } from '../../../services/context/context.service' ;
@@ -152,6 +152,9 @@ export class MapComponent
152
152
private basemapTree : L . Control . Layers . TreeObject [ ] [ ] = [ ] ;
153
153
private overlaysTree : L . Control . Layers . TreeObject [ ] [ ] = [ ] ;
154
154
155
+ /** Refreshing layers. When true, should prevent layers to be duplicated */
156
+ private refreshingLayers = new BehaviorSubject < boolean > ( true ) ;
157
+
155
158
/**
156
159
* Map widget component
157
160
*
@@ -253,10 +256,27 @@ export class MapComponent
253
256
} ) ;
254
257
//}
255
258
} , 1000 ) ;
259
+ /**
260
+ * Keep checking until filters are applied in order to apply next one
261
+ */
262
+ const loadNextFilters = ( ) : Promise < void > => {
263
+ const checkAgain = ( resolve : ( ) => void ) => {
264
+ if ( this . refreshingLayers . getValue ( ) ) {
265
+ resolve ( ) ;
266
+ } else {
267
+ setTimeout ( ( ) => checkAgain ( resolve ) , 100 ) ;
268
+ }
269
+ } ;
270
+ return new Promise ( checkAgain ) ;
271
+ } ;
256
272
257
273
// Listen to dashboard filters changes
258
274
this . contextService . filter$
259
- . pipe ( debounceTime ( 500 ) , takeUntil ( this . destroy$ ) )
275
+ . pipe (
276
+ debounceTime ( 500 ) ,
277
+ concatMap ( ( ) => loadNextFilters ( ) ) ,
278
+ takeUntil ( this . destroy$ )
279
+ )
260
280
. subscribe ( ( ) => {
261
281
this . filterLayers ( ) ;
262
282
} ) ;
@@ -950,6 +970,7 @@ export class MapComponent
950
970
if ( isEqual ( filters , this . appliedDashboardFilters ) ) {
951
971
return ;
952
972
}
973
+ this . refreshingLayers . next ( false ) ;
953
974
this . appliedDashboardFilters = filters ;
954
975
const { layers : layersToGet , controls } = this . extractSettings ( ) ;
955
976
@@ -1000,6 +1021,8 @@ export class MapComponent
1000
1021
flatten ( this . overlaysTree )
1001
1022
) ;
1002
1023
}
1024
+
1025
+ this . refreshingLayers . next ( true ) ;
1003
1026
}
1004
1027
1005
1028
/**
0 commit comments