Skip to content

Commit 5269e0f

Browse files
committed
fix(google-maps): mapId not being set
Fixes that the `mapId` input wasn't being passed along to the map. Fixes #28608.
1 parent d1d1d02 commit 5269e0f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/google-maps/google-map/google-map.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ describe('GoogleMap', () => {
5252
const container = fixture.debugElement.query(By.css('div'))!;
5353
expect(container.nativeElement.style.height).toBe(DEFAULT_HEIGHT);
5454
expect(container.nativeElement.style.width).toBe(DEFAULT_WIDTH);
55-
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
55+
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
56+
...DEFAULT_OPTIONS,
57+
mapId: undefined,
58+
});
5659
});
5760

5861
it('sets height and width of the map', () => {
@@ -67,7 +70,10 @@ describe('GoogleMap', () => {
6770
const container = fixture.debugElement.query(By.css('div'))!;
6871
expect(container.nativeElement.style.height).toBe('750px');
6972
expect(container.nativeElement.style.width).toBe('400px');
70-
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
73+
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
74+
...DEFAULT_OPTIONS,
75+
mapId: undefined,
76+
});
7177

7278
fixture.componentInstance.height = '650px';
7379
fixture.componentInstance.width = '350px';
@@ -118,6 +124,7 @@ describe('GoogleMap', () => {
118124
center: {lat: 3, lng: 5},
119125
zoom: 7,
120126
mapTypeId: DEFAULT_OPTIONS.mapTypeId,
127+
mapId: undefined,
121128
};
122129
mapSpy = createMapSpy(options);
123130
mapConstructorSpy = createMapConstructorSpy(mapSpy);
@@ -344,6 +351,20 @@ describe('GoogleMap', () => {
344351
expect(mapSpy.setMapTypeId).toHaveBeenCalledWith('roadmap');
345352
});
346353

354+
it('should set the map ID', () => {
355+
mapSpy = createMapSpy(DEFAULT_OPTIONS);
356+
mapConstructorSpy = createMapConstructorSpy(mapSpy);
357+
358+
const fixture = TestBed.createComponent(TestApp);
359+
fixture.componentInstance.mapId = '123';
360+
fixture.detectChanges();
361+
362+
expect(mapConstructorSpy).toHaveBeenCalledWith(
363+
jasmine.any(HTMLElement),
364+
jasmine.objectContaining({mapId: '123'}),
365+
);
366+
});
367+
347368
it('sets mapTypeId through the options', () => {
348369
const options = {mapTypeId: 'satellite'};
349370
mapSpy = createMapSpy(options);
@@ -401,6 +422,7 @@ describe('GoogleMap', () => {
401422
[zoom]="zoom"
402423
[options]="options"
403424
[mapTypeId]="mapTypeId"
425+
[mapId]="mapId"
404426
(mapClick)="handleClick($event)"
405427
(centerChanged)="handleCenterChanged()"
406428
(mapRightclick)="handleRightclick($event)"
@@ -417,6 +439,7 @@ class TestApp {
417439
zoom?: number;
418440
options?: google.maps.MapOptions;
419441
mapTypeId?: google.maps.MapTypeId;
442+
mapId?: string;
420443

421444
handleClick(event: google.maps.MapMouseEvent) {}
422445
handleCenterChanged() {}

src/google-maps/google-map/google-map.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
531531
// Passing in an undefined `mapTypeId` seems to break tile loading
532532
// so make sure that we have some kind of default (see #22082).
533533
mapTypeId: this.mapTypeId || options.mapTypeId || DEFAULT_OPTIONS.mapTypeId,
534+
mapId: this.mapId || options.mapId,
534535
};
535536
}
536537

0 commit comments

Comments
 (0)