react-leaflet-markercluster

by yuzhva

React wrapper of the official Leaflet.markercluster for react-leaflet

156 Stars 50 Forks Last release: 7 months ago (v2.0.0) MIT License 37 Commits 17 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

React leaflet markercluster

npm Code Climate npm license

React wrapper of Leaflet.markercluster for react-leaflet

React leaflet markercluster

Examples with the Documentation: https://yuzhva.github.io/react-leaflet-markercluster/
CodeSandbox Getting Started

Description

If you are faced with an issue with markers overlapping during map zooming, or they are overlapping because they are close to each other - you probably need to group them.
That is what you can do with react-leaflet-markercluster.

Just grab your markers inside

 component, right after 
:
```javascript
import MarkerClusterGroup from "react-leaflet-markercluster";

```

Note: Before getting started, please see these useful guides:

Table of Contents

Getting started

1. Install package:

yarn add react-leaflet-markercluster # yarn
npm install react-leaflet-markercluster # npm

The

react-leaflet-markercluster
requires
leaflet.markercluster
as
peerDependency

(Leaflet and react-leaflet also should be installed)

yarn add leaflet.markercluster leaflet react-leaflet # yarn
npm install leaflet.markercluster leaflet react-leaflet # npm

2. Import markercluster and leaflet styles:

@import '~leaflet/dist/leaflet.css'; // sass
@import '~react-leaflet-markercluster/dist/styles.min.css'; // sass

require('~leaflet/dist/leaflet.css'); // inside .js file require('react-leaflet-markercluster/dist/styles.min.css'); // inside .js file

Or include CSS styles directly to the head of HTML file:


3. Write some simple

react-leaflet
Map:
import { Map, TileLayer, Marker } from 'react-leaflet';


  

NOTE: Remember to add map styles

.markercluster-map { height: 90vh; }
.

4. Just grab your markers inside

 component, right after 
:
import MarkerClusterGroup from "react-leaflet-markercluster";


  
  
  

More examples with the Documentation
CodeSandbox Getting Started

API

Just pass whatever option you need from All Leaflet.markercluster Options to

MarkerClusterGroup
as
prop
.

For example:


or:

const createClusterCustomIcon = function (cluster) {
  return L.divIcon({
    html: `${cluster.getChildCount()}`,
    className: 'marker-cluster-custom',
    iconSize: L.point(40, 40, true),
  });
}

P.S: Examples for v1 are available at CHANGELOG.md

Event listeners

You are able to add any listener, supported by Leaflet, with simple

on
property prefix.

How to run DEV env

1. Clone the repo:

git clone https://github.com/YUzhva/react-leaflet-markercluster.git

2. Install all dependencies:

yarn install --no-lockfile # yarn
npm install # npm

3. Start the server:

yarn dev # yarn
npm run dev # npm

4. After starting the server, storybook should automatically open the following address:

http://localhost:8080/

Contributing

All sources are placed in the

./src
folder:

1. Fork the repo.

2. Edit

react-leaflet-markercluster.js
plugin or
style.scss
style files.

3. Commit your changes and open Pull Request.

:beer: Thank you for contribution :beer:

UMD

UMD builds are available on unpkg:







License

MIT License, see LICENSE file.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.