Skip to content

Commit

Permalink
fix(google-maps): mapId not being set
Browse files Browse the repository at this point in the history
Fixes that the `mapId` input wasn't being passed along to the map.

Fixes #28608.
  • Loading branch information
crisbeto committed Feb 21, 2024
1 parent d1d1d02 commit 5269e0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/google-maps/google-map/google-map.spec.ts
Expand Up @@ -52,7 +52,10 @@ 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);
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
...DEFAULT_OPTIONS,
mapId: undefined,
});
});

it('sets height and width of the map', () => {
Expand All @@ -67,7 +70,10 @@ 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);
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, {
...DEFAULT_OPTIONS,
mapId: undefined,
});

fixture.componentInstance.height = '650px';
fixture.componentInstance.width = '350px';
Expand Down Expand Up @@ -118,6 +124,7 @@ describe('GoogleMap', () => {
center: {lat: 3, lng: 5},
zoom: 7,
mapTypeId: DEFAULT_OPTIONS.mapTypeId,
mapId: undefined,
};
mapSpy = createMapSpy(options);
mapConstructorSpy = createMapConstructorSpy(mapSpy);
Expand Down Expand Up @@ -344,6 +351,20 @@ describe('GoogleMap', () => {
expect(mapSpy.setMapTypeId).toHaveBeenCalledWith('roadmap');
});

it('should set the map ID', () => {
mapSpy = createMapSpy(DEFAULT_OPTIONS);
mapConstructorSpy = createMapConstructorSpy(mapSpy);

const fixture = TestBed.createComponent(TestApp);
fixture.componentInstance.mapId = '123';
fixture.detectChanges();

expect(mapConstructorSpy).toHaveBeenCalledWith(
jasmine.any(HTMLElement),
jasmine.objectContaining({mapId: '123'}),
);
});

it('sets mapTypeId through the options', () => {
const options = {mapTypeId: 'satellite'};
mapSpy = createMapSpy(options);
Expand Down Expand Up @@ -401,6 +422,7 @@ describe('GoogleMap', () => {
[zoom]="zoom"
[options]="options"
[mapTypeId]="mapTypeId"
[mapId]="mapId"
(mapClick)="handleClick($event)"
(centerChanged)="handleCenterChanged()"
(mapRightclick)="handleRightclick($event)"
Expand All @@ -417,6 +439,7 @@ class TestApp {
zoom?: number;
options?: google.maps.MapOptions;
mapTypeId?: google.maps.MapTypeId;
mapId?: string;

handleClick(event: google.maps.MapMouseEvent) {}
handleCenterChanged() {}
Expand Down
1 change: 1 addition & 0 deletions src/google-maps/google-map/google-map.ts
Expand Up @@ -531,6 +531,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
// 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,
mapId: this.mapId || options.mapId,
};
}

Expand Down

0 comments on commit 5269e0f

Please sign in to comment.