Skip to content

Commit

Permalink
fix(image): add a loaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
Wykks committed Dec 18, 2017
1 parent ebc2fe9 commit 32c4557
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/app/demo/examples/add-image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { Component } from '@angular/core';
<mgl-image
id="cat"
url="https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/400px-Cat_silhouette.svg.png"
(loaded)="imageLoaded = true"
>
</mgl-image>
<mgl-layer
*ngIf="imageLoaded"
id="points"
type="symbol"
[source]="{
Expand Down
25 changes: 21 additions & 4 deletions src/app/lib/image/image.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core';
import {
Component,
EventEmitter,
Input,
NgZone,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges
} from '@angular/core';
import { MapService } from '../map/map.service';
import { MapImageOptions, MapImageData } from '../map/map.types';
import { MapImageData, MapImageOptions } from '../map/map.types';

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

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

private imageAdded = false;

constructor(
private MapService: MapService
private MapService: MapService,
private zone: NgZone
) { }

ngOnInit() {
Expand All @@ -40,8 +52,13 @@ export class ImageComponent implements OnInit, OnDestroy, OnChanges {
this.options
);
this.imageAdded = true;
this.zone.run(() => {
this.loaded.emit();
});
} catch (error) {
this.error.emit(error);
this.zone.run(() => {
this.error.emit(error);
});
}
}
});
Expand Down

0 comments on commit 32c4557

Please sign in to comment.