Socket
Socket
Sign inDemoInstall

react-native-map-markerclustering2

Package Overview
Dependencies
530
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-map-markerclustering2

Add marker clustering in airbnb/react-native-map


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
23.0 kB
Created
Weekly downloads
 

Readme

Source

react-native-map-markerClustering

A react-native module to add map marker clustering in airbnb/react-native-map for both iOS and Android.

Dependencies

  react: >=15.4.0
  react-native >=0.40
  react-native-maps >=0.15.0

Installation

Make sure you have react-native-maps installed and react native linking is done. If not then follow this for Installation instructions.

Or do this :

Using npm
npm install react-native-maps --save
react-native link react-native-maps
Using Yarn
yarn add react-native-maps 
react-native link react-native-maps

Install react-native-map-markerclustering

Using npm
npm install react-native-map-markerclustering --save
Using Yarn
yarn add react-native-map-markerclustering

How to use?

  1. Import MapView from react-native-map-markerclustering and Marker from react-native-maps
import MapView from 'react-native-map-markerclustering';
import Marker from 'react-native-maps';
  1. Inside render use MapView and Marker like this:
        <MapView
            region={{ latitude: 28.5,
                      longitude: 25.2,
                      latitudeDelta: 6.5,
                      longitudeDelta: 6.5}}
            style={{width: 320, height: 500}}>
            <Marker coordinate={{latitude: 28.0, longitude: 24.2}} />
            <Marker coordinate={{latitude: 25.7, longitude: 24.7}} />
            <Marker coordinate={{latitude: 28.1, longitude: 24.4}} />
            <Marker coordinate={{latitude: 29.6, longitude: 24.3}} />
            <Marker coordinate={{latitude: 27.6, longitude: 24.0}} />
            <Marker coordinate={{latitude: 26.1, longitude: 24.8}} />
            <Marker coordinate={{latitude: 28.9, longitude: 25.9}} />
            <Marker coordinate={{latitude: 30.2, longitude: 25.0}} />
        </MapView>

Extra Props

All the props of MapView of react-native-maps cab be used except onRegionChangeComplete as it overwrites this.

PropTypeDefault ValueDescription
clusterColorString#F5F5F5Background color of cluster.
clusterTextColorString#FF5252Color of text in cluster.
clusterBorderColorString#FF5252Color of border. Set to transparent if you don't want borders.
clusterBorderWidthInt1Width of border. Set to 0 if you don't want borders.
onClusterPressFunctionnullAllows you to control cluster on click event. Function returns coordinate of cluster.
customClusterMarkerDesignHTML elementnullCustom background for your clusters.
Example 1:
        <MapView
    clusterColor = '#ACB234'
    clusterTextColor = '#FFFFFF'
    clusterBorderColor = '#2A2A2A'
    clusterBorderWidth = {2}
    region={{latitude: 28.5, longitude: 25.2,
             latitudeDelta: 6.5, longitudeDelta: 6.5}}
            style={{width: 320, height: 500}}>
            <Marker coordinate={{latitude: 28.0, longitude: 24.2}} />
            <Marker coordinate={{latitude: 25.7, longitude: 24.7}} />
            <Marker coordinate={{latitude: 28.1, longitude: 24.4}} />
            <Marker coordinate={{latitude: 29.6, longitude: 24.3}} />
            <Marker coordinate={{latitude: 27.6, longitude: 24.0}} />
            <Marker coordinate={{latitude: 26.1, longitude: 24.8}} />
            <Marker coordinate={{latitude: 28.9, longitude: 25.9}} />
            <Marker coordinate={{latitude: 30.2, longitude: 25.0}} />
        </MapView>
Exapmle 2 (onClusterPress) :
    <MapView
        ref = {(ref)=>mapView=ref}
        onClusterPress={(coordinate)=>{
            this.animate(coordinate);
        }}
       ...
    </MapView>
Example 3 (customClusterMarkerDesign) :
    <MapView
        customClusterMarkerDesign =
        {(<Image style = {{width: imageWidth, height:imageHeight}}
        source = {require('./customCluster.png')}/>)}
           ...
    </MapView>

For using ref

Inside render
    <MapView
            ref = {(ref)=>mapView=ref}
            ...
    </MapView>
Sample (to use animateToRegion)
    animate(){
       let r = {
            latitude: 42.5,
            longitude: 15.2,
            latitudeDelta: 7.5,
            longitudeDelta: 7.5,
        };
        mapView._root.animateToRegion(r, 2000);
    }

Keywords

FAQs

Last updated on 23 Sep 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc