From ccab47d59808042bdd0ab73f7f1858aea3a0bb7d Mon Sep 17 00:00:00 2001 From: Paul Marrapese Date: Sun, 5 Apr 2020 19:06:08 -0700 Subject: [PATCH 1/4] improved performance of addLayers by preallocating array --- src/MarkerClusterGroup.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 99c56e7d..db5c3d7c 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -291,7 +291,8 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ process(); } else { - var needsClustering = this._needsClustering; + var needsClustering = new Array(l - offset); // improve performance by preallocating the maximum size of our array + var tail = 0; for (; offset < l; offset++) { m = layersArray[offset]; @@ -317,8 +318,11 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ continue; } - needsClustering.push(m); + needsClustering[tail++] = m; } + + needsClustering = needsClustering.slice(0, tail); // truncate empty elements + this._needsClustering.push.apply(this._needsClustering, needsClustering); } return this; }, From f7a510e4cb23f02d16190873dac81a8f9ff3de9b Mon Sep 17 00:00:00 2001 From: Paul Marrapese Date: Wed, 26 Oct 2022 15:07:49 -0700 Subject: [PATCH 2/4] addLayers performance: use concat instead of push --- src/MarkerClusterGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index c631ff3e..e2fe5ff9 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -323,7 +323,7 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ } needsClustering = needsClustering.slice(0, tail); // truncate empty elements - this._needsClustering.push.apply(this._needsClustering, needsClustering); + this._needsClustering = this._needsClustering.concat(needsClustering); } return this; }, From 1641cf5ba475037f15812ac5e622f8e6106cae17 Mon Sep 17 00:00:00 2001 From: maranderan <33160267+maranderan@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:55:52 -0500 Subject: [PATCH 3/4] Check for finite min and max zoom properties In the event leaflet sends "infinity" as a max or min zoom while generating the initial clusters, the loop to set up the grid clusters will crash the browser. --- src/MarkerClusterGroup.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index e2fe5ff9..97ea55a7 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -972,6 +972,13 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ this._gridUnclustered = {}; //Set up DistanceGrids for each zoom + + if (!isFinite(maxZoom) ) { + throw "Map has no maxZoom specified"; + } + if (!isFinite(minZoom)) { + throw "Map has no minZoom specified"; + } for (var zoom = maxZoom; zoom >= minZoom; zoom--) { this._gridClusters[zoom] = new L.DistanceGrid(radiusFn(zoom)); this._gridUnclustered[zoom] = new L.DistanceGrid(radiusFn(zoom)); From ec8261dc0b18b6e9690ac7ecd02456c557a3a1fe Mon Sep 17 00:00:00 2001 From: tmiaa <95731292+tmiaa@users.noreply.github.com> Date: Sun, 9 Jan 2022 23:46:02 +0100 Subject: [PATCH 4/4] Adding markers aria-label for accessibility --- src/MarkerClusterGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 97ea55a7..042daf23 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -834,7 +834,7 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ c += 'large'; } - return new L.DivIcon({ html: '
' + childCount + '
', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) }); + return new L.DivIcon({ html: '
' + childCount + ' ' + '
', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) }); }, _bindEvents: function () {