diff --git a/src/google-maps/google-map/google-map.spec.ts b/src/google-maps/google-map/google-map.spec.ts index 0472272c217a..5eea53ede1c3 100644 --- a/src/google-maps/google-map/google-map.spec.ts +++ b/src/google-maps/google-map/google-map.spec.ts @@ -363,6 +363,18 @@ describe('GoogleMap', () => { expect(mapConstructorSpy.calls.mostRecent()?.args[1].mapTypeId).toBe('satellite'); }); + it('should emit mapInitialized event when the map is initialized', () => { + mapSpy = createMapSpy(DEFAULT_OPTIONS); + mapConstructorSpy = createMapConstructorSpy(mapSpy); + + const fixture = TestBed.createComponent(TestApp); + fixture.detectChanges(); + + expect(fixture.componentInstance.mapInitializedSpy).toHaveBeenCalledOnceWith( + fixture.componentInstance.map.googleMap, + ); + }); + it('should emit authFailure event when window.gm_authFailure is called', () => { mapSpy = createMapSpy(DEFAULT_OPTIONS); mapConstructorSpy = createMapConstructorSpy(mapSpy); @@ -397,7 +409,8 @@ describe('GoogleMap', () => { [mapTypeId]="mapTypeId" (mapClick)="handleClick($event)" (centerChanged)="handleCenterChanged()" - (mapRightclick)="handleRightclick($event)"> + (mapRightclick)="handleRightclick($event)" + (mapInitialized)="mapInitializedSpy($event)"> `, }) class TestApp { @@ -412,4 +425,5 @@ class TestApp { handleClick(event: google.maps.MapMouseEvent) {} handleCenterChanged() {} handleRightclick(event: google.maps.MapMouseEvent) {} + mapInitializedSpy = jasmine.createSpy('mapInitialized'); } diff --git a/src/google-maps/google-map/google-map.ts b/src/google-maps/google-map/google-map.ts index 5bfbf7f55020..1014fe7be4df 100644 --- a/src/google-maps/google-map/google-map.ts +++ b/src/google-maps/google-map/google-map.ts @@ -104,6 +104,10 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { } private _options = DEFAULT_OPTIONS; + /** Event emitted when the map is initialized. */ + @Output() readonly mapInitialized: EventEmitter = + new EventEmitter(); + /** * See * https://developers.google.com/maps/documentation/javascript/events#auth-errors @@ -305,6 +309,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { this.googleMap = new google.maps.Map(this._mapEl, this._combineOptions()); }); this._eventManager.setTarget(this.googleMap); + this.mapInitialized.emit(this.googleMap); } } diff --git a/tools/public_api_guard/google-maps/google-maps.md b/tools/public_api_guard/google-maps/google-maps.md index 2147c7593a0e..a58e189075c3 100644 --- a/tools/public_api_guard/google-maps/google-maps.md +++ b/tools/public_api_guard/google-maps/google-maps.md @@ -65,6 +65,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { readonly mapDrag: Observable; readonly mapDragend: Observable; readonly mapDragstart: Observable; + readonly mapInitialized: EventEmitter; readonly mapMousemove: Observable; readonly mapMouseout: Observable; readonly mapMouseover: Observable; @@ -92,7 +93,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { set zoom(zoom: number); readonly zoomChanged: Observable; // (undocumented) - static ɵcmp: i0.ɵɵComponentDeclaration; + static ɵcmp: i0.ɵɵComponentDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; }