From 1e6128604a1bd4f2051439beacfdaf713b5461d6 Mon Sep 17 00:00:00 2001 From: Maximilian Schaum <74653168+ixam1@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:08:22 +0100 Subject: [PATCH 1/2] Prevent unnecessary rerendering of not changed clusters --- src/markerclusterer.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/markerclusterer.ts b/src/markerclusterer.ts index 6da5eb2e..a2611707 100644 --- a/src/markerclusterer.ts +++ b/src/markerclusterer.ts @@ -179,7 +179,8 @@ export class MarkerClusterer extends OverlayViewSafe { }); // Allow algorithms to return flag on whether the clusters/markers have changed. - if (changed || changed == undefined) { + // But if the cluster amount hasnt changed dont rerender unnecessarily, since nothing has changed + if (clusters.length !== this.clusters.length && (changed || changed == undefined)) { // Accumulate the markers of the clusters composed of a single marker. // Those clusters directly use the marker. // Clusters with more than one markers use a group marker generated by a renderer. @@ -207,15 +208,15 @@ export class MarkerClusterer extends OverlayViewSafe { // Delay the removal of old group markers to avoid flickering. groupMarkers.push(cluster.marker); } - } - this.clusters = clusters; - this.renderClusters(); + this.clusters = clusters; + this.renderClusters(); - // Delayed removal of the markers of the former groups. - requestAnimationFrame(() => - groupMarkers.forEach((marker) => MarkerUtils.setMap(marker, null)) - ); + // Delayed removal of the markers of the former groups. + requestAnimationFrame(() => + groupMarkers.forEach((marker) => MarkerUtils.setMap(marker, null)) + ); + } } google.maps.event.trigger( this, From 155a7324595e03330962e68f3fcd0403f62e2570 Mon Sep 17 00:00:00 2001 From: Maximilian Schaum <74653168+ixam1@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:23:20 +0100 Subject: [PATCH 2/2] fix: prevent unnecessary rerendering --- src/markerclusterer.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/markerclusterer.ts b/src/markerclusterer.ts index a2611707..141a4242 100644 --- a/src/markerclusterer.ts +++ b/src/markerclusterer.ts @@ -208,15 +208,15 @@ export class MarkerClusterer extends OverlayViewSafe { // Delay the removal of old group markers to avoid flickering. groupMarkers.push(cluster.marker); } - - this.clusters = clusters; - this.renderClusters(); - - // Delayed removal of the markers of the former groups. - requestAnimationFrame(() => - groupMarkers.forEach((marker) => MarkerUtils.setMap(marker, null)) - ); } + + this.clusters = clusters; + this.renderClusters(); + + // Delayed removal of the markers of the former groups. + requestAnimationFrame(() => + groupMarkers.forEach((marker) => MarkerUtils.setMap(marker, null)) + ); } google.maps.event.trigger( this,