Skip to content

Commit

Permalink
Prevent unnecessary rerendering of not changed clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
ixam1 authored Nov 16, 2023
1 parent b084ba4 commit 1e61286
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/markerclusterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1e61286

Please sign in to comment.