Skip to content

Commit

Permalink
feat(context): choose to remove or not all layers on context change (#…
Browse files Browse the repository at this point in the history
…406)

* feat(context): choose to remove or not all layers on context change

* Update layer-context.directive.ts

* package
  • Loading branch information
PhilippeLafreniere18 authored and mbarbeau committed Sep 11, 2019
1 parent 2a8ca55 commit 8b2929e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface DetailedContext extends Context {
layers?: LayerOptions[];
tools?: Tool[];
toolbar?: string[];
removeLayersOnContextChange?: boolean;
}

export interface ContextMapView extends MapViewOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, OnInit, OnDestroy, Optional } from '@angular/core';
import { Directive, OnInit, OnDestroy, Optional, Input } from '@angular/core';

import { Subscription, of, zip } from 'rxjs';
import { withLatestFrom, skip, filter } from 'rxjs/operators';
Expand All @@ -25,6 +25,8 @@ export class LayerContextDirective implements OnInit, OnDestroy {

private contextLayers: Layer[] = [];

@Input() removeLayersOnContextChange: boolean = true;

get map(): IgoMap {
return this.component.map;
}
Expand Down Expand Up @@ -62,8 +64,11 @@ export class LayerContextDirective implements OnInit, OnDestroy {

private handleContextChange(context: DetailedContext) {
if (context.layers === undefined) { return; }

this.map.removeLayers(this.contextLayers);
if (this.removeLayersOnContextChange === true) {
this.map.removeAllLayers();
} else {
this.map.removeLayers(this.contextLayers);
}
this.contextLayers = [];

const layersAndIndex$ = zip(...context.layers.map((layerOptions: LayerOptions, index: number) => {
Expand Down

0 comments on commit 8b2929e

Please sign in to comment.