Skip to main content

Module cluster

Module cluster 

Source
Expand description

Point clustering engine (supercluster-equivalent).

Provides zoom-based point clustering for GeoJSON point sources, matching the behaviour of MapLibre/Mapbox’s supercluster algorithm.

§Algorithm

  1. All input points are projected to a [0, 1) Mercator plane.
  2. At each zoom level from max_zoom down to min_zoom, a spatial grid is used to find nearby points within radius (in screen-pixel units, converted to world-space for each zoom).
  3. Nearby points are merged into cluster nodes. Each cluster carries point_count and optional aggregated properties.
  4. Querying for a specific zoom returns a mix of cluster features (for merged groups) and individual point features (for isolated points or at zooms above max_zoom).

§Usage

use rustial_engine::cluster::{PointCluster, ClusterOptions};
use rustial_engine::geometry::FeatureCollection;

let options = ClusterOptions {
    radius: 50.0,
    max_zoom: 16,
    min_zoom: 0,
    min_points: 2,
    ..Default::default()
};
let mut cluster = PointCluster::new(options);
cluster.load(&features);
let clustered = cluster.get_clusters_for_zoom(5);

Structs§

ClusterOptions
Options controlling point-clustering behaviour.
PointCluster
A zoom-based point clustering index.