dburles / meteor-google-maps

🗺 Meteor package for the Google Maps Javascript API v3
https://atmospherejs.com/dburles/google-maps
MIT License
196 stars 48 forks source link

inherit using prototype from google.maps.OverlayView #114

Closed jupiterkenji closed 8 years ago

jupiterkenji commented 8 years ago

I try to create context-menu by inheriting from google.maps.OverlayView() like so:

ContextMenu.prototype = new google.maps.OverlayView();
ContextMenu.prototype.onAdd = function() {
...
}

But it keeps saying google is not defined. I have been googling and people suggesting: if (GoogleMaps.loaded()) {..} But sounds a bit weird.

Does anyone have any knowledge on this?

Thank you. Great package!

dburles commented 8 years ago

Hey @stewiegaribaldi that's right you'll need to use that function to check whether the library has loaded before interacting with it. Typically you might attach it to the template that displays the map.

Template.myMap.onCreated(function() {
  this.autorun(() => {
    if (GoogleMaps.loaded()) {
      ContextMenu.prototype = new google.maps.OverlayView();
      ContextMenu.prototype.onAdd = function() {
        // ...
      }
    }
  });
});
jupiterkenji commented 8 years ago

Thank you @dburles , it works great!