Index of every page on this site: llms.txt
All skills
gmi-software avatar

/react-native-better-clustering

@443959a
Run it yourself

Expert guide to react-native-better-clustering — a drop-in clustered MapView for react-native-maps backed by a C++ supercluster engine over Nitro/JSI. Use when installing, configuring, or debugging it; when clustering is slow, wrong, or flickering; when handling thousands of map markers; when migrating from react-native-map-clustering or react-native-clusterer; and when changing the library's TypeScript, C++, or Nitro specs. Also use before writing any performance claim about map clustering, pan, zoom, or marker frame rate.

  • 11 files
  • 102.9 KB
  • MIT
  • Updated 3 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/gmi-software/better-skills/react-native-better-clustering

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesapi.md

≈2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

API reference

Public surface only. Signatures from package/src. Do not invent props.

Deep aggregation (reducers, packing, MapView denial): aggregation.md. Rendering identity: rendering.md. Migration: migration.md. Thread safety: architecture.md.

Drop-in MapView (default)

import MapView from 'react-native-better-clustering'
import { Marker } from 'react-native-maps'

<MapView
  style={{ flex: 1 }}
  initialRegion={{
    latitude: 52.23,
    longitude: 21.01,
    latitudeDelta: 0.35,
    longitudeDelta: 0.35,
  }}
  radius={56}
  minPoints={2}
  clusterColor="#0F52FF"
  clusterTextColor="#FFFFFF"
  spiralEnabled
  animationEnabled
  clusterUpdateIntervalMs={100}
  onClusterPress={(cluster, markers) => {
    cluster.properties.point_count
    markers.length
  }}
>
  {markers}
  <Marker cluster={false} coordinate={{ latitude: 52.23, longitude: 21.01 }} />
</MapView>

markers should be a stable element list (rendering.md). Migration from react-native-map-clustering is this import plus the same Marker children (ADR 0001).

/compat is the same module as the root export.

clusterProperties is NOT a MapView prop

`clusterProperties` is supported by the lower-level clustering APIs,
but it is NOT a prop accepted by the root MapView compatibility API.

Do not write <MapView clusterProperties={...} /> — compat/MapView.tsx never reads that prop; clustererOptions only forwards radius, maxZoom, minZoom, minPoints, extent, nodeSize.

Use aggregation via /engine (Supercluster options) or /hooks (useClusterer options). Overview below; full detail: aggregation.md.

ClusteredMapViewProps extras (on top of RN Maps MapViewProps)

radius, maxZoom, minZoom, minPoints, extent, nodeSize, edgePadding, onClusterPress, onRegionChangeComplete (adds markers as third arg), onMarkersChange, preserveClusterPressBehavior, clusteringEnabled, clusterColor, clusterTextColor, clusterFontFamily, superClusterRef, mapRef, spiralEnabled, spiderLineColor, renderCluster, selectedClusterId, selectedClusterColor, animationEnabled, layoutAnimationConf, clusterFadeInDuration, tracksViewChanges, width, height, clusterUpdateIntervalMs.

RN Maps props (including provider) are forwarded via ...restProps.

Defaults: see compat/MapView.tsx. Engine-only defaults (radius: 40) apply to /engine and /hooks, not to MapView radius.

edgePadding is a MapView / fit-related prop. It does not drive the clustering query bbox — that comes from regionToBBox / viewport math (algo.md).

Measuring visible features (k)

onMarkersChange receives the same stabilized clusters array the map renders — use markers.length as k (performance.md).

onRegionChangeComplete on RN Maps is omitted from the extends and re-declared with the extra markers argument.

Custom cluster bubble

import MapView, { type RenderClusterProps } from 'react-native-better-clustering'
import { Marker } from 'react-native-maps'
import { useCallback } from 'react'

const renderCluster = useCallback((cluster: RenderClusterProps) => {
  const [longitude, latitude] = cluster.geometry.coordinates
  return (
    <Marker
      coordinate={{ latitude, longitude }}
      onPress={cluster.onPress}
      tracksViewChanges={false}
    >
      {/* bubble */}
    </Marker>
  )
}, [])

<MapView renderCluster={renderCluster}>{markers}</MapView>

RenderClusterProps is ClusterFeature plus onPress, clusterColor, clusterTextColor, tracksViewChanges. Custom render skips default fade (clusterFadeInDuration ignored).

useClusterer (you own MapView)

import MapView, { Marker } from 'react-native-maps'
import { useClusterer } from 'react-native-better-clustering/hooks'
import { isClusterFeature } from 'react-native-better-clustering/geojson'

const [clusters, supercluster] = useClusterer(data, mapDimensions, region, {
  radius: 40,
  minPoints: 2,
})

// clusters: PointFeature | ClusterFeature
// supercluster.getClusterExpansionZoom(id)

data is PointFeature[]. Empty until loaded. Returns [clusters, supercluster] — not a third isLoaded value. Use supercluster.isLoaded or empty clusters rather than querying blindly.

Clusterer component

import { Clusterer } from 'react-native-better-clustering/clusterer'

<Clusterer
  data={data}
  region={region}
  mapDimensions={mapDimensions}
  renderItem={(feature) => <Marker ... />}
/>

Undocumented subpath (ADR 0001); still exported. renderItem belongs in useCallback.

Supercluster / createClusterEngine

import {
  Supercluster,
  createClusterEngine,
} from 'react-native-better-clustering/engine'
import { packPoints } from 'react-native-better-clustering/utils'

const clusterer = new Supercluster({ radius: 40, minZoom: 1, maxZoom: 20 })
await clusterer.loadAsync(features)
const visible = clusterer.getClustersFromRegion(region, { width, height })
clusterer.destroy()

const engine = createClusterEngine()
engine.setOptions({
  radius: 40,
  minPoints: 2,
  minZoom: 1,
  maxZoom: 20,
  extent: 512,
  nodeSize: 64,
  reducers: [],
})
engine.setPoints(packPoints(coordinates).buffer)
await engine.buildAsync()
const nodes = engine.getClusters({
  north, south, east, west, zoom,
})

After build / buildAsync, engine.isBuilt is true and engine.pointCount is the number of valid loaded points. Query before that throws.

Supercluster query helpers (throw if engine is still null; getClustersFromRegion returns [] while !isLoaded):

clusterer.getChildren(id)
clusterer.getLeaves(id, 10, 0)      // default limit 10
clusterer.getAllLeaves(id)          // limit 0 = unlimited; sync on the JS thread
clusterer.getClusterExpansionZoom(id)
clusterer.getClusterExpansionRegion(id)
clusterer.isLoaded                  // engine?.isBuilt ?? false

getAllLeaves is unbounded. Compat cluster press uses it — a cluster of tens of thousands of leaves will hitch on tap.

Lifecycle: setOptions → setPoints → build/buildAsync → query. load/loadAsync once per Supercluster instance.

Do not run concurrent buildAsync and queries on the same createClusterEngine() instance (architecture.md). For uninterrupted querying during a rebuild, use the dual-engine swap pattern there.

Aggregation overview

clusterProperties (JS wrapper / useClusterer options — not root MapView): { source, key?, reduce: 'sum' | 'min' | 'max' }[]. Arbitrary JS reducers are not supported.

const [clusters] = useClusterer(data, dimensions, region, {
  clusterProperties: [
    { source: 'price', reduce: 'sum' },
    { source: 'price', key: 'maxPrice', reduce: 'max' },
  ],
})
// cluster.properties.price / maxPrice on cluster features

source is a dot path into leaf properties. key defaults to the last path segment. Values must be numeric. Keep the options array stable or memoize it. Full pipeline: aggregation.md.

GeoJSON helper

import { coordsToGeoJSONFeature, isClusterFeature } from 'react-native-better-clustering/geojson'

const feature = coordsToGeoJSONFeature(
  { latitude: 52.23, longitude: 21.01 },
  { id: 'p1' }
)

Types

  • ClusterFeature.properties: cluster: true, cluster_id, point_count, point_count_abbreviated, getExpansionRegion().
  • EngineClusterNode: id, latitude, longitude, count, isCluster, parentId, pointIndex, values.
  • Leaf pointIndex is the pack index (array index into the loaded feature list).

Viewport handling in-app

Prefer compat MapView region plumbing (throttled). If you drive useClusterer yourself, put throttled region in state (clusterUpdateIntervalMs equivalent) and keep data out of that setState.

TypeScript

Package react-native condition points at src/index.ts; types at lib/index.d.ts. Subpaths are listed in exports. There is no ./types export.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 443959a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 3 months ago
Other metadata
metadata
{
  "package": "react-native-better-clustering",
  "version": "1.0.0",
  "commit": "7c7d659046a3d1bb8b7d4cb06a94f6e0d509862e",
  "verified": "2026-08-21",
  "repository": "https://github.com/gmi-software/react-native-better-clustering",
  "audience": "library users and library contributors",
  "tags": "react-native, clustering, maps, markers, geospatial, supercluster, nitro, jsi, cpp, performance, ios, android, expo"
}

README badge

README badge for gmi-software/better-skills/react-native-better-clustering