Skip to content

Commit 32c4557

Browse files
author
Wykks
committed
fix(image): add a loaded event
1 parent ebc2fe9 commit 32c4557

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/app/demo/examples/add-image.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { Component } from '@angular/core';
88
<mgl-image
99
id="cat"
1010
url="https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/400px-Cat_silhouette.svg.png"
11+
(loaded)="imageLoaded = true"
1112
>
1213
</mgl-image>
1314
<mgl-layer
15+
*ngIf="imageLoaded"
1416
id="points"
1517
type="symbol"
1618
[source]="{

src/app/lib/image/image.component.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core';
1+
import {
2+
Component,
3+
EventEmitter,
4+
Input,
5+
NgZone,
6+
OnChanges,
7+
OnDestroy,
8+
OnInit,
9+
Output,
10+
SimpleChanges
11+
} from '@angular/core';
212
import { MapService } from '../map/map.service';
3-
import { MapImageOptions, MapImageData } from '../map/map.types';
13+
import { MapImageData, MapImageOptions } from '../map/map.types';
414

515
@Component({
616
selector: 'mgl-image',
@@ -16,11 +26,13 @@ export class ImageComponent implements OnInit, OnDestroy, OnChanges {
1626
@Input() url?: string;
1727

1828
@Output() error = new EventEmitter<{ status: number }>();
29+
@Output() loaded = new EventEmitter<void>();
1930

2031
private imageAdded = false;
2132

2233
constructor(
23-
private MapService: MapService
34+
private MapService: MapService,
35+
private zone: NgZone
2436
) { }
2537

2638
ngOnInit() {
@@ -40,8 +52,13 @@ export class ImageComponent implements OnInit, OnDestroy, OnChanges {
4052
this.options
4153
);
4254
this.imageAdded = true;
55+
this.zone.run(() => {
56+
this.loaded.emit();
57+
});
4358
} catch (error) {
44-
this.error.emit(error);
59+
this.zone.run(() => {
60+
this.error.emit(error);
61+
});
4562
}
4663
}
4764
});

0 commit comments

Comments
 (0)