Skip to content

Commit

Permalink
fix(label): correctly remove labels when LabelLayer is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
zarov committed Oct 2, 2020
1 parent d7f5c06 commit 60cfa44
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class LabelLayer extends Layer {
const label = new Label(content,
coord.clone(),
g.properties.style || f.style || this.style);
label.layerId = this.id;

if (f.size == 2) {
label.needsAltitude = true;
Expand Down Expand Up @@ -249,18 +250,39 @@ class LabelLayer extends Layer {
// Necessary event listener, to remove any Label attached to
// this tile
node.addEventListener('removed', () => {
result.forEach(labels => labels.forEach(label => node.remove(label)));
const child = node.domElements[this.id].dom;
child.parentElement.removeChild(child);
result.forEach(labels => labels.forEach(l => node.remove(l)));
this.removeNodeDomElement(node);
});
}

node.layerUpdateState[this.id].noMoreUpdatePossible();
});
}

removeLabelsFromNodeRecursive(node) {
node.children.forEach((c) => {
if (c.isLabel && c.layerId === this.id) {
node.remove(c);
} else if (c.isTileMesh) {
this.removeLabelsFromNodeRecursive(c);
}
});

this.removeNodeDomElement(node);
}

removeNodeDomElement(node) {
if (node.domElements[this.id]) {
const child = node.domElements[this.id].dom;
child.parentElement.removeChild(child);
delete node.domElements[this.id];
}
}

delete() {
this.domElement.parentElement.removeChild(this.domElement);

this.parent.level0Nodes.forEach(obj => this.removeLabelsFromNodeRecursive(obj));
}
}

Expand Down

0 comments on commit 60cfa44

Please sign in to comment.