Skip to content

Commit 3f1b1f7

Browse files
authored
fix(google-maps): mapTypeId not being set from options (#21909)
Fixes a regression where the `mapTypeId` from the `options` object wasn't being preserved when combining the options with the input values. Fixes #21903.
1 parent adb31c2 commit 3f1b1f7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ describe('GoogleMap', () => {
347347

348348
expect(mapSpy.setMapTypeId).toHaveBeenCalledWith('roadmap');
349349
});
350+
351+
it('sets mapTypeId through the options', () => {
352+
const options = {mapTypeId: 'satellite'};
353+
mapSpy = createMapSpy(options);
354+
mapConstructorSpy = createMapConstructorSpy(mapSpy).and.callThrough();
355+
const fixture = TestBed.createComponent(TestApp);
356+
fixture.componentInstance.options = options;
357+
fixture.detectChanges();
358+
359+
expect(mapConstructorSpy.calls.mostRecent()?.args[1].mapTypeId).toBe('satellite');
360+
});
361+
350362
});
351363

352364
@Component({

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
252252
const googleMap = this.googleMap;
253253

254254
if (googleMap) {
255-
if (changes['options'] && this._options) {
256-
googleMap.setOptions(this._options);
255+
if (changes['options']) {
256+
googleMap.setOptions(this._combineOptions());
257257
}
258258

259259
if (changes['center'] && this._center) {
@@ -459,14 +459,14 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
459459

460460
/** Combines the center and zoom and the other map options into a single object */
461461
private _combineOptions(): google.maps.MapOptions {
462-
const options = this._options;
462+
const options = this._options || {};
463463
return {
464464
...options,
465465
// It's important that we set **some** kind of `center` and `zoom`, otherwise
466466
// Google Maps will render a blank rectangle which looks broken.
467467
center: this._center || options.center || DEFAULT_OPTIONS.center,
468468
zoom: this._zoom ?? options.zoom ?? DEFAULT_OPTIONS.zoom,
469-
mapTypeId: this.mapTypeId
469+
mapTypeId: this.mapTypeId || options.mapTypeId
470470
};
471471
}
472472

0 commit comments

Comments
 (0)