Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

included the Google Maps API multiple times on this page #10

Closed
atzorvas opened this issue Jun 22, 2015 · 6 comments
Closed

included the Google Maps API multiple times on this page #10

atzorvas opened this issue Jun 22, 2015 · 6 comments

Comments

@atzorvas
Copy link

I cannot understand why this is defined multiple times. any ideas?

You have included the Google Maps API multiple times on this page. 
This may cause unexpected errors.

this is inside my routes.js

Router.onBeforeAction(function() {
  GoogleMaps.load({
    libraries: 'places'
  });
  this.next();
}, { only: ['oneRoute', 'anotherRoute'] });

2015-06-22--1434973830_1906x168_scrot

thanks

@jshimko
Copy link
Owner

jshimko commented Jun 22, 2015

Hmm. Not sure. GoogleMaps.load() is in an onBeforeAction (which does often run multiple times), but that load method can only run once thanks to underscore's _.once(). See source here.

I also load the library the same way in multiple apps and don't have the issue, so are you sure there's not another spot that you used the GoogleMaps.load() and forgot to remove it?

@atzorvas
Copy link
Author

Yeah, routes.js is the only place

grep 'GoogleMaps.load' * -aR

app/.meteor/local/build/programs/server/app/lib/routes.js:  GoogleMaps.load({
app/.meteor/local/build/programs/web.browser/app/lib/routes.js:  GoogleMaps.load({
app/.meteor/local/build/programs/web.browser/app/client/templates/rides/create_ride/create_ride.js:    if (GoogleMaps.loaded()) {
app/.meteor/local/build/programs/web.browser/packages/dburles_google-maps.js:    if (GoogleMaps.loaded()) {                                                                 // 79
app/.meteor/local/build/programs/web.browser/packages/dburles_google-maps.js.map:{"version":3,"sources":["dburles:google-maps/google-maps.html","dburles:google-maps/google-maps.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kC;AACA,wE;AACA,kB;AACA,sF;AACA,I;;;;;;;;;;;;;;;;;;;ACLA,mD;;AAEA,c;AACA,kC;AACA,gD;AACA,8F;AACA,kD;AACA,oC;AACA,sE;AACA,wC;;AAEA,sC;AACA,K;AACA,uB;AACA,sC;AACA,qC;AACA,I;AACA,kC;AACA,sB;AACA,8B;AACA,I;AACA,W;AACA,iB;AACA,0B;AACA,2B;AACA,kD;AACA,oD;AACA,sC;AACA,wB;;AAEA,wC;AACA,O;AACA,I;AACA,+B;AACA,gD;AACA,2B;AACA,gB;AACA,O;AACA,I;AACA,6B;AACA,gC;AACA,iC;AACA,8C;AACA,gE;AACA,2C;AACA,I;AACA,iC;AACA,uB;AACA,0B;AACA,2B;AACA,4B;AACA,S;AACA,O;AACA,uB;AACA,2B;AACA,I;AACA,oC;AACA,oB;AACA,uB;AACA,iC;AACA,8B;AACA,M;;AAEA,gD;AACA,wC;AACA,yC;AACA,Y;AACA,iF;AACA,2C;AACA,S;AACA,K;AACA,G;AACA,E;;AAEA,0C;AACA,kB;AACA,4B;AACA,4B;AACA,8B;AACA,wC;;AAEA,yB;AACA,e;AACA,sB;AACA,sE;AACA,M;AACA,gD;;AAEA,uB;AACA,+C;AACA,4C;AACA,8E;;AAEA,qC;AACA,mB;AACA,8D;AACA,6B;AACA,S;;AAEA,e;AACA,K;AACA,K;AACA,G","file":"/packages/dburles_google-maps.js","sourcesContent":["\nTemplate.__checkName(\"googleMap\");\nTemplate[\"googleMap\"] = new Template(\"Template.googleMap\", (function() {\n  var view = this;\n  return HTML.Raw('<div class=\"map-canvas\" style=\"width: 100%; height: 100%\"></div>');\n}));\n","var supportedTypes = ['Map', 'StreetViewPanorama'];\n\nGoogleMaps = {\n  load: _.once(function(options) {\n    options = _.extend({ v: '3.exp' }, options);\n    var params = _.map(options, function(value, key) { return key + '=' + value; }).join('&');\n    var script = document.createElement('script');\n    script.type = 'text/javascript';\n    script.src = 'https://maps.googleapis.com/maps/api/js?' + params +\n      '&callback=GoogleMaps.initialize';\n\n    document.body.appendChild(script);\n  }),\n  utilityLibraries: [],\n  loadUtilityLibrary: function(path) {\n    this.utilityLibraries.push(path);\n  },\n  _loaded: new ReactiveVar(false),\n  loaded: function() {\n    return this._loaded.get();\n  },\n  maps: {},\n  _callbacks: {},\n  initialize: function() {\n    this._loaded.set(true);\n    _.each(this.utilityLibraries, function(path) {\n      var script = document.createElement('script');\n      script.type = 'text/javascript';\n      script.src = path;\n\n      document.body.appendChild(script);\n    });\n  },\n  _ready: function(name, map) {\n    _.each(this._callbacks[name], function(cb) {\n      if (_.isFunction(cb))\n        cb(map);\n    });\n  },\n  ready: function(name, cb) {\n    if (! this._callbacks[name])\n      this._callbacks[name] = [];\n    // make sure we run the callback only once\n    // as the tilesloaded event will also run after initial load\n    this._callbacks[name].push(_.once(cb));\n  },\n  // options: function(options) {\n  //   var self = this;\n  //   return function() {\n  //     if (self.loaded())\n  //       return options();\n  //   };\n  // },\n  get: function(name) {\n    return this.maps[name];\n  },\n  _create: function(name, options) {\n    var self = this;\n    self.maps[name] = {\n      instance: options.instance,\n      options: options.options\n    };\n\n    if (options.type === 'StreetViewPanorama') {\n      options.instance.setVisible(true);\n      self._ready(name, self.maps[name]);\n    } else {\n      google.maps.event.addListener(options.instance, 'tilesloaded', function() {\n        self._ready(name, self.maps[name]);\n      });\n    }\n  }\n};\n\nTemplate.googleMap.onRendered(function() {\n  var self = this;\n  self.autorun(function(c) {\n    // if the api has loaded\n    if (GoogleMaps.loaded()) {\n      var data = Template.currentData();\n\n      if (! data.options)\n        return;\n      if (! data.name)\n        throw new Meteor.Error(\"GoogleMaps - Missing argument: name\");\n      \n      var canvas = self.$('.map-canvas').get(0);\n\n      // default to Map\n      var type = data.type ? data.type : 'Map';\n      if (! _.include(supportedTypes, type))\n        throw new Meteor.Error(\"GoogleMaps - Invalid type argument: \" + type);\n\n      GoogleMaps._create(data.name, {\n        type: type,\n        instance: new google.maps[type](canvas, data.options),\n        options: data.options\n      });\n\n      c.stop();\n    }\n  });\n});\n"]}
app/lib/routes.js:  GoogleMaps.load({
app/client/templates/rides/create_ride/create_ride.js:    if (GoogleMaps.loaded()) {

iron list

accounts-base
accounts-facebook
aldeed:autoform
aldeed:collection2
aldeed:delete-button
ian:accounts-ui-bootstrap-3
iron:router
jeremy:geocomplete
meteor-platform
momentjs:moment
twbs:bootstrap

@jshimko
Copy link
Owner

jshimko commented Jun 22, 2015

Unfortunately, I can't reproduce the issue on my end. If you put something up on Github, I'd be happy to take a look at it.

@atzorvas
Copy link
Author

Thanks, I've just created the repo github.com/atzorvas/rideshare

@jshimko
Copy link
Owner

jshimko commented Jun 22, 2015

@jshimko jshimko closed this as completed Jun 22, 2015
@atzorvas
Copy link
Author

oh thanks, my bad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants