1.0.6 • Published 5 years ago

react-native-maps-clusterize v1.0.6

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

react-native-maps-clusterize

license Version npm Email

React Native MapView clustering component for iOS + Android


Made by CODEMPIRE

Examples

Zoom inZoom out
Example zoom outExample zoom in
Cluster ExpandNested Cluster Expand
Example cluster expandExample nested cluster expand

Installation

  1. Install react-native-maps

  2. Install this component

npm install --save react-native-maps-clusterize

Usage

import { Marker } from "react-native-maps";
import { ClusterMap } from "react-native-maps-clusterize";

<ClusterMap
  region={{
    latitude: 37.78825,
    longitude: -122.4324,
    latitudeDelta: 0.0922,
    longitudeDelta: 0.0421,
  }}
>
  <Marker coordinate={{ latitude:37.78725, longitude: -122.434 }} />
  <Marker coordinate={{ latitude:37.789, longitude: -122.431 }} />
  <Marker coordinate={{ latitude:37.78825, longitude:-122.4324 }} />
</ClusterMap>

Custom Cluster Marker

You can customize cluster marker with renderClusterMarker prop

MyMap.jsx

import { Marker } from "react-native-maps";
import { MyCluster } from "./MyCluster";

// ...

renderCustomClusterMarker = (count) => <MyCluster count={count} />

render () {
  const { markers, region } = this.state;
  return (
    <ClusterMap
      renderClusterMarker={this.renderCustomClusterMarker}
      region={region}
    >
      {markers.map((marker) => (
          <Marker {...marker} />
      ))}
    <ClusterMap>
  )
}

MyCluster.jsx

import * as React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export const MyCluster = (props) => {
  const { count } = props;
  return (
    <View style={styles}>
      <Text>{count}</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  width: 50,
  height: 50,
  borderRadius: 25,
  backgroundColor: 'red',
  justifyContent: 'center',
  alignItems: 'center'
})

Result

Custom Marker Example

Props

PropsTypeDefaultNote
superClusterOptionsOptions{ radius: 16, maxZoom: 15, minZoom: 1, nodeSize: 16 }SuperCluster lib options
isClusterExpandClickbooleantrueEnables cluster zoom on click
regionRegionrequiredGoogle Map Region
priorityMarkerReactNodenullMarker which will be outside of clusters
renderClusterMarker():ReactNode() => { return \ }Returns cluster marker component
styleStylePropabsoluteFillObjectStyling for MapView

Also contains react-native-maps \ Props

Events

Event NameReturnsNotes
onClusterClickvoidCallback that is called when the user pressed on the cluster marker
onZoomChangevoidCallback that is called with updated map zoom in number

Also contains react-native-maps \ Events