Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/codempireio/react-native-cluster-map

ReactNative MapView clustering component for iOS + Android
https://github.com/codempireio/react-native-cluster-map

cluster clustering custom-cluster-marker google-maps map-cluster marker react react-native supercluser typescript

Last synced: 18 days ago
JSON representation

ReactNative MapView clustering component for iOS + Android

Awesome Lists containing this project

README

        

# react-native-cluster-map

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()
[![Version](https://img.shields.io/npm/v/react-native-cluster-map.svg)](https://www.npmjs.com/package/react-native-cluster-map)
[![npm](https://img.shields.io/npm/dt/react-native-cluster-map.svg)](https://www.npmjs.com/package/react-native-cluster-map)
[![Email](https://img.shields.io/badge/contact-CODEMPIRE-blue.svg?style=flat)](mailto:[email protected])

React Native MapView clustering component for iOS + Android

---

Made by [CODEMPIRE](http://codempire.io/)

## Examples

| Zoom in | Zoom out |
| --------------------------------------------------------- | ----------------------------------------------------------------------- |
| ![Example zoom out](demo/images/zoom-in.gif) | ![Example zoom in](demo/images/zoom-out.gif) |
| **Cluster Expand** | **Nested Cluster Expand** |
| ![Example cluster expand](demo/images/cluster-expand.gif) | ![Example nested cluster expand](demo/images/nested-cluster-expand.gif) |

## Installation

1. Install [`react-native-maps`](https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md)

2. Install this component

```bash
npm install --save react-native-cluster-map
```

## Usage

```javascript
import { Marker } from 'react-native-maps';
import { ClusterMap } from 'react-native-cluster-map';




;
```

### Custom Cluster Marker

You can customize cluster marker with **renderClusterMarker** prop

> _MyMap.jsx_

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

// ...

renderCustomClusterMarker = (count) =>

render () {
const { markers, region } = this.state;
return (

{markers.map((marker) => (

))}

)
}

```

> _MyCluster.jsx_

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

export const MyCluster = (props) => {
const { count } = props;
return (

{count}

);
};

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

### Result

![Custom Marker Example](demo/images/custom-marker.png)

## Props

| Props | Type | Default value | Note |
| ------------------------ | ------------ | ----------------------------------------------------- | ---------------------------------------- |
| **superClusterOptions** | _Options_ | { radius: 16, maxZoom: 15, minZoom: 1, nodeSize: 16 } | SuperCluster lib options |
| **isClusterExpandClick** | _boolean_ | true | Enables cluster zoom on click |
| **region** | _Region_ | **_required_** | Google Map Region |
| **priorityMarker** | _ReactNode_ | null | Marker which will be outside of clusters |
| **renderClusterMarker** | (_object_):ReactNode | undefined | Returns cluster marker component |
| **clusterMarkerProps** | _object_ | undefined | Additional ClusterMarker props |
| **provider** | _'google'_ or _null_ | 'google' | Map provider. If null will use the platform default one (Google Maps for Android and MapKit for iOS) |
| **style** | _StyleProp_ | absoluteFillObject | Styling for MapView |

---

## Children Props

| Props | Type | Default | Note |
| ------------------------ | ------------ | ----------------------------------------------------- | ---------------------------------------- |
| **isOutsideCluster** | _boolean_ | false | Prevent child from clusterization. **_Required_** for not a Marker children (e.g. Polygon, Polyline, Circle) |

---

> Also contains react-native-maps [\ Props](https://github.com/react-native-community/react-native-maps/blob/master/docs/mapview.md#props)

## Events

| Event Name | Returns | Notes |
| ------------------ | ---------------------------------------------------------------- | ------------------------------------------------------------------------- |
| **onClusterClick** | ({ clusterId: number, coordinate : LatLng }, children: Marker[]) | Callback that is called when the user pressed on the **_cluster_** marker |
| **onZoomChange** | void | Callback that is called with updated map zoom in **number** |

---

> Also contains react-native-maps [\ Events](https://github.com/react-native-community/react-native-maps/blob/master/docs/mapview.md#events)