Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active December 22, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knownasilya/6439916 to your computer and use it in GitHub Desktop.
Save knownasilya/6439916 to your computer and use it in GitHub Desktop.
GMap InfoWindow for Ember
App.MapView = Ember.View.extend({
// Other methods here
openPopup: function (options) {
var popup = this.get('popup'),
hiddenPopup = this.get('lastPopupView'),
controller = this.get('controller');
// close last popup
if (popup) {
popup.close();
}
if (hiddenPopup) {
hiddenPopup.destroy();
}
popup = new google.maps.InfoWindow({
content: '<div id=\'single-popup\'></div>',
position: options.position
});
hiddenPopup = this.container.lookup('view:popup');
hiddenPopup.set('controller', controller);
hiddenPopup.set('building', options.data);
popup.open(options.map);
hiddenPopup.appendTo('body');
Ember.run.scheduleOnce('afterRender', hiddenPopup, function () {
var $detached = hiddenPopup.$().detach();
popup.setContent($detached.get(0));
hiddenPopup.toggleProperty('isVisible');
});
this.set('popup', popup);
this.set('lastPopupView', hiddenPopup);
this.handlePopupClose(popup, hiddenPopup);
},
handlePopupClose: function (popup, popupView) {
if (popup && popupView) {
google.maps.event.addListener(popup, 'closeclick', function () {
popupView.destroy();
});
}
}
});
@knownasilya
Copy link
Author

This is for a single popup at a time. To get multiple popups to work, i'd take the auto generated id of the hiddenPopup and prepend it with container-, so container-ember323 and add that as a blank div to the popup just opened, then you can find that element, and append to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment