Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 2788dba

Browse files
committed
feat(AgmMap): know when map is ready
You can now listen to the new mapReady output to know when the map is initialized. Closes #740 Closes #972
1 parent d23e2d7 commit 2788dba

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/core/directives/map.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {DataLayerManager} from './../services/managers/data-layer-manager';
5252
'scaleControl', 'scaleControlOptions', 'mapTypeId', 'clickableIcons', 'gestureHandling'
5353
],
5454
outputs: [
55-
'mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange', 'zoomChange'
55+
'mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange', 'zoomChange', 'mapReady'
5656
],
5757
host: {
5858
// todo: deprecated - we will remove it with the next version
@@ -314,6 +314,12 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
314314
*/
315315
zoomChange: EventEmitter<number> = new EventEmitter<number>();
316316

317+
/**
318+
* This event is fired when the google map is fully initialized.
319+
* You get the google.maps.Map instance as a result of this EventEmitter.
320+
*/
321+
mapReady: EventEmitter<any> = new EventEmitter<any>();
322+
317323
constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper) {}
318324

319325
/** @internal */
@@ -355,7 +361,9 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
355361
mapTypeId: this.mapTypeId,
356362
clickableIcons: this.clickableIcons,
357363
gestureHandling: this.gestureHandling
358-
});
364+
})
365+
.then(() => this._mapsWrapper.getNativeMap())
366+
.then(map => this.mapReady.emit(map));
359367

360368
// register event listeners
361369
this._handleMapCenterChange();

0 commit comments

Comments
 (0)