Skip to content

Comments

feat: Migrates the event-poi sample to js-api-samples.#1135

Open
willum070 wants to merge 1 commit intomainfrom
migrate-event-poi
Open

feat: Migrates the event-poi sample to js-api-samples.#1135
willum070 wants to merge 1 commit intomainfrom
migrate-event-poi

Conversation

@willum070
Copy link
Collaborator

This PR makes the following changes:

  • Migrates the event-poi sample to js-api-samples.
  • Refactors the app to use the gmp-map element and dynamic loading.
  • Updates the app to use the New Places API.
  • Simplifies the sample by removing directions functionality (too many things distract from the primary use case).

@snippet-bot
Copy link

snippet-bot bot commented Feb 24, 2026

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@willum070 willum070 requested a review from ReeseJones February 24, 2026 20:19
Copy link

@ReeseJones ReeseJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link

@ReeseJones ReeseJones Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you prefer to define variables globally for samples, I would define this in initMap just before its used on line 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants