supercluster_rs/
options.rs

1/// Options for Supercluster generation
2#[derive(Debug, Clone, Copy)]
3pub struct SuperclusterOptions {
4    /// Minimum zoom level at which clusters are generated.
5    ///
6    /// Defaults to `0`.
7    pub min_zoom: usize,
8
9    /// Maximum zoom level at which clusters are generated.
10    ///
11    /// Defaults to `16`.
12    pub max_zoom: usize,
13
14    /// Minimum number of points to form a cluster.
15    ///
16    /// Defaults to `2`.
17    pub min_points: usize,
18
19    /// Cluster radius, in pixels.
20    ///
21    /// Defaults to `40`.
22    pub radius: f64,
23
24    /// Tile extent. Radius is calculated relative to this value.
25    ///
26    /// Defaults to `512`.
27    pub extent: f64,
28
29    /// Size of the KD-tree leaf node. Affects performance.
30    ///
31    /// Defaults to `64`.
32    pub node_size: usize,
33}
34
35impl SuperclusterOptions {
36    pub fn new() -> Self {
37        Default::default()
38    }
39
40    pub fn with_min_zoom(self, min_zoom: usize) -> Self {
41        SuperclusterOptions { min_zoom, ..self }
42    }
43    pub fn with_max_zoom(self, max_zoom: usize) -> Self {
44        SuperclusterOptions { max_zoom, ..self }
45    }
46    pub fn with_min_points(self, min_points: usize) -> Self {
47        SuperclusterOptions { min_points, ..self }
48    }
49    pub fn with_radius(self, radius: f64) -> Self {
50        SuperclusterOptions { radius, ..self }
51    }
52    pub fn with_extent(self, extent: f64) -> Self {
53        SuperclusterOptions { extent, ..self }
54    }
55    pub fn with_node_size(self, node_size: usize) -> Self {
56        SuperclusterOptions { node_size, ..self }
57    }
58}
59
60impl Default for SuperclusterOptions {
61    fn default() -> Self {
62        Self {
63            min_zoom: 0,
64            max_zoom: 16,
65            min_points: 2,
66            radius: 40.0,
67            extent: 512.0,
68            node_size: 64,
69        }
70    }
71}