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
feat(google-maps): support setting the map type #18578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ export interface UpdatedGoogleMap extends google.maps.Map { | |
export const DEFAULT_OPTIONS: google.maps.MapOptions = { | ||
center: {lat: 37.421995, lng: -122.084092}, | ||
zoom: 17, | ||
mapTypeId: undefined | ||
}; | ||
|
||
/** Arbitrary default height for the map element */ | ||
|
@@ -79,10 +80,18 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { | |
/** Whether we're currently rendering inside a browser. */ | ||
_isBrowser: boolean; | ||
|
||
/** Height of the map. */ | ||
@Input() height: string | number = DEFAULT_HEIGHT; | ||
|
||
/** Width of the map. */ | ||
@Input() width: string | number = DEFAULT_WIDTH; | ||
|
||
/** | ||
* Type of map that should be rendered. E.g. hybrid map, terrain map etc. | ||
* See: https://developers.google.com/maps/documentation/javascript/reference/map#MapTypeId | ||
*/ | ||
@Input() mapTypeId: google.maps.MapTypeId | undefined; | ||
|
||
@Input() | ||
set center(center: google.maps.LatLngLiteral|google.maps.LatLng) { | ||
this._center.next(center); | ||
|
@@ -249,6 +258,9 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { | |
|
||
ngOnChanges() { | ||
this._setSize(); | ||
if (this._googleMap && this.mapTypeId) { | ||
this._googleMap.setMapTypeId(this.mapTypeId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will call setMapTypeId for every change. My preference would be to continue the existing pattern, or failing that, at least include a check that the mapTypeId has changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct, but from what I can tell, the Google Maps API already knows not to do anything if you're giving it the same map type that it already has. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, sounds good |
||
} | ||
} | ||
|
||
ngOnInit() { | ||
|
@@ -447,6 +459,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy { | |
...options, | ||
center: center || options.center, | ||
zoom: zoom !== undefined ? zoom : options.zoom, | ||
mapTypeId: this.mapTypeId | ||
}; | ||
return combinedOptions; | ||
})); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not google.maps.MapTypeId.TERRAIN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the global
google
variable isn't available when running unit tests.