All Projects → novalabio → React Native Maps Super Cluster

novalabio / React Native Maps Super Cluster

Licence: mit
A Clustering-enabled map for React Native

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Maps Super Cluster

js-markerclusterer
Create and manage clusters for large amounts of markers
Stars: ✭ 92 (-67.61%)
Mutual labels:  maps, clustering
Supercluster
A very fast geospatial point clustering library for browsers and Node.
Stars: ✭ 1,246 (+338.73%)
Mutual labels:  clustering, maps
React Native Map Clustering
React Native map clustering both for Android and iOS.
Stars: ✭ 450 (+58.45%)
Mutual labels:  clustering, maps
react-map-gl-cluster
Urbica React Cluster Component for Mapbox GL JS
Stars: ✭ 27 (-90.49%)
Mutual labels:  maps, clustering
Osmnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
Stars: ✭ 3,357 (+1082.04%)
Mutual labels:  maps
Mongodb consistent backup
A tool for performing consistent backups of MongoDB Clusters or Replica Sets
Stars: ✭ 255 (-10.21%)
Mutual labels:  clustering
k8s-openresty-streaming
Full-fledged media streaming server with OpenResty and rtmp module
Stars: ✭ 37 (-86.97%)
Mutual labels:  clustering
flagfillr
Use flags as fills for ggplot2 maps. (WIP)
Stars: ✭ 23 (-91.9%)
Mutual labels:  maps
Rabbitmq Peer Discovery K8s
Kubernetes-based peer discovery mechanism for RabbitMQ
Stars: ✭ 283 (-0.35%)
Mutual labels:  clustering
Maps Pair Programming
Fastest marker render +500k markers
Stars: ✭ 280 (-1.41%)
Mutual labels:  maps
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-3.87%)
Mutual labels:  maps
Mapper
OpenOrienteering Mapper is a software for creating maps for the orienteering sport.
Stars: ✭ 258 (-9.15%)
Mutual labels:  maps
React Yandex Maps
Yandex Maps API bindings for React
Stars: ✭ 277 (-2.46%)
Mutual labels:  maps
NNS
Nonlinear Nonparametric Statistics
Stars: ✭ 26 (-90.85%)
Mutual labels:  clustering
2018 Machinelearning Lectures Esa
Machine Learning Lectures at the European Space Agency (ESA) in 2018
Stars: ✭ 280 (-1.41%)
Mutual labels:  clustering
angular-mapboxgl-directive
AngularJS directive for Mapbox GL
Stars: ✭ 43 (-84.86%)
Mutual labels:  maps
Dotmap
Dot access dictionary with dynamic hierarchy creation and ordered iteration
Stars: ✭ 273 (-3.87%)
Mutual labels:  maps
Supervizer
NodeJS Application Manager
Stars: ✭ 278 (-2.11%)
Mutual labels:  clustering
Dagsfm
Distributed and Graph-based Structure from Motion
Stars: ✭ 269 (-5.28%)
Mutual labels:  clustering
Shareabouts
Shareabouts is a mapping application for crowdsourced info gathering.
Stars: ✭ 269 (-5.28%)
Mutual labels:  maps

React Native Super Cluster

This module wraps AirBnB's react-native-maps and uses MapBox's SuperCluster as clustering engine.

Example

See the showcase application.

Rationale

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.

Install

npm i --save react-native-maps-super-cluster

Usage

NOTES:

  • the prop key of the markers rendered through renderMarker should not be left up to React. Instead, we strongly suggest to use an id in order the have unique keys while still taking advantage of React's recycling
  • ClusteredMapView supports usual React children. Those children won't be affected by clustering, i.e. the behavior for those children is exactly the same as wrapping them around an AirBnB's react-native-maps instance
  • Use onMarkerPress event on MapView instead of using onPress directly on Markers whenever possibile, in particular if you have a lot of pins and clusters. Within onMarkerPress you have access to the marker identifier through the event.nativeEvent attribute, hence you should be able to do everything you would do within an onPress function of a Marker
import React, { Component } from 'react'
import { Marker, Callout } 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 {
  
  ...

  renderCluster = (cluster, onPress) => {
    const pointCount = cluster.pointCount,
          coordinate = cluster.coordinate,
          clusterId = cluster.clusterId

    // use pointCount to calculate cluster size scaling
    // and apply it to "style" prop below

    // eventually get clustered points by using
    // underlying SuperCluster instance
    // Methods ref: https://github.com/mapbox/supercluster
    const clusteringEngine = this.map.getClusteringEngine(),
          clusteredPoints = clusteringEngine.getLeaves(clusterId, 100)

    return (
      <Marker coordinate={coordinate} onPress={onPress}>
        <View style={styles.myClusterStyle}>
          <Text style={styles.myClusterTextStyle}>
            {pointCount}
          </Text>
        </View>
        {
          /*
            Eventually use <Callout /> to
            show clustered point thumbs, i.e.:
            <Callout>
              <ScrollView>
                {
                  clusteredPoints.map(p => (
                    <Image source={p.image}>
                  ))
                }
              </ScrollView>
            </Callout>

            IMPORTANT: be aware that Marker's onPress event isn't really consistent when using Callout.
           */
        }
      </Marker>
    )
  }

  renderMarker = (data) => <Marker key={data.id || Math.random()} coordinate={data.location} />

  ...

  render() {
    return (
      <ClusteredMapView
        style={{flex: 1}}
        data={this.state.data}
        initialRegion={INIT_REGION}
        ref={(r) => { this.map = r }}
        renderMarker={this.renderMarker}
        renderCluster={this.renderCluster} />
    )
  }
}

Props

Name Type Required Default Note
radius Number false window width * 4,5% SuperCluster radius.
extent Number false 512 SuperCluster extent.
minZoom Number false 1 SuperCluster minZoom.
maxZoom Number false 16 SuperCluster maxZoom.
width Number false window width map's width.
height Number false window height map's height.
data Array true undefined Objects must have an attribute location representing a GeoPoint, i.e. { latitude: x, longitude: y }.
onExplode Function false undefined TODO
onImplode Function false undefined TODO
onClusterPress(clusterId, ?children) Function false Add (or completey override) behaviours to the clusterPress handler. children is passed when default behavior is preserved (see preserveClusterPressBehavior prop).
preserveClusterPressBehavior Bool false true Whether onClusterPress prop should completely override module's behavior rather than integrate it.
clusterPressMaxChildren Function false 100 Max number of cluster leaves returned as second parameter of onClusterPress.
edgePadding Object false { top: 10, left: 10, bottom: 10, right: 10 } Edge padding for react-native-maps's fitToCoordinates method, called in onClusterPress for fitting to pressed cluster children.
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.
layoutAnimationConf LayoutAnimationConfig false LayoutAnimation.Presets.spring Custom Layout animation configuration object for clusters animation during implode / explode Works only on iOS.
clusteringEnabled Bool false true Dynamically set whether to pass through clustering functions or immediately render markers as a normal mapview.
accessor String|Func true "location" Accessor for item coordinate values. Could be a string (field name of an item object with latitude and longitude values) or a function (that describes how to access to coordinate data).

Methods

Name Params Description Note
getMapRef none Getter for underlying react-native-maps instance Official Doc
getClusteringEngine none Getter for underlying SuperCluster instance Official Doc

Production usage

If you are using this module in a production application, please submit a PR or contact us to add it here.

TODO

features

  • improve scaleUpRatio math for fontSize
  • trigger events on cluster implode/explode

Support

As an open source project, we provide free support over Github. However, our daily job may increase response time to days or even weeks. If you need dedicated support, feel free to contact us for a quote.

Contributors

License

See our License for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].