Skip to content

Commit

Permalink
feat(AgmMap): know when map is ready
Browse files Browse the repository at this point in the history
You can now listen to the new mapReady output
to know when the map is initialized.

Closes #740
Closes #972
  • Loading branch information
sebholstein committed Apr 9, 2017
1 parent d23e2d7 commit 2788dba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {DataLayerManager} from './../services/managers/data-layer-manager';
'scaleControl', 'scaleControlOptions', 'mapTypeId', 'clickableIcons', 'gestureHandling'
],
outputs: [
'mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange', 'zoomChange'
'mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange', 'zoomChange', 'mapReady'
],
host: {
// todo: deprecated - we will remove it with the next version
Expand Down Expand Up @@ -314,6 +314,12 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
*/
zoomChange: EventEmitter<number> = new EventEmitter<number>();

/**
* This event is fired when the google map is fully initialized.
* You get the google.maps.Map instance as a result of this EventEmitter.
*/
mapReady: EventEmitter<any> = new EventEmitter<any>();

constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper) {}

/** @internal */
Expand Down Expand Up @@ -355,7 +361,9 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
mapTypeId: this.mapTypeId,
clickableIcons: this.clickableIcons,
gestureHandling: this.gestureHandling
});
})
.then(() => this._mapsWrapper.getNativeMap())
.then(map => this.mapReady.emit(map));

// register event listeners
this._handleMapCenterChange();
Expand Down

0 comments on commit 2788dba

Please sign in to comment.