Layer cluster
A point layer clusters in one of two ways. Set exactly one of distance and resolution; with both or neither the cluster configuration is ignored with a warning.[1]
Browser clustering with distance: all features are loaded and Openlayers merges features closer than distance pixels. A distance below 1 removes the cluster configuration. Use it for layers with up to a few thousand features.
Database clustering with resolution: PostGIS aggregates features on a grid whose cell size is resolution times the tile width at the current zoom. The MAPP library then sets format to cluster, params.viewport and params.z, and the query template to cluster, or cluster_hex with hexgrid.[2] Use it for large tables.
resolutionmust be a number greater than 0, andsridmust not be"4326".labelnames the field shown for a cluster.- Cluster icons and their scaling belong to the layer style.
Pitfalls
- Database clustering always restricts queries to the viewport, so it needs
geomandsridand returns nothing without a map extent. - The
4326check compares the string"4326"; a numericsridof 4326 passes it and clusters degrees as if they were metres. - The grid cell is
resolution× 40075016.68 / 2^z metres, rounded down to an integer. A cell below 1 metre at the deepest zoom divides by zero in the query, so keepresolution× 40075016.68 / 2^maxZoom ≥ 1.
Examples
Browser clustering of the devdb retail points within 15 pixels.
{
"dbs": "DEVDB",
"locale": {
"layers": {
"retail_points": {
"display": true,
"format": "wkt",
"table": "geodata.uk_glx_open_retail_points",
"geom": "geom_p_4326",
"srid": "4326",
"qID": "id",
"cluster": { "distance": 15, "label": "store_name" }
}
}
}
}