Skip to content

fix(google-maps): ensure that a mapTypeId is always passed in #22098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/google-maps/google-map/google-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ describe('GoogleMap', () => {
const container = fixture.debugElement.query(By.css('div'))!;
expect(container.nativeElement.style.height).toBe(DEFAULT_HEIGHT);
expect(container.nativeElement.style.width).toBe(DEFAULT_WIDTH);
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
...DEFAULT_OPTIONS,
mapTypeId: undefined
});
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
});

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

fixture.componentInstance.height = '650px';
fixture.componentInstance.width = '350px';
Expand Down Expand Up @@ -131,7 +125,7 @@ describe('GoogleMap', () => {
});

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

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

it('sets map options', () => {
const options = {center: {lat: 3, lng: 5}, zoom: 7, draggable: false, mapTypeId: undefined};
const options = {
center: {lat: 3, lng: 5},
zoom: 7,
draggable: false,
mapTypeId: DEFAULT_OPTIONS.mapTypeId
};
mapSpy = createMapSpy(options);
mapConstructorSpy = createMapConstructorSpy(mapSpy).and.callThrough();

Expand Down Expand Up @@ -211,7 +210,7 @@ describe('GoogleMap', () => {
center: {lat: 12, lng: 15},
zoom: 5,
heading: 170,
mapTypeId: undefined
mapTypeId: DEFAULT_OPTIONS.mapTypeId
};
mapSpy = createMapSpy(correctedOptions);
mapConstructorSpy = createMapConstructorSpy(mapSpy);
Expand Down
8 changes: 6 additions & 2 deletions src/google-maps/google-map/google-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ interface GoogleMapsWindow extends Window {
/** default options set to the Googleplex */
export const DEFAULT_OPTIONS: google.maps.MapOptions = {
center: {lat: 37.421995, lng: -122.084092},
zoom: 17
zoom: 17,
// Note: the type conversion here isn't necessary for our CI, but it resolves a g3 failure.
mapTypeId: 'roadmap' as unknown as google.maps.MapTypeId
};

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

Expand Down