Skip to content

Commit ba78923

Browse files
samuel-girardNeonox31
authored andcommitted
feat(source): update params when input changes (TileWMS and ImageWMS) (#199)
1 parent 8bfd7b2 commit ba78923

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

projects/ngx-openlayers/src/lib/sources/imagewms.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
1+
import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core';
22
import { AttributionLike, ImageLoadFunctionType, ProjectionLike, source } from 'openlayers';
33
import { LayerImageComponent } from '../layers/layerimage.component';
44
import { SourceComponent } from './source.component';
@@ -8,7 +8,7 @@ import { SourceComponent } from './source.component';
88
template: `<ng-content></ng-content>`,
99
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageWMSComponent) }],
1010
})
11-
export class SourceImageWMSComponent extends SourceComponent implements OnInit {
11+
export class SourceImageWMSComponent extends SourceComponent implements OnChanges, OnInit {
1212
instance: source.ImageWMS;
1313

1414
@Input()
@@ -42,4 +42,10 @@ export class SourceImageWMSComponent extends SourceComponent implements OnInit {
4242
this.instance = new source.ImageWMS(this);
4343
this.host.instance.setSource(this.instance);
4444
}
45+
46+
ngOnChanges(changes: SimpleChanges) {
47+
if (this.instance && changes.hasOwnProperty('params')) {
48+
this.instance.updateParams(this.params);
49+
}
50+
}
4551
}

projects/ngx-openlayers/src/lib/sources/tilewms.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
1+
import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core';
22
import { source, TileLoadFunctionType, tilegrid } from 'openlayers';
33
import { LayerTileComponent } from '../layers/layertile.component';
44
import { SourceComponent } from './source.component';
@@ -8,7 +8,7 @@ import { SourceComponent } from './source.component';
88
template: `<ng-content></ng-content>`,
99
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMSComponent) }],
1010
})
11-
export class SourceTileWMSComponent extends SourceComponent implements OnInit {
11+
export class SourceTileWMSComponent extends SourceComponent implements OnChanges, OnInit {
1212
instance: source.TileWMS;
1313
@Input()
1414
cacheSize: number;
@@ -45,4 +45,10 @@ export class SourceTileWMSComponent extends SourceComponent implements OnInit {
4545
this.instance = new source.TileWMS(this);
4646
this.host.instance.setSource(this.instance);
4747
}
48+
49+
ngOnChanges(changes: SimpleChanges) {
50+
if (this.instance && changes.hasOwnProperty('params')) {
51+
this.instance.updateParams(this.params);
52+
}
53+
}
4854
}

0 commit comments

Comments
 (0)