clusters method

List<T> clusters(
  1. List<double> bbox,
  2. int zoom
)

Returns a list of clusters that reside within the bounding box, where bbox = southwestLng, southwestLat, northeastLng, northeastLat.

The list is comprised of the original points passed into the constructor or clusters of points (and perhaps other clusters) produced by createCluster().

Implementation

List<T> clusters(List<double> bbox, int zoom) {
  var minLng = ((bbox[0] + 180) % 360 + 360) % 360 - 180;
  var minLat = math.max<double>(-90, math.min(90, bbox[1]));
  var maxLng =
      bbox[2] == 180 ? 180.0 : ((bbox[2] + 180) % 360 + 360) % 360 - 180;
  var maxLat = math.max<double>(-90, math.min(90, bbox[3]));

  if (bbox[2] - bbox[0] >= 360) {
    minLng = -180;
    maxLng = 180.0;
  } else if (minLng > maxLng) {
    var easternHemisphere = clusters([minLng, minLat, 180, maxLat], zoom);
    var westernHemisphere = clusters([-180, minLat, maxLng, maxLat], zoom);

    easternHemisphere.addAll(westernHemisphere);

    return easternHemisphere;
  }

  var tree = _trees[_limitZoom(zoom)]!;
  List<int?> ids =
      tree.range(_lngX(minLng), _latY(maxLat), _lngX(maxLng), _latY(minLat));

  var result = <T>[];

  for (var id in ids) {
    var c = tree.points[id!];

    result.add((c.pointsSize != null && c.pointsSize! > 0)
        ? _createCluster!(c, _xLng(c.x!), _yLat(c.y!))
        : _points[c.index!]);
  }

  return result;
}