aurelia-leaflet
aurelia-leaflet copied to clipboard
BUG FIX Don't add existing layers again
BUG: I've noticed that, when removing a layer, the remaining layers were added again. As they are added on top of each other, you cannot see it, but you can check it in your DOM tree.
FIX: The problem occurs in leaflet.js, in the attachLayers function. It doesn't check whether an existing layer is already attached. All I needed to do was to change (line 161)
if (this.layers.hasOwnProperty('base')) {
for (let layer of this.layers.base) {
layersToAttach.base[this.getLayerId(layer)] = this.layerFactory.getLayer(layer);
}
}
if (this.layers.hasOwnProperty('overlay')) {
for (let layer of this.layers.overlay) {
layersToAttach.overlay[this.getLayerId(layer)] = this.layerFactory.getLayer(layer);
}
}
into
if (this.layers.hasOwnProperty('base')) {
for (let layer of this.layers.base) {
const id = this.getLayerId(layer);
if (this.attachedLayers.base.hasOwnProperty(id)) { continue; }
layersToAttach.base[id] = this.layerFactory.getLayer(layer);
}
}
if (this.layers.hasOwnProperty('overlay')) {
for (let layer of this.layers.overlay) {
const id = this.getLayerId(layer);
if (this.attachedLayers.overlay.hasOwnProperty(id)) { continue; }
layersToAttach.overlay[this.getLayerId(layer)] = this.layerFactory.getLayer(layer);
}
}
@erikvullings Thank you so much for this PR. Just now found the time to look into this. I left one small change request. If you could update your PR I'll happily merge it and release a new version.