feat: Migrates the event-poi sample to js-api-samples.#1135
feat: Migrates the event-poi sample to js-api-samples.#1135
Conversation
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
ReeseJones
left a comment
There was a problem hiding this comment.
Looks good, I have a few suggestions and questions.
| <body> | ||
| <gmp-map center="0, -180" zoom="3" map-type-id="terrain"> </gmp-map> | ||
| <gmp-map center="-33.871, 151.197" zoom="18"> | ||
| <div id="infowindow-content"></div> |
There was a problem hiding this comment.
Regarding the "div" on line 20 - This doesn't appear to be used in any way? I see there are css styles referencing it, but I cannot find any references to this in the sample code leading me to believe its unused? Let me know if I am missing something here.
| // Request the needed libraries. | ||
| await google.maps.importLibrary('maps'); | ||
|
|
||
| innerMap = await mapElement.innerMap; |
There was a problem hiding this comment.
The await on innerMap = await mapElement.innerMap is strange since innerMap is not a promise.
its a lot like writing
await 0;
innerMap = mapElement.innerMap;Which does things regarding processing the javascript event loop, but maybe shouldn't be used for a sample?
Does this work without it? if it does I think it should be removed.
If not, I think we should promote another way to check for when custom-components are upgraded into theirselves (and then will have all their properties and what not set). Below is something I copied from a google search about how you wait for web components to be defined.
async function waitForComponent(tagName: string): Promise<void> {
// customElements.whenDefined returns a Promise
await customElements.whenDefined(tagName);
console.log(`${tagName} is defined and ready to be used`);
}
// Usage
(async () => {
await waitForComponent('gmp-map');
// Initialize component logic here, access properties etc...
})();| // [START maps_event_poi] | ||
| const mapElement = document.querySelector('gmp-map') as google.maps.MapElement; | ||
| let innerMap; | ||
| let infowindow: google.maps.InfoWindow; |
There was a problem hiding this comment.
How do you feel about avoiding global variables?
Let infowindow be declared on line 19 and pass it in as a parameter to showInfoWindow on line 27?
| */ | ||
|
|
||
| // [START maps_event_poi] | ||
| const mapElement = document.querySelector('gmp-map') as google.maps.MapElement; |
There was a problem hiding this comment.
Unless you prefer to define variables globally for samples, I would define this in initMap just before its used on line 16.
This PR makes the following changes: