From a18b240c65ba37102c01f569e50c99ab9c175501 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 30 Jan 2025 18:40:05 +0100 Subject: [PATCH] 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 --- .../umap/js/modules/rendering/layers/cluster.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/modules/rendering/layers/cluster.js b/umap/static/umap/js/modules/rendering/layers/cluster.js index 227ea82c6..2349f6c02 100644 --- a/umap/static/umap/js/modules/rendering/layers/cluster.js +++ b/umap/static/umap/js/modules/rendering/layers/cluster.js @@ -63,7 +63,17 @@ export const Cluster = L.MarkerClusterGroup.extend({ addLayer: function (layer) { this._layers.push(layer) - return L.MarkerClusterGroup.prototype.addLayer.call(this, layer) + try { + 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) {