Skip to content

Commit

Permalink
feat(source): update params when input changes (TileWMS and ImageWMS) (
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-girard authored and Neonox31 committed Oct 9, 2018
1 parent 8bfd7b2 commit ba78923
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions projects/ngx-openlayers/src/lib/sources/imagewms.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,7 +8,7 @@ import { SourceComponent } from './source.component';
template: `<ng-content></ng-content>`,
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()
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 8 additions & 2 deletions projects/ngx-openlayers/src/lib/sources/tilewms.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,7 +8,7 @@ import { SourceComponent } from './source.component';
template: `<ng-content></ng-content>`,
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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit ba78923

Please sign in to comment.