Skip to content

Commit 7c9b83a

Browse files
authored
fix(google-maps): ensure that a mapTypeId is always passed in (#22098)
We pass in `mapTypeId` as undefined if the provided options don't have it. This seems to trigger a bug in Google Maps where it stops loading map tiles. These changes fix the issue by always providing a `mapTypeId`. Fixes #22082.
1 parent ba6efbf commit 7c9b83a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ describe('GoogleMap', () => {
6363
const container = fixture.debugElement.query(By.css('div'))!;
6464
expect(container.nativeElement.style.height).toBe(DEFAULT_HEIGHT);
6565
expect(container.nativeElement.style.width).toBe(DEFAULT_WIDTH);
66-
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
67-
...DEFAULT_OPTIONS,
68-
mapTypeId: undefined
69-
});
66+
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
7067
});
7168

7269
it('sets height and width of the map', () => {
@@ -81,10 +78,7 @@ describe('GoogleMap', () => {
8178
const container = fixture.debugElement.query(By.css('div'))!;
8279
expect(container.nativeElement.style.height).toBe('750px');
8380
expect(container.nativeElement.style.width).toBe('400px');
84-
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
85-
...DEFAULT_OPTIONS,
86-
mapTypeId: undefined
87-
});
81+
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
8882

8983
fixture.componentInstance.height = '650px';
9084
fixture.componentInstance.width = '350px';
@@ -131,7 +125,7 @@ describe('GoogleMap', () => {
131125
});
132126

133127
it('sets center and zoom of the map', () => {
134-
const options = {center: {lat: 3, lng: 5}, zoom: 7, mapTypeId: undefined};
128+
const options = {center: {lat: 3, lng: 5}, zoom: 7, mapTypeId: DEFAULT_OPTIONS.mapTypeId};
135129
mapSpy = createMapSpy(options);
136130
mapConstructorSpy = createMapConstructorSpy(mapSpy).and.callThrough();
137131

@@ -152,7 +146,12 @@ describe('GoogleMap', () => {
152146
});
153147

154148
it('sets map options', () => {
155-
const options = {center: {lat: 3, lng: 5}, zoom: 7, draggable: false, mapTypeId: undefined};
149+
const options = {
150+
center: {lat: 3, lng: 5},
151+
zoom: 7,
152+
draggable: false,
153+
mapTypeId: DEFAULT_OPTIONS.mapTypeId
154+
};
156155
mapSpy = createMapSpy(options);
157156
mapConstructorSpy = createMapConstructorSpy(mapSpy).and.callThrough();
158157

@@ -211,7 +210,7 @@ describe('GoogleMap', () => {
211210
center: {lat: 12, lng: 15},
212211
zoom: 5,
213212
heading: 170,
214-
mapTypeId: undefined
213+
mapTypeId: DEFAULT_OPTIONS.mapTypeId
215214
};
216215
mapSpy = createMapSpy(correctedOptions);
217216
mapConstructorSpy = createMapConstructorSpy(mapSpy);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ interface GoogleMapsWindow extends Window {
3535
/** default options set to the Googleplex */
3636
export const DEFAULT_OPTIONS: google.maps.MapOptions = {
3737
center: {lat: 37.421995, lng: -122.084092},
38-
zoom: 17
38+
zoom: 17,
39+
// Note: the type conversion here isn't necessary for our CI, but it resolves a g3 failure.
40+
mapTypeId: 'roadmap' as unknown as google.maps.MapTypeId
3941
};
4042

4143
/** Arbitrary default height for the map element */
@@ -466,7 +468,9 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
466468
// Google Maps will render a blank rectangle which looks broken.
467469
center: this._center || options.center || DEFAULT_OPTIONS.center,
468470
zoom: this._zoom ?? options.zoom ?? DEFAULT_OPTIONS.zoom,
469-
mapTypeId: this.mapTypeId || options.mapTypeId
471+
// Passing in an undefined `mapTypeId` seems to break tile loading
472+
// so make sure that we have some kind of default (see #22082).
473+
mapTypeId: this.mapTypeId || options.mapTypeId || DEFAULT_OPTIONS.mapTypeId
470474
};
471475
}
472476

0 commit comments

Comments
 (0)