This module wraps AirBnB's react-native-maps and uses MapBox's SuperCluster as clustering engine.
This module wants to provide a stable and performing solution for maps clustering in React Native. In particular, our efforts are focused on integrating SuperCluster methods into React's state/lifecycle events, ensuring stability, compatibility and great performance.
npm i --save react-native-maps-super-cluster
NOTES:
- the prop
keyof the markers rendered throughrenderMarkershould not be left up to React. Instead, we strongly suggest to use anidin order the have unique keys while still taking advantage of React's recycling.
import React, { Component } from 'react'
import { Marker } from 'react-native-maps'
import ClusteredMapView from 'react-native-maps-super-cluster'
const INIT_REGION = {
latitude: 41.8962667,
longitude: 11.3340056,
latitudeDelta: 12,
longitudeDelta: 12
}
export default class MyClusteredMapView extends Component {
...
renderMarker = (data) => <Marker key={data.id || Math.random()} coordinate={data.location} />
...
render() {
return (
<ClusteredMapView
style={{flex: 1}}
data={this.state.data}
initialRegion={INIT_REGION}
renderMarker={this.renderMarker}
{/* cluster text */}
textStyle={{ color: '#65bc46' }}
{/* cluster container */}
containerStyle={{backgroundColor: 'white', borderColor: '#65bc46'}} />
)
}
}| Name | Type | Required | Default | Note |
|---|---|---|---|---|
| width | Number | false | window width | map's width |
| height | Number | false | window height | map's height |
| clusterInitialDimension | Number | false | 30 | cluster view base dimension in dpi/ppi. Clusters size grows with amount of clustered markers |
| data | Array | true | undefined | Objects must have an attribute representing a GeoPoint, i.e. { latitude: x, longitude: y } |
| onExplode | Function | false | undefined | TODO |
| onImplode | Function | false | undefined | TODO |
| onClusterPress | Function | false | undefined | |
| renderMarker | Function | false | undefined | Must return a react-native-maps' Marker component |
| animateClusters | Bool | false | true | Animate imploding/exploding of clusters' markers and clusters size change. Works only on iOS. |
| textStyle | Object | false | NovaLab Brand colors | Style of the Text component used for clusters counters |
| containerStyle | Object | false | NovaLab Brand colors | Style of the clusters View |
- dynamically enable/disable clustering
- trigger events on clusters implode/explode
- enhance
isZoomLevelChangedmath - enhance clusters press-to-zoom math
See our License for more information.
