Skip to content
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

Can we get an event for when gmpx-api-loader is done loading? #234

Open
spingary opened this issue Sep 19, 2024 · 2 comments
Open

Can we get an event for when gmpx-api-loader is done loading? #234

spingary opened this issue Sep 19, 2024 · 2 comments
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@spingary
Copy link

Can we get an event fired when gmpx-api-loader is done loading "maps" and other libraries? Currently there's no way to implement a "initMap" type function reliably.

For example, on Safari, once the page is cached, the window.load event fires before the Google Maps library is finished loading/initializing. As such, I cannot access google.maps.* functions.

I had to resort to polling (yuck!) for now.

@spingary spingary added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Sep 19, 2024
@awmack
Copy link
Collaborator

awmack commented Sep 20, 2024

Hey! Thanks for the feedback. Can you give some more description about your use case -- what are you trying to accomplish? In general, I would recommend avoiding the global google.maps object and instead get references to GMP API objects explicitly (for exactly the types of scenarios you mention).

Typically, <gmpx-api-loader> usage falls into two scenarios:

  • If you're simply using components in this library like <gmpx-place-overview>, a <gmpx-api-loader> is a way to specify your API key and you don't need to explicitly wait for anything.
  • If you're building your own component and want to use <gmpx-api-loader> to load a Google Maps library, you'd write e.g. const { Map } = await APILoader.importLibrary('map');. In this case you wouldn't need an event since you are await'ing the load event in JS.

@spingary
Copy link
Author

So I am placing a component with some markers inside.
I have a select box which a user can change to show/hide different markers inside the map.
On page load, I need to read the default select box selection, and then show/hide the appropriate markers in the map, then do a fitBounds().

As such, I need to use "new google.maps.LatLngBounds()" on page load so I can calculate the bounds to fitBounds to. But as mentioned, sometimes google.maps is not yet initialized, so even though my script runs on window.load,

So in my case, would you suggest that I don' t use the web component and instead load the map programmatically?

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants