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,