googlemaps / extended-component-library

A set of Web Components from Google Maps Platform
https://configure.mapsplatform.google/
Apache License 2.0
136 stars 12 forks source link

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

Open spingary opened 2 months ago

spingary commented 2 months ago

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.

awmack commented 2 months ago

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:

spingary commented 2 months ago

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!