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

Remove popups on Map#remove #7749

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class Popup extends Evented {
constructor(options: PopupOptions) {
super();
this.options = extend(Object.create(defaultOptions), options);
bindAll(['_update', '_onClickClose'], this);
bindAll(['_update', '_onClickClose', 'remove'], this);
}

/**
Expand All @@ -99,6 +99,7 @@ export default class Popup extends Evented {
if (this.options.closeOnClick) {
this._map.on('click', this._onClickClose);
}
this._map.on('remove', this.remove);
this._update();

/**
Expand Down Expand Up @@ -143,6 +144,7 @@ export default class Popup extends Evented {
if (this._map) {
this._map.off('move', this._update);
this._map.off('click', this._onClickClose);
this._map.off('remove', this.remove);
delete this._map;
}

Expand Down
13 changes: 13 additions & 0 deletions test/unit/ui/popup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,16 @@ test('Popup adds classes from className option', (t) => {
t.ok(popupContainer.classList.contains('classes'));
t.end();
});

test('Popup closes on Map#remove', (t) => {
const map = createMap(t);
const popup = new Popup()
.setText("Test")
.setLngLat([0, 0])
.addTo(map);

map.remove();

t.ok(!popup.isOpen());
t.end();
});