Skip to content

Commit fc856b3

Browse files
Elodie TasiaNeonox31
authored andcommitted
feat(image): add image loading events
1 parent 41448f9 commit fc856b3

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
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, OnInit, forwardRef, Output, EventEmitter } from '@angular/core';
22
import { ProjectionLike, source, Extent, AttributionLike, ImageLoadFunctionType, Size } from 'openlayers';
33
import { SourceComponent } from './source.component';
44
import { LayerImageComponent } from '../layers/layerimage.component';
@@ -30,12 +30,22 @@ export class SourceImageStaticComponent extends SourceComponent implements OnIni
3030
@Input()
3131
imageSize?: Size;
3232

33+
@Output()
34+
onImageLoadStart = new EventEmitter<source.ImageEvent>();
35+
@Output()
36+
onImageLoadEnd = new EventEmitter<source.ImageEvent>();
37+
@Output()
38+
onImageLoadError = new EventEmitter<source.ImageEvent>();
39+
3340
constructor(@Host() layer: LayerImageComponent) {
3441
super(layer);
3542
}
3643

3744
ngOnInit() {
3845
this.instance = new source.ImageStatic(this);
3946
this.host.instance.setSource(this.instance);
47+
this.instance.on('imageloadstart', (event: source.ImageEvent) => this.onImageLoadStart.emit(event));
48+
this.instance.on('imageloadend', (event: source.ImageEvent) => this.onImageLoadEnd.emit(event));
49+
this.instance.on('imageloaderror', (event: source.ImageEvent) => this.onImageLoadError.emit(event));
4050
}
4151
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core';
1+
import {
2+
Component,
3+
Host,
4+
Input,
5+
OnChanges,
6+
OnInit,
7+
forwardRef,
8+
SimpleChanges,
9+
Output,
10+
EventEmitter,
11+
} from '@angular/core';
212
import { AttributionLike, ImageLoadFunctionType, ProjectionLike, source } from 'openlayers';
313
import { LayerImageComponent } from '../layers/layerimage.component';
414
import { SourceComponent } from './source.component';
@@ -36,13 +46,23 @@ export class SourceImageWMSComponent extends SourceComponent implements OnChange
3646
@Input()
3747
url: string;
3848

49+
@Output()
50+
onImageLoadStart = new EventEmitter<source.ImageEvent>();
51+
@Output()
52+
onImageLoadEnd = new EventEmitter<source.ImageEvent>();
53+
@Output()
54+
onImageLoadError = new EventEmitter<source.ImageEvent>();
55+
3956
constructor(@Host() layer: LayerImageComponent) {
4057
super(layer);
4158
}
4259

4360
ngOnInit() {
4461
this.instance = new source.ImageWMS(this);
4562
this.host.instance.setSource(this.instance);
63+
this.instance.on('imageloadstart', (event: source.ImageEvent) => this.onImageLoadStart.emit(event));
64+
this.instance.on('imageloadend', (event: source.ImageEvent) => this.onImageLoadEnd.emit(event));
65+
this.instance.on('imageloaderror', (event: source.ImageEvent) => this.onImageLoadError.emit(event));
4666
}
4767

4868
ngOnChanges(changes: SimpleChanges) {

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { OverlayComponent } from './overlay/overlay.component';
2424
import { ColorSelectHoverComponent } from './color-select-hover/color-select-hover.component';
2525
import { MarkerComponent } from './marker/marker.component';
2626
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
27+
import { ImageWMSComponent } from './image-wms/image-wms.component';
2728

2829
@NgModule({
2930
declarations: [
@@ -45,6 +46,7 @@ import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
4546
ColorSelectHoverComponent,
4647
MarkerComponent,
4748
ArcgisImageComponent,
49+
ImageWMSComponent,
4850
],
4951
imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule],
5052
providers: [],

src/app/app.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { OverlayComponent } from './overlay/overlay.component';
1717
import { ColorSelectHoverComponent } from './color-select-hover/color-select-hover.component';
1818
import { MarkerComponent } from './marker/marker.component';
1919
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
20+
import { ImageWMSComponent } from './image-wms/image-wms.component';
2021

2122
const routes: Routes = [
2223
{ path: '', component: ExamplesListComponent },
@@ -39,6 +40,7 @@ const routes: Routes = [
3940
{ path: 'cluster', component: ClusterComponent },
4041
{ path: 'raster', component: RasterComponent },
4142
{ path: 'arcgis-image', component: ArcgisImageComponent },
43+
{ path: 'image-wms', component: ImageWMSComponent },
4244
],
4345
},
4446
{ path: '**', redirectTo: '' },

src/app/example-list.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@ export const examplesList = [
8585
routerLink: 'arcgis-image',
8686
openLayersLink: 'https://openlayers.org/en/latest/examples/arcgis-image.html',
8787
},
88+
{
89+
title: 'Image Load Events',
90+
description: 'Example of using aol-source-imagewms. This example listens to image loading events.',
91+
routerLink: 'image-wms',
92+
openLayersLink: 'https://openlayers.org/en/latest/examples/image-load-events.html',
93+
},
8894
];
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
template: `
6+
<aol-map #map width="100%" height="100%">
7+
<aol-interaction-default></aol-interaction-default>
8+
<aol-view zoom="4"> <aol-coordinate [x]="-10997148" [y]="4569099"></aol-coordinate> </aol-view>
9+
<aol-layer-image>
10+
<aol-source-imagewms
11+
[url]="'https://ahocevar.com/geoserver/wms'"
12+
[params]="params"
13+
[serverType]="'geoserver'"
14+
(onImageLoadStart)="onImageLoadStart()"
15+
(onImageLoadEnd)="onImageLoadEnd()"
16+
></aol-source-imagewms>
17+
</aol-layer-image>
18+
</aol-map>
19+
`,
20+
styles: [
21+
`
22+
map {
23+
background: #e0eced;
24+
}
25+
`,
26+
],
27+
})
28+
export class ImageWMSComponent implements OnInit {
29+
constructor() {}
30+
31+
params = { LAYERS: 'topp:states' };
32+
33+
ngOnInit() {}
34+
35+
onImageLoadStart() {
36+
console.log('image starts loading at: ' + new Date());
37+
}
38+
39+
onImageLoadEnd() {
40+
console.log('image ends loading at: ' + new Date());
41+
}
42+
}

0 commit comments

Comments
 (0)