fix: catch cluster error at zoom in certain situation

Eg. to reproduce: a map with a limitBounds that makes uMap immediately
zoom to fit the bbox.

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2025-01-30 18:40:05 +01:00
parent e6db23d4d3
commit a18b240c65

View file

@ -63,7 +63,17 @@ export const Cluster = L.MarkerClusterGroup.extend({
addLayer: function (layer) { addLayer: function (layer) {
this._layers.push(layer) this._layers.push(layer)
try {
return L.MarkerClusterGroup.prototype.addLayer.call(this, layer) return L.MarkerClusterGroup.prototype.addLayer.call(this, layer)
} catch (error) {
console.debug(error)
// Certainly a race condition when loading a clustered layer
// while zooming (this for example can happen at load, when the
// initial zoom is changed by uMap).
// FIXME: remove when this is merged:
// https://github.com/Leaflet/Leaflet.markercluster/pull/1048/files
return this
}
}, },
removeLayer: function (layer) { removeLayer: function (layer) {