Skip to content

Layer cluster ​

Workspace Key draft workspace layer mapp cluster

layer.cluster clusters point features either in the browser by pixel distance or in PostGIS by grid resolution; use for dense point layers.

Resource and sources

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.

  • resolution must be a number greater than 0, and srid must not be "4326".
  • label names 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 geom and srid and returns nothing without a map extent.
  • The 4326 check compares the string "4326"; a numeric srid of 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 keep resolution × 40075016.68 / 2^maxZoom ≥ 1.

Examples ​

Browser clustering of the devdb retail points within 15 pixels.

json
{
  "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" }
      }
    }
  }
}

  1. layer/format/vector.mjs clusterConfig ↩︎

  2. templates/cluster.js and cluster_hex.js ↩︎

XYZ v5.1.0. Generated from knowledge/ at dd7a6fa27736502733499c1bf485f15659b10338. Concepts marked draft are not reviewed.