Skip to main content

Types

Main export​

import type {
ClusteredMapViewProps,
RenderClusterProps,
} from 'react-native-better-clustering'

ClusteredMapViewProps extends react-native-maps MapViewProps with clustering options (radius, minPoints, onClusterPress, renderCluster, etc.).

RenderClusterProps is passed to renderCluster: a ClusterFeature plus onPress, clusterColor, clusterTextColor, clusterFontFamily, and tracksViewChanges.

GeoJSON types (/geojson)​

import type {
PointFeature,
ClusterFeature,
PointOrClusterFeature,
BBox,
} from 'react-native-better-clustering/geojson'

Cluster properties include cluster, cluster_id, point_count, point_count_abbreviated, and getExpansionRegion().

Engine types (/engine)​

import type {
SuperclusterOptions,
ClusterPropertyConfig,
MapDimensions,
} from 'react-native-better-clustering/engine'

SuperclusterOptions​

OptionDefaultDescription
radius40Cluster radius in pixels
minZoom1Min zoom for clustering
maxZoom20Max zoom for clustering. Queries above it return every point on its own (see Above maxZoom)
minPoints2Min points to form a cluster
extent512Tile extent used for projection math (see note)
nodeSize64KD-tree leaf size
clusterProperties[]Numeric point properties to aggregate into each cluster: { source, key?, reduce }, where reduce is 'sum', 'min' or 'max'. supercluster's map and reduce functions are not supported
viewportTileSizeextentTile size used to pick a zoom from a map region (see note)

Valid values​

Loading points throws a RangeError naming the first option outside these ranges, instead of building an empty or unbounded index:

OptionMust be
radiusA finite number >= 0
minZoom, maxZoomIntegers from 0 to 30 (supercluster's limit), with minZoom <= maxZoom
extentAn integer >= 1
minPoints, nodeSize32-bit integers. Below 2 and 1 they act as 2 and 1
viewportTileSizeA finite number > 0

useClusterer, Clusterer and MapView pass the error to onError, or throw it during render when onError is not set.

Radius and extent​

radius and extent mean exactly what they mean in supercluster: radius is the cluster radius in pixels of a tile that is extent pixels wide, so the two are read together as radius / extent. Raising extent therefore tightens clustering and lowering it loosens clustering, at the same radius.

Given the same options and zoom, this package produces the same clusters as supercluster, apart from two edge cases (points exactly on the radius boundary, and tie-breaking with minPoints above 2) described under supercluster parity.

Viewport tile size​

viewportTileSize is separate from extent. It only affects getClustersFromRegion (how a map region plus a pixel size is turned into a zoom level) and shifts the result by a whole zoom level:

ValueParity with
256react-native-map-clustering (geo-viewport's default). Correct for map dimensions in logical points, which is what onLayout reports.
512 (= extent, the default)react-native-clusterer, which passes its extent to geo-viewport. One zoom level lower.

The MapView compat layer sets 256 so a drop-in swap renders the same clusters. useClusterer and Supercluster default to extent, keeping react-native-clusterer parity; pass viewportTileSize: 256 to opt in.

Headless engine (ClusterEngine)​

Low-level Nitro hybrid object; create it via createClusterEngine() from /engine. See the headless engine guide for lifecycle, isBuilt checks, and error behavior.

import {
createClusterEngine,
type ClusterBounds,
type ClusterEngine,
type ClusterEngineOptions,
type EngineClusterNode,
type Viewport,
} from 'react-native-better-clustering/engine'

Each EngineClusterNode has minLeafId: the smallest point id among its leaves (its own id for a point). A cluster keeps it across zoom levels while it only gains or loses other leaves, so it can key the cluster's marker.

Lifecycle: setOptions → setPoints (packPoints() buffer) → build() → query. Query methods throw when isBuilt is false; setPoints throws on invalid buffers.