Progress bar is shown too late after layer was added
m-mohr opened this issue · comments
Matthias Mohr commented
Sorry, I have to come up with an issue again. ;-)
I was wondering why the progress bar doesn't show up immediately for layers added later (see #4).
I would propose the following change in onAdd:
Replace
map.on('layeradd', function(e) {
var currentLayers = leafletElt.getLayers();
for (var i = 0; i < currentLayers.length; i++) {
// If the layer added to the map is part of the layer group then we rebind the loading triggers.
if (currentLayers[i] === e.layer) {
controlInstance.unbindLoadEventTriggers();
controlInstance.bindLoadEventTriggers();
break;
}
}
});
with
var self = this;
map.on('layeradd', function(e) {
var currentLayers = leafletElt.getLayers();
for (var i = 0; i < currentLayers.length; i++) {
// If the layer added to the map is part of the layer group then we rebind the loading triggers.
if (currentLayers[i] === e.layer) {
controlInstance.unbindLoadEventTriggers();
controlInstance.bindLoadEventTriggers();
break;
}
}
self.handleLoadingStatusUpdate();
});
It seems the first event fires quite late after the (slow loading) layer has been added. I could fix it by calling handleLoadingStatusUpdate() once after the layer has been added.
Still looking into the back-and-forth issue.
James Collins commented
Seems like reasonable logic. But wouldn't it only be necessary to handle the loading status update inside of the conditional?
Like so:
map.on('layeradd', function(e) {
var currentLayers = leafletElt.getLayers();
for (var i = 0; i < currentLayers.length; i++) {
// If the layer added to the map is part of the layer group then we rebind the loading triggers.
if (currentLayers[i] === e.layer) {
controlInstance.unbindLoadEventTriggers();
controlInstance.bindLoadEventTriggers();
controlInstance.handleLoadingStatusUpdate();
break;
}
}
});
Matthias Mohr commented
Yes, indeed.
James Collins commented
Fixed in 1.0.8
Matthias Mohr commented
Great, thanks.