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 controls before destroying map #7479

Merged
merged 1 commit into from
Oct 26, 2018
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
7 changes: 4 additions & 3 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,10 @@ class Map extends Camera {
*/
remove() {
if (this._hash) this._hash.remove();

for (const control of this._controls) control.onRemove(this);
this._controls = [];

if (this._frame) {
this._frame.cancel();
this._frame = null;
Expand All @@ -1675,9 +1679,6 @@ class Map extends Camera {
window.removeEventListener('online', this._onWindowOnline, false);
}

for (const control of this._controls) control.onRemove(this);
this._controls = [];

const extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
if (extension) extension.loseContext();
removeNode(this._canvasContainer);
Expand Down
24 changes: 24 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,30 @@ test('Map', (t) => {
t.end();
});

t.test('#remove calls onRemove on added controls before style is destroyed', (t) => {
const map = createMap(t);
let onRemoveCalled = 0;
let style;
const control = {
onRemove: function(map) {
onRemoveCalled++;
t.deepEqual(map.getStyle(), style);
},
onAdd: function (_) {
return window.document.createElement('div');
}
};

map.addControl(control);

map.on('style.load', () => {
style = map.getStyle();
map.remove();
t.equal(onRemoveCalled, 1);
t.end();
});
});

t.test('#addControl', (t) => {
const map = createMap(t);
const control = {
Expand Down