Skip to content

bug([google-map]): [README.MD example only produces grey rectangle, no map] #18965

Closed
@eamon-otuathail

Description

@eamon-otuathail

Reproduction

The README for Google Maps contains code that produces just a grey map:
https://github.com/angular/components/blob/master/src/google-maps/README.md

Steps to reproduce:
Add the readme code to a brand new simple new demo project (ng new demo)

Expected Behavior

The map should be displayed correctly, without having to force a refresh.

Actual Behavior

A grey rectangle is displayed where the map should be.
No error messages are produced.
Note the README example did work correctly for Google Maps in Angular Components 9.0.

With Google-Maps in Angular Components 9.2, to get a map correctly displayed, one now needs to add this extra line to the demo .html file:
[mapTypeId]="mapTypeId"
And add this line to the demo .ts file:
mapTypeId: google.maps.MapTypeId;
and also implement AfterViewInit to force a redraw:
export class GoogleMapDemo implements AfterViewInit {
..
ngAfterViewInit(): void {
// Vary the map properties somehow to force a redraw
this.mapTypeId = google.maps.MapTypeId.ROADMAP;
}
}

Environment

  • Angular: 9.1.0
  • CDK/Material: 9.2.0
  • Browser(s): Chrome 83.0.4093.3
  • Operating System: Windows

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions