Skip to content

Commit

Permalink
Fix exceptions thrown when opening marker-bound popup by click
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Aug 30, 2016
1 parent 1b43db0 commit b2e352b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions js/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ Marker.prototype = {

/**
* Binds a Popup to the Marker
* @param {Popup=} popup an instance of the `Popup` class. If undefined or null, any popup
* @param {Popup=} popup an instance of the `Popup` class. If undefined or null, any popup
* set on this `Marker` instance is unset
* @returns {Marker} `this`
*/

setPopup: function (popup) {
var this = that;

if (popup == null) {
this._closePopup();
delete this._popupHandlersAdded;
Expand All @@ -110,7 +112,10 @@ Marker.prototype = {
if (this._popup && this._lngLat) this._popup.setLngLat(this._lngLat);

if (!this._popupHandlersAdded) {
this.getElement().addEventListener('click', this._openPopup.bind(this));
this.getElement().addEventListener('click', function(event) {
event.stopPropagation();
that._openPopup();
});
this._popupHandlersAdded = true;
}
return this;
Expand Down Expand Up @@ -139,9 +144,6 @@ Marker.prototype = {
},

_openPopup: function (e) {
// prevent event from bubbling up to the map canvas
e.stopPropagation();

if (!this._popup || !this._map) return;

if (!this._popup._map) {
Expand All @@ -165,4 +167,3 @@ Marker.prototype = {
DOM.setTransform(this._el, 'translate(' + pos.x + 'px,' + pos.y + 'px)');
}
};

0 comments on commit b2e352b

Please sign in to comment.