Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-map-clustering

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-map-clustering

React Native Map Clustering both for Android and iOS

  • 3.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
increased by6.25%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Map Clustering

React Native module that handles map clustering for you.

Works with Expo and react-native-cli 🚀

This repo is proudly sponsored by:


React Native Templates & Starter Kits and Apps for easier start.

Demo

Demo

Installation

npm install react-native-map-clustering react-native-maps --save
// yarn add react-native-map-clustering react-native-maps

Full example

import React from "react";
import MapView from "react-native-map-clustering";
import { Marker } from "react-native-maps";

const INITIAL_REGION = {
  latitude: 52.5,
  longitude: 19.2,
  latitudeDelta: 8.5,
  longitudeDelta: 8.5,
};

const App = () => (
  <MapView initialRegion={INITIAL_REGION} style={{ flex: 1 }}>
    <Marker coordinate={{ latitude: 52.4, longitude: 18.7 }} />
    <Marker coordinate={{ latitude: 52.1, longitude: 18.4 }} />
    <Marker coordinate={{ latitude: 52.6, longitude: 18.3 }} />
    <Marker coordinate={{ latitude: 51.6, longitude: 18.0 }} />
    <Marker coordinate={{ latitude: 53.1, longitude: 18.8 }} />
    <Marker coordinate={{ latitude: 52.9, longitude: 19.4 }} />
    <Marker coordinate={{ latitude: 52.2, longitude: 21 }} />
    <Marker coordinate={{ latitude: 52.4, longitude: 21 }} />
    <Marker coordinate={{ latitude: 51.8, longitude: 20 }} />
  </MapView>
);

export default App;

Props

NameTypeDefaultNote
clusterColorString#00B386Background color of cluster.
clusterTextColorString#FFFFFFColor of text in cluster.
clusterFontFamilyStringundefinedFont family of text in cluster.
onClusterPress(cluster, markers)Function() => {}Allows you to control cluster on click event. Function returns information about cluster and its markers.
tracksViewChangesBoolfalseSets whether the cluster markers should track view changes. It's turned off by default to improve cluster markers performance.
widthNumberwindow widthmap's width.
heightNumberwindow heightmap's height.
radiusNumberwindow.width * 6%SuperCluster radius.
extentNumber512SuperCluster extent.
minZoomNumber1SuperCluster minZoom.
maxZoomNumber20SuperCluster maxZoom.
minPointsNumber2SuperCluster minPoints.
preserveClusterPressBehaviorBoolfalseIf set to true, after clicking on cluster it will not be zoomed.
edgePaddingObject{ top: 50, left: 50, bottom: 50, right: 50 }Edge padding for react-native-maps's fitToCoordinates method, called in onClusterPress for fitting to pressed cluster children.
animationEnabledBooltrueAnimate imploding/exploding of clusters' markers and clusters size change. Works only on iOS.
layoutAnimationConfLayoutAnimationConfigLayoutAnimation.Presets.springLayoutAnimation.Presets.spring
onRegionChangeComplete(region, markers)Function() => {}Called when map's region changes. In return you get current region and markers data.
onMarkersChange(markers)Function() => {}Called when markers change. In return you get markers data.
superClusterRefMutableRefObject{}Return reference to supercluster library. You can read more about options it has here.
clusteringEnabledBooltrueSet true to enable and false to disable clustering.
spiralEnabledBooltrueSet true to enable and false to disable spiral view.
renderClusterFunctionundefinedEnables you to render custom cluster with custom styles and logic.
spiderLineColorString#FF0000Enables you to set color of spider line which joins spiral location with center location.

How to animate to region?

Full example of how to use animateToRegion().

import React, { useRef } from "react";
import { Button } from "react-native";
import MapView from "react-native-map-clustering";
import { Marker } from "react-native-maps";

const INITIAL_REGION = {
  latitude: 52.5,
  longitude: 19.2,
  latitudeDelta: 8.5,
  longitudeDelta: 8.5,
};

const App = () => {
  const mapRef = useRef();

  const animateToRegion = () => {
    let region = {
      latitude: 42.5,
      longitude: 15.2,
      latitudeDelta: 7.5,
      longitudeDelta: 7.5,
    };

    mapRef.current.animateToRegion(region, 2000);
  };

  return (
    <>
      <MapView
        ref={mapRef}
        initialRegion={INITIAL_REGION}
        style={{ flex: 1 }}
      />
      <Button onPress={animateToRegion} title="Animate" />
    </>
  );
};

export default App;

Support

Feel free to create issues and pull requests. I will try to provide as much support as possible over GitHub. In case of questions or problems, contact me at: tony@venits.com

Happy Coding 💖🚀

Keywords

FAQs

Package last updated on 10 Jan 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc