diff --git a/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts b/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts index 9d7369645d..5c079c93c3 100644 --- a/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts +++ b/packages/geo/src/lib/search/shared/search-pointer-summary.directive.ts @@ -52,6 +52,7 @@ export class SearchPointerSummaryDirective implements OnInit, OnDestroy, AfterCo private pointerSearchStore: EntityStore = new EntityStore([]); private lastTimeoutRequest; private store$$: Subscription; + private layers$$: Subscription; private reverseSearch$$: Subscription[] = []; private hasPointerReverseSearchSource: boolean = false; @@ -108,6 +109,14 @@ export class SearchPointerSummaryDirective implements OnInit, OnDestroy, AfterCo this.store = new FeatureStore([], {map: this.map}); this.initStore(); }); + + // To handle context change without using the contextService. + this.layers$$ = this.map.layers$.subscribe((layers) => { + if (this.store && !layers.find(l => l.id === 'searchPointerSummaryId')) { + this.initStore(); + } + }); + } /** @@ -118,6 +127,7 @@ export class SearchPointerSummaryDirective implements OnInit, OnDestroy, AfterCo const store = this.store; const layer = new VectorLayer({ + id : 'searchPointerSummaryId', title: 'searchPointerSummary', zIndex: 900, source: new FeatureDataSource(), @@ -145,6 +155,7 @@ export class SearchPointerSummaryDirective implements OnInit, OnDestroy, AfterCo this.unlistenToMapPointerMove(); this.unsubscribeToPointerStore(); this.unsubscribeReverseSearch(); + this.layers$$.unsubscribe(); } /**