getAnnotations method

Future<List<AppleCluster<T>>> getAnnotations()

Implementation

Future<List<AppleCluster<T>>> getAnnotations() async {
  if (_mapController == null) return List.empty();

  final mapBounds = await _mapController!.getVisibleRegion();
  final inflatedBounds = switch (clusterAlgorithm) {
    ClusterAlgorithmApple.geoHash => _inflateBounds(mapBounds),
    _ => mapBounds,
  };

  final visibleItems = items.where((i) => inflatedBounds.contains(i.location)).toList();

  if (stopClusteringZoom != null && _zoom >= stopClusteringZoom!) {
    return visibleItems.map((i) => AppleCluster<T>.fromItems([i])).toList();
  }

  List<AppleCluster<T>> annotations;

  if (clusterAlgorithm == ClusterAlgorithmApple.geoHash || visibleItems.length >= maxItemsForMaxDistAlgo) {
    final level = _findLevel(levels);
    annotations = _computeClusters(visibleItems, List.empty(growable: true), level: level);
  } else {
    annotations = _computeClustersWithMaxDist(visibleItems, _zoom);
  }

  return annotations;
}