Skip to content

Commit cc8758a

Browse files
author
Frederik Fröling
committed
chore: add parameter to switch to geo_hash algo with a certain number of visible items
1 parent 4c9bbe9 commit cc8758a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/src/cluster_manager.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ClusterManager<T extends ClusterItem> {
2121
{Future<Marker> Function(Cluster<T>)? markerBuilder,
2222
this.levels = const [1, 4.25, 6.75, 8.25, 11.5, 14.5, 16.0, 16.5, 20.0],
2323
this.extraPercent = 0.5,
24+
this.maxItemsForMaxDistAlgo = 200,
2425
this.clusterAlgorithm = ClusterAlgorithm.GEOHASH,
2526
this.maxDistParams,
2627
this.stopClusteringZoom})
@@ -30,6 +31,9 @@ class ClusterManager<T extends ClusterItem> {
3031
/// Method to build markers
3132
final Future<Marker> Function(Cluster<T>) markerBuilder;
3233

34+
// Num of Items to switch from MAX_DIST algo to GEOHASH
35+
final int maxItemsForMaxDistAlgo;
36+
3337
/// Function to update Markers on Google Map
3438
final void Function(Set<Marker>) updateMarkers;
3539

@@ -124,7 +128,8 @@ class ClusterManager<T extends ClusterItem> {
124128
if (stopClusteringZoom != null && _zoom >= stopClusteringZoom!)
125129
return visibleItems.map((i) => Cluster<T>.fromItems([i])).toList();
126130

127-
if (clusterAlgorithm == ClusterAlgorithm.GEOHASH) {
131+
if (clusterAlgorithm == ClusterAlgorithm.GEOHASH ||
132+
visibleItems.length >= maxItemsForMaxDistAlgo) {
128133
int level = _findLevel(levels);
129134
List<Cluster<T>> markers = _computeClusters(
130135
visibleItems, List.empty(growable: true),
@@ -183,7 +188,8 @@ class ClusterManager<T extends ClusterItem> {
183188
return 1;
184189
}
185190

186-
List<Cluster<T>> _computeClustersWithMaxDist(List<T> inputItems, double zoom) {
191+
List<Cluster<T>> _computeClustersWithMaxDist(
192+
List<T> inputItems, double zoom) {
187193
MaxDistClustering<T> scanner = MaxDistClustering(
188194
epsilon: maxDistParams?.epsilon ?? 20,
189195
);

0 commit comments

Comments
 (0)