angulargoogle-mapsgoogle-maps-api-3agm

Does AGM preserve Google Map's session when component is re-initialised?


We're currently working on a map-load heavy portal for sales in Angular. We decided to use the AGM library which provided a very good support for both Angular and TypeScript.

We display the map on every Search results page and when the user is navigating back-and-forth from Search results to Product's detail page we destroy/re-initialise the MapComponent. I'm a bit worried if this will not trigger additional Google Maps requests/sessions as it's re-initialised, but I have no idea how to do the metrics. We, unfortunately, cannot easily hide/show the component because of our app's architecture.

So the question is how the session behaves in the AGM? Does each re-initialisation of the component create a new paid request? Thank you in advance.


Solution

  • As any other angular component, when agm-map is removed from the component tree, it's removed from the DOM. The google.maps.Map object is destroyed, and recreated when the component is shown again.

    The reinitalization is not completely from scratch, though. google maps script is loaded only once per project (at least once per calling AgmCoreModule.forRoot which should be called only once in any normal project). So while google.maps.Map object is destroyed and reinitialized, the script remains.

    Your last location and all polygons, etc WILL NOT be cached, because when an agm-map component is created or recreated, it sets the center attribute from scratch.

    As for prices, google docs seems to suggest that you will be charged for every recreation of the map.