Skip to content

Commit 13a28c7

Browse files
Michael ParryNeonox31
authored andcommitted
feat(raster): not updated when source change
- re-instantiate raster when source change - add TileEvent(s) on XYZ and OSM - add wrapX to ArcGISRest - add example desciption
1 parent f4330af commit 13a28c7

File tree

7 files changed

+52
-35
lines changed

7 files changed

+52
-35
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class SourceImageArcGISRestComponent extends SourceComponent implements O
2222
@Input() ratio = 1;
2323
@Input() resolutions?: number[];
2424
@Input() logo?: string | olx.LogoOptions;
25+
@Input() wrapX?: boolean;
2526

2627
constructor(@Host() layer: LayerImageComponent) {
2728
super(layer);

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Host, forwardRef, Input, AfterContentInit, Optional } from '@angular/core';
1+
import { Component, Host, forwardRef, Input, AfterContentInit, Optional, Output, EventEmitter } from '@angular/core';
22
import { source, AttributionLike, TileLoadFunctionType } from 'openlayers';
33
import { LayerTileComponent } from '../layers/layertile.component';
44
import { SourceComponent } from './source.component';
@@ -34,6 +34,13 @@ export class SourceOsmComponent extends SourceXYZComponent implements AfterConte
3434
@Input()
3535
wrapX: boolean;
3636

37+
@Output()
38+
tileLoadStart: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
39+
@Output()
40+
tileLoadEnd: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
41+
@Output()
42+
tileLoadError: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
43+
3744
constructor(
3845
@Host()
3946
@Optional()
@@ -49,7 +56,13 @@ export class SourceOsmComponent extends SourceXYZComponent implements AfterConte
4956
if (this.tileGridXYZ) {
5057
this.tileGrid = this.tileGridXYZ.instance;
5158
}
59+
5260
this.instance = new source.OSM(this);
61+
62+
this.instance.on('tileloadstart', (event: source.TileEvent) => this.tileLoadStart.emit(event));
63+
this.instance.on('tileloadend', (event: source.TileEvent) => this.tileLoadEnd.emit(event));
64+
this.instance.on('tileloaderror', (event: source.TileEvent) => this.tileLoadError.emit(event));
65+
5366
this._register(this.instance);
5467
}
5568
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ export class SourceRasterComponent extends SourceComponent implements AfterConte
4040
}
4141

4242
ngAfterContentInit() {
43-
this.instance = new source.Raster(this);
43+
this.init();
44+
}
4445

46+
init() {
47+
this.instance = new source.Raster(this);
4548
this.instance.on('beforeoperations', (event: source.RasterEvent) => this.beforeOperations.emit(event));
4649
this.instance.on('afteroperations', (event: source.RasterEvent) => this.afterOperations.emit(event));
47-
4850
this._register(this.instance);
4951
}
5052
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class SourceComponent implements OnDestroy {
3030

3131
if (this.raster) {
3232
this.raster.sources = [s];
33+
this.raster.init();
3334
}
3435
}
3536
}

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
ContentChild,
99
SimpleChanges,
1010
Optional,
11+
Output,
12+
EventEmitter,
1113
} from '@angular/core';
1214
import { source, Size, TileUrlFunctionType, TileLoadFunctionType, tilegrid } from 'openlayers';
1315
import { LayerTileComponent } from '../layers/layertile.component';
@@ -58,6 +60,13 @@ export class SourceXYZComponent extends SourceComponent implements AfterContentI
5860
@ContentChild(TileGridComponent)
5961
tileGridXYZ: TileGridComponent;
6062

63+
@Output()
64+
tileLoadStart: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
65+
@Output()
66+
tileLoadEnd: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
67+
@Output()
68+
tileLoadError: EventEmitter<source.TileEvent> = new EventEmitter<source.TileEvent>();
69+
6170
constructor(
6271
@Optional()
6372
@Host()
@@ -73,8 +82,7 @@ export class SourceXYZComponent extends SourceComponent implements AfterContentI
7382
if (this.tileGridXYZ) {
7483
this.tileGrid = this.tileGridXYZ.instance;
7584
}
76-
this.instance = new source.XYZ(this);
77-
this._register(this.instance);
85+
this.init();
7886
}
7987

8088
ngOnChanges(changes: SimpleChanges) {
@@ -91,8 +99,17 @@ export class SourceXYZComponent extends SourceComponent implements AfterContentI
9199

92100
this.instance.setProperties(properties, false);
93101
if (changes.hasOwnProperty('url')) {
94-
this.instance = new source.XYZ(this);
95-
this._register(this.instance);
102+
this.init();
96103
}
97104
}
105+
106+
init() {
107+
this.instance = new source.XYZ(this);
108+
109+
this.instance.on('tileloadstart', (event: source.TileEvent) => this.tileLoadStart.emit(event));
110+
this.instance.on('tileloadend', (event: source.TileEvent) => this.tileLoadEnd.emit(event));
111+
this.instance.on('tileloaderror', (event: source.TileEvent) => this.tileLoadError.emit(event));
112+
113+
this._register(this.instance);
114+
}
98115
}

src/app/example-list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export const examplesList = [
7676
},
7777
{
7878
title: 'Raster',
79+
description:
80+
'Example of using raster to perform pixel-based operations. Adjust brightness and contrast in this case.',
7981
routerLink: 'raster',
8082
},
8183
{

src/app/raster/raster.component.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface RasterData {
99
@Component({
1010
selector: 'app-raster',
1111
template: `
12-
<aol-map [width]="'100%'" [height]="'100%'">
12+
<aol-map width="100%" height="100%">
1313
<aol-interaction-default></aol-interaction-default>
1414
<aol-control-defaults></aol-control-defaults>
1515
<aol-control-fullscreen></aol-control-fullscreen>
@@ -18,35 +18,20 @@ interface RasterData {
1818
<aol-coordinate [x]="1.4886" [y]="43.5554" [srid]="'EPSG:4326'"></aol-coordinate>
1919
</aol-view>
2020
21-
<aol-layer-image *ngIf="selectLayer === 'osm'">
21+
<aol-layer-image>
2222
<aol-source-raster
23-
#raster1
23+
threads="4"
24+
operationType="image"
2425
[operation]="operation"
25-
[threads]="threads"
2626
[lib]="lib"
27-
[operationType]="operationType"
2827
(beforeOperations)="beforeOperations($event)"
29-
(afterOperations)="afterOperations($event)"
30-
>
31-
<aol-source-osm></aol-source-osm>
32-
</aol-source-raster>
33-
</aol-layer-image>
34-
35-
<aol-layer-image *ngIf="selectLayer === 'xyz'">
36-
<aol-source-raster
37-
#raster2
38-
[operation]="operation"
39-
[threads]="threads"
40-
[lib]="lib"
41-
[operationType]="operationType"
42-
(beforeOperations)="beforeOperations($event)"
43-
(afterOperations)="afterOperations($event)"
4428
>
29+
<aol-source-osm *ngIf="selectLayer === 'osm'"></aol-source-osm>
4530
<aol-source-xyz
31+
*ngIf="selectLayer === 'xyz'"
4632
url="https://c.tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=0e6fc415256d4fbb9b5166a718591d71"
4733
crossOrigin=""
48-
>
49-
</aol-source-xyz>
34+
></aol-source-xyz>
5035
</aol-source-raster>
5136
</aol-layer-image>
5237
</aol-map>
@@ -94,8 +79,6 @@ interface RasterData {
9479
],
9580
})
9681
export class RasterComponent {
97-
threads = 4;
98-
operationType = 'image';
9982
lib: any = {
10083
brightness: brightness,
10184
contrast: contrast,
@@ -105,7 +88,7 @@ export class RasterComponent {
10588

10689
selectLayer = 'osm';
10790
@ViewChild(SourceRasterComponent)
108-
currentRasterSource;
91+
rasterSource;
10992

11093
beforeOperations(event) {
11194
const data: RasterData = event.data;
@@ -120,10 +103,8 @@ export class RasterComponent {
120103
return imageData;
121104
}
122105

123-
afterOperations() {}
124-
125106
updateRaster() {
126-
this.currentRasterSource.instance.changed();
107+
this.rasterSource.instance.refresh();
127108
}
128109
}
129110

0 commit comments

Comments
 (0)