Installations
npm install react-leaflet-markercluster
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.14.0
NPM Version
10.9.1
Score
86.3
Supply Chain
93.8
Quality
90.4
Maintenance
100
Vulnerability
98.9
License
Releases
Contributors
Languages
JavaScript (52.52%)
MDX (45.38%)
SCSS (1.79%)
HTML (0.31%)
Developer
Download Statistics
Total Downloads
6,897,020
Last Day
1,901
Last Week
19,153
Last Month
103,498
Last Year
1,143,379
GitHub Statistics
295 Stars
71 Commits
101 Forks
6 Watching
4 Branches
14 Contributors
Bundle Size
5.18 kB
Minified
2.05 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.2.1
Package Id
react-leaflet-markercluster@4.2.1
Unpacked Size
43.43 kB
Size
10.41 kB
File Count
11
NPM Version
10.9.1
Node Version
20.14.0
Publised On
06 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
6,897,020
Last day
-66.6%
1,901
Compared to previous day
Last week
-23.8%
19,153
Compared to previous week
Last month
8.4%
103,498
Compared to previous month
Last year
-25.1%
1,143,379
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
Dev Dependencies
35
React leaflet markercluster
React wrapper of Leaflet.markercluster for react-leaflet
Examples with the Documentation: https://yuzhva.github.io/react-leaflet-markercluster/
CodeSandbox Getting Started
Description
If you are faced with an issue with markers or polygons 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 or ClusterableRegions inside <MarkerClusterGroup />
component, right after <TileLayer />
:
1import MarkerClusterGroup from "react-leaflet-markercluster"; 2 3<MarkerClusterGroup> 4 <Marker position={[49.8397, 24.0297]} /> 5 <Marker position={[52.2297, 21.0122]} /> 6 <Marker position={[51.5074, -0.0901]} /> 7</MarkerClusterGroup>;
Note: Before getting started, please see these useful guides:
Table of Contents
Getting started
1. Install package:
1yarn add react-leaflet-markercluster@next # yarn 2npm install react-leaflet-markercluster # npm
The react-leaflet-markercluster
requires leaflet.markercluster
as peerDependency
(Leaflet and react-leaflet also should be installed)
1yarn add leaflet.markercluster leaflet react-leaflet # yarn 2npm install leaflet.markercluster leaflet react-leaflet # npm
2. Import markercluster and leaflet styles:
1//sass 2@import '~leaflet/dist/leaflet.css'; 3@import '~react-leaflet-markercluster/styles'; 4 5//cjs 6require('~leaflet/dist/leaflet.css'); 7require('react-leaflet-markercluster/styles'); 8 9//esm 10import 'leaflet/dist/leaflet.css' 11import 'react-leaflet-markercluster/styles'
Or include CSS styles directly to the head of HTML file:
1<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> 2 3<link 4 rel="stylesheet" 5 href="https://unpkg.com/react-leaflet-markercluster/styles" 6/>
3. Write some simple react-leaflet
Map:
1import { MapContainer, TileLayer, Marker } from "react-leaflet"; 2 3<MapContainer 4 className="markercluster-map" 5 center={[51.0, 19.0]} 6 zoom={4} 7 maxZoom={18} 8> 9 <TileLayer 10 url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" 11 attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' 12 /> 13 14 <Marker position={[49.8397, 24.0297]} /> 15 <Marker position={[52.2297, 21.0122]} /> 16 <Marker position={[51.5074, -0.0901]} /> 17</MapContainer>;
NOTE: Remember to add map styles .markercluster-map { height: 90vh; }
.
4. Just put your markers or ClusterableRegions inside <MarkerClusterGroup />
component, right after <TileLayer />
:
1import MarkerClusterGroup from "react-leaflet-markercluster"; 2 3<MarkerClusterGroup> 4 <Marker position={[49.8397, 24.0297]} /> 5 <Marker position={[52.2297, 21.0122]} /> 6 <Marker position={[51.5074, -0.0901]} /> 7</MarkerClusterGroup>;
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:
1<MarkerClusterGroup showCoverageOnHover={false} />
or:
1const createClusterCustomIcon = function (cluster) { 2 return L.divIcon({ 3 html: `<span>${cluster.getChildCount()}</span>`, 4 className: 'marker-cluster-custom', 5 iconSize: L.point(40, 40, true), 6 }); 7} 8 9<MarkerClusterGroup iconCreateFunction={createClusterCustomIcon} />
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:
1git clone https://github.com/YUzhva/react-leaflet-markercluster.git
2. Install all dependencies:
1yarn install --no-lockfile # yarn 2npm install # npm
3. Start the server:
1yarn dev # yarn 2npm run dev # npm
4. After starting the server, storybook should automatically open the following address:
http://localhost:8080/
Contributors ✨
Thanks goes to these wonderful people: Avatars rendered by contributors-img.
Special thanks to:
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:
1<!-- unpkg, production code (minified) --> 2<script src="https://unpkg.com/react-leaflet-markercluster/dist/index.js"></script> 3<!-- unpkg, development code --> 4<script src="https://unpkg.com/react-leaflet-markercluster/src/react-leaflet-markercluster.js"></script> 5 6<!-- unpkg, production styles (minified) --> 7<link 8 rel="stylesheet" 9 type="text/css" 10 href="https://unpkg.com/react-leaflet-markercluster/styles" 11/> 12<!-- unpkg, development styles --> 13<link 14 rel="stylesheet" 15 type="text/css" 16 href="https://unpkg.com/react-leaflet-markercluster/src/styles.scss" 17/>
License
MIT License, see LICENSE file.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
25 commit(s) and 8 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-7q7g-4xm8-89cq
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
Reason
Found 2/14 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Score
4.1
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-leaflet-markercluster
@types/react-leaflet-markercluster
TypeScript definitions for react-leaflet-markercluster
@changey/react-leaflet-markercluster
React wrapper of Leaflet.markercluster for react-laeflet
@christopherpickering/react-leaflet-markercluster
React wrapper of Leaflet.markercluster for react-laeflet
@greenatom/react-leaflet-markercluster
React wrapper of Leaflet.markercluster for react-laeflet