Skip to content

Commit

Permalink
fix: always open popup with single click (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
turban authored Sep 13, 2021
1 parent 491bda4 commit bd2b9ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,16 @@ export class MapGL extends Evented {
this._popup = new Popup()
}

// Remove previous attached onClose event before setting new content
this._popup.clear()

this._popup
.setLngLat(lnglat)
.setDOMContent(content)
.onClose(onClose)
.addTo(this)

// (Re)set onClose event
this._popup.onClose(onClose)
}

closePopup() {
Expand Down
10 changes: 10 additions & 0 deletions src/ui/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ class Popup extends PopupGL {
}
}

// Remove onClose event if it exists
clear() {
if (this._onCloseFunc) {
this.off('close', this._onCloseFunc)
this._onCloseFunc = null
}
return this
}

onClose(onClose) {
if (typeof onClose === 'function') {
this._onCloseFunc = onClose
this.on('close', onClose)
}
return this
Expand Down

0 comments on commit bd2b9ac

Please sign in to comment.