Socket
Socket
Sign inDemoInstall

leaflet.markercluster

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet.markercluster

Provides Beautiful Animated Marker Clustering functionality for Leaflet


Version published
Maintainers
2
Created

What is leaflet.markercluster?

The leaflet.markercluster package is a plugin for Leaflet, a popular JavaScript library for interactive maps. This plugin provides functionality for clustering markers on a map, which helps in managing and displaying a large number of markers efficiently.

What are leaflet.markercluster's main functionalities?

Basic Marker Clustering

This feature allows you to cluster a large number of markers on a map. The code sample demonstrates how to create a map, add a tile layer, and then add 100 random markers to a marker cluster group.

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
}).addTo(map);
var markers = L.markerClusterGroup();
for (var i = 0; i < 100; i++) {
    var marker = L.marker(getRandomLatLng());
    markers.addLayer(marker);
}
map.addLayer(markers);
function getRandomLatLng() {
    return [51.505 + Math.random() * 0.1 - 0.05, -0.09 + Math.random() * 0.1 - 0.05];
}

Custom Cluster Icons

This feature allows you to customize the icons used for clusters. The code sample demonstrates how to create a map, add a tile layer, and then add 100 random markers to a marker cluster group with custom cluster icons.

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
}).addTo(map);
var markers = L.markerClusterGroup({
    iconCreateFunction: function (cluster) {
        return L.divIcon({
            html: '<b>' + cluster.getChildCount() + '</b>',
            className: 'custom-cluster-icon',
            iconSize: L.point(40, 40)
        });
    }
});
for (var i = 0; i < 100; i++) {
    var marker = L.marker(getRandomLatLng());
    markers.addLayer(marker);
}
map.addLayer(markers);
function getRandomLatLng() {
    return [51.505 + Math.random() * 0.1 - 0.05, -0.09 + Math.random() * 0.1 - 0.05];
}

Spiderfied Markers

This feature allows markers to be 'spiderfied' when they are too close to each other, making them easier to distinguish. The code sample demonstrates how to create a map, add a tile layer, and then add 100 random markers to a marker cluster group with spiderfied markers.

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
}).addTo(map);
var markers = L.markerClusterGroup({
    spiderfyOnMaxZoom: true,
    showCoverageOnHover: false,
    zoomToBoundsOnClick: true
});
for (var i = 0; i < 100; i++) {
    var marker = L.marker(getRandomLatLng());
    markers.addLayer(marker);
}
map.addLayer(markers);
function getRandomLatLng() {
    return [51.505 + Math.random() * 0.1 - 0.05, -0.09 + Math.random() * 0.1 - 0.05];
}

Other packages similar to leaflet.markercluster

Keywords

FAQs

Package last updated on 18 Oct 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