GuillaumeLeclerc / vue-google-maps

Google maps component for vue with 2-way data binding
561 stars 654 forks source link

Getting the map object #111

Closed ethanclevenger91 closed 8 years ago

ethanclevenger91 commented 8 years ago

Hey, trying to get the map object to render some directions and some other stuff that either isn't in this library or isn't documented. The documentation says to use vm.mapObject, but what is vm referring to in that context?

Right now I've got a component with a <map v-ref:map></map> as a child component, but this.$refs.map.mapObject is undefined:

import { Map, Marker, Cluster, loaded } from 'vue-google-maps'
...
ready() {
    var vm = this;
    loaded.then(function() {
      vm.directionsDisplay = new google.maps.DirectionsRenderer();
      console.log(vm.$refs.map.mapObject);
    });
  }
xkjyeah commented 8 years ago

Your code is correct, except mapObject is not available at that point because the Map instance hasn't called new google.maps.Map(...).

You need to wait on map.mapCreated promise.

vm.$refs.map.mapCreated.then((gmapObject) => ...)
ethanclevenger91 commented 8 years ago

That worked, thanks a lot. Is that promise documented?

xkjyeah commented 8 years ago

I wasn't one minute ago...

I'm not too sure about whether it should be part of the API, but I'll just document it anyway since we're not at v1.0.0 yet.