[Solved] Accessing map in ember-google-maps

I’m using ember-google-maps and I’ve added a few markers. I would like to run map.fitBounds(bounds); once all the markers have been added. Is this possible?

1 Like

What I’ve done in the past is bind the map onLoad event to a function which caches a ref to the map in my component (this is using pre-octane patterns but basically the same thing should still apply):

// components/my-map-component.js
  actions: {
    onLoad(map) {
      this.set('loaded', true);
      this.set('map', map);
      ... // do stuff with this.map here, or later

and in template:

// templates/components/my-map-component.js
  onLoad=(action "onLoad")
  as |g|

EDIT: my use case was the same, later in a different action i was doing this (notice the map.map):

    let bounds = new google.maps.LatLngBounds();
    locations.forEach((l) => bounds.extend(l));
1 Like

Thank you. That’s exactly what I needed.