React wrapper of Leaflet.markercluster for react-laeflet
npm install @christopherpickering/react-leaflet-markercluster
Yet another react-leaflet-markercluster npm package. Why, there are already a dozen? I could not find one that worked with the latest version of react-leaflet and also seemed to support maintenance. I'm not a node developer but created this so that others could use an updated version and also maintain it. PR's are welcome. The fork-chain here is about a mile long so I've broken out of it, but listed the original developers below.

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 '@christopherpickering/react-leaflet-markercluster';
`
> Note: Before getting started, please see these useful guides:
>
> - Leaflet Quick Start Guide.
> - react-leaflet Installation.
- Getting started
- API
- How to run DEV env
- Contributors ✨
- Contributing
- License
1. Install packages:
`bash`
npm install @christopherpickering/react-leaflet-markercluster leaflet react-leaflet leaflet.markercluster
2. Import markercluster and leaflet styles:
`javascript
@import '~leaflet/dist/leaflet.css'; // sass
@import '~@christopherpickering/react-leaflet-markercluster/dist/styles.min.css'; // sass
require('~leaflet/dist/leaflet.css'); // inside .js file
require('@christopherpickering/react-leaflet-markercluster/dist/styles.min.css'); // inside .js file
`
Or include CSS styles directly to the head of HTML file:
`html
rel="stylesheet"
href="https://unpkg.com/@christopherpickering/react-leaflet-markercluster/dist/styles.min.css"
/>
`
3. Write some simple react-leaflet Map:
`javascript
import { MapContainer, TileLayer, Marker } from 'react-leaflet';
center={[51.0, 19.0]}
zoom={4}
maxZoom={18}
>
attribution='© OpenStreetMap contributors'
/>
;
`
NOTE: Remember to add map styles .markercluster-map { height: 90vh; }.
4. Just grab your markers inside component, right after :
`javascript
import MarkerClusterGroup from '@christopherpickering/react-leaflet-markercluster';
`
More examples with the Documentation
CodeSandbox Getting Started
Just pass whatever option you need from All Leaflet.markercluster Options to MarkerClusterGroup as prop.
For example:
`javascript`
or:
`javascript${cluster.getChildCount()}
const createClusterCustomIcon = function (cluster) {
return L.divIcon({
html: ,
className: 'marker-cluster-custom',
iconSize: L.point(40, 40, true),
});
}
`
You are able to add any listener, supported by Leaflet, with simple on property prefix.
Run yarn storybook and storybook should automatically open the at http://localhost:6006/.
react-leaflet-markercluster was originally built by @yuzhva and then modified by @amauryfischer, @l4b4r4b4b4 and @changey before reaching this point. Many others have contributed as well.
Special thanks to:
- @webcarrot react-leaflet v2 supportreact-leaflet
- @CodeCutterUK v3 supportreact-leaflet
- @changey v4 support
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.
Thank you for contribution
UMD builds are available on unpkg:
`html
rel="stylesheet"
type="text/css"
href="https://unpkg.com/@christopherpickering%2freact-leaflet-markercluster/dist/styles.min.css"
/>
rel="stylesheet"
type="text/css"
href="https://unpkg.com/@christopherpickering%2freact-leaflet-markercluster/src/styles.scss"
/>
``
MIT License, see LICENSE file.
MIT License, see LICENSE file.
MIT License, see LICENSE file.
MIT License, see LICENSE file.
MIT License, see LICENSE file.