From ba78923d897c0e4a51b3c86b3db5926b61dc06a1 Mon Sep 17 00:00:00 2001 From: samuel-girard <32910196+samuel-girard@users.noreply.github.com> Date: Tue, 9 Oct 2018 08:56:45 +0200 Subject: [PATCH] feat(source): update params when input changes (TileWMS and ImageWMS) (#199) --- .../src/lib/sources/imagewms.component.ts | 10 ++++++++-- .../src/lib/sources/tilewms.component.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/projects/ngx-openlayers/src/lib/sources/imagewms.component.ts b/projects/ngx-openlayers/src/lib/sources/imagewms.component.ts index 3688e986..6b8e2aa8 100644 --- a/projects/ngx-openlayers/src/lib/sources/imagewms.component.ts +++ b/projects/ngx-openlayers/src/lib/sources/imagewms.component.ts @@ -1,4 +1,4 @@ -import { Component, Host, Input, OnInit, forwardRef } from '@angular/core'; +import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core'; import { AttributionLike, ImageLoadFunctionType, ProjectionLike, source } from 'openlayers'; import { LayerImageComponent } from '../layers/layerimage.component'; import { SourceComponent } from './source.component'; @@ -8,7 +8,7 @@ import { SourceComponent } from './source.component'; template: ``, providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageWMSComponent) }], }) -export class SourceImageWMSComponent extends SourceComponent implements OnInit { +export class SourceImageWMSComponent extends SourceComponent implements OnChanges, OnInit { instance: source.ImageWMS; @Input() @@ -42,4 +42,10 @@ export class SourceImageWMSComponent extends SourceComponent implements OnInit { this.instance = new source.ImageWMS(this); this.host.instance.setSource(this.instance); } + + ngOnChanges(changes: SimpleChanges) { + if (this.instance && changes.hasOwnProperty('params')) { + this.instance.updateParams(this.params); + } + } } diff --git a/projects/ngx-openlayers/src/lib/sources/tilewms.component.ts b/projects/ngx-openlayers/src/lib/sources/tilewms.component.ts index 0031d2e1..11ee5680 100644 --- a/projects/ngx-openlayers/src/lib/sources/tilewms.component.ts +++ b/projects/ngx-openlayers/src/lib/sources/tilewms.component.ts @@ -1,4 +1,4 @@ -import { Component, Host, Input, OnInit, forwardRef } from '@angular/core'; +import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core'; import { source, TileLoadFunctionType, tilegrid } from 'openlayers'; import { LayerTileComponent } from '../layers/layertile.component'; import { SourceComponent } from './source.component'; @@ -8,7 +8,7 @@ import { SourceComponent } from './source.component'; template: ``, providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMSComponent) }], }) -export class SourceTileWMSComponent extends SourceComponent implements OnInit { +export class SourceTileWMSComponent extends SourceComponent implements OnChanges, OnInit { instance: source.TileWMS; @Input() cacheSize: number; @@ -45,4 +45,10 @@ export class SourceTileWMSComponent extends SourceComponent implements OnInit { this.instance = new source.TileWMS(this); this.host.instance.setSource(this.instance); } + + ngOnChanges(changes: SimpleChanges) { + if (this.instance && changes.hasOwnProperty('params')) { + this.instance.updateParams(this.params); + } + } }