getCluster function

FeatureCollection<GeometryObject> getCluster(
  1. FeatureCollection<GeometryObject> geojson,
  2. dynamic filter
)

Get Cluster Takes a FeatureCollection<Feature> and a dynamic filter used on GeoJSON properties to get Cluster. Returns a FeatureCollection single cluster filtered by GeoJSON Properties For example:

var geojson = FeatureCollection<Point>(features: [
   Feature(
     geometry: Point(coordinates: Position.of([10, 10])),
     properties: {'marker-symbol': 'circle'},
   ),
   Feature(
     geometry: Point(coordinates: Position.of([20, 20])),
     properties: {'marker-symbol': 'circle'},
   ),
   Feature(
     geometry: Point(coordinates: Position.of([30, 30])),
     properties: {'marker-symbol': 'square'},
   ),
   Feature(
     geometry: Point(coordinates: Position.of([40, 40])),
     properties: {'marker-symbol': 'triangle'},
   ),
 ]);

// Creates a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = clustersKmeans(geojson);

// Retrieves first cluster (0)
var cluster = getCluster(clustered, {cluster: 0});
//= cluster

// Retrieves cluster based on custom properties
getCluster(clustered, {'marker-symbol': 'circle'}).length;
//= 2
getCluster(clustered, {'marker-symbol': 'square'}).length;
//= 1

Implementation

FeatureCollection getCluster(FeatureCollection geojson, dynamic filter) {
  // Filter Features
  List<Feature> features = [];
  featureEach(geojson, (feature, i) {
    if (applyFilter(feature.properties, filter)) features.add(feature);
  });
  return FeatureCollection(features: features);
}