npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

leaflet-clustering

v0.1.2

Published

[![npm version](https://img.shields.io/npm/v/leaflet-clustering.svg)](https://www.npmjs.com/package/leaflet-clustering) [![build status](https://github.com/stardisblue/leaflet-clustering/actions/workflows/publish.yml/badge.svg)](https://github.com/stardis

Readme

Leaflet Clustering

npm version build status license

High performance clustering for leaflet.

cluster map example

Features

  • High-performance marker clustering for Leaflet
  • Fine-grained control over clustering methods and marker appearance
  • Restrict clustering to visible map bounds
  • TypeScript support out of the box
  • Easily extensible for custom clustering logic

If you want an out-of-the-box experience, go check out Leaflet.markercluster.

If you want more fine-grained control on how clustering is done and mess around with markers, you're at the right place.

Getting Started (npm)

To use leaflet-clustering in your project:

Install via npm :

npm install leaflet-clustering leaflet

Import and use in your code:

import { ClusterFeatureGroup } from 'leaflet-clustering';
import { map, tileLayer, marker } from 'leaflet';

const leafletMap = map('map').setView([48.9, 2.3], 6);
tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '© OpenStreetMap contributors',
}).addTo(leafletMap);

const markers = [
  marker([48.8566, 2.3522]), // Paris
  marker([51.5074, -0.1278]) // London
];

const clusters = new ClusterFeatureGroup(markers, {
  restrictToVisibleBounds: true,
});
clusters.addTo(leafletMap);

Bind popups or other interactions:

clusters.bindPopup((layer) => `Cluster contains ${layer.getLayers().length} markers`);

Documentation & Examples

See API section below for usage details.

More examples and documentation coming soon!


API

ClusterFeatureGroup(markers, options)

The ClusterFeatureGroup is a class that extends Leaflet's FeatureGroup to provide clustering functionality for markers. It requires an array of markers and an optional configuration object.

markers: An array of CircleMarker or Marker instances that you want to cluster.

options: An optional object to configure the clustering behavior. It includes:

  • method: A constructor for the clustering method to be used. Defaults to FsacClustering.
  • restrictToVisibleBounds: A boolean indicating whether clustering should be restricted to markers within the current map view. Defaults to false.
  • FsacClustering: Options specific to the default FsacClustering method, which are extracted from the ClusterFeatureGroup options. These include:
    • padding: A number specifying the padding to be used around clusters. Defaults to 4.
    • ShapedCluster: A constructor for the shaped cluster to be used. Defaults to CircleCluster.
    • shapedClusterOptions: Options specific to the shaped cluster, excluding padding.
    • ClusterMarker: A constructor for the cluster marker to be used. Defaults to CircleClusterMarker.
    • clusterMarkerOptions: Options specific to the cluster marker.

The ClusterFeatureGroup provides several methods and properties to interact with the clustering:

  • getLayers(): Returns the layers created by the clustering method.
  • getClusteringMethod(): Returns the current clustering method instance.
  • clusterize(): Triggers the clustering process for the current markers and map state.

Wishlist

  • [ ] allow any cluster marker to use convex hull
  • [ ] allow any cluster marker to use spiderfier

Future

  • [ ] animate zoom transitions
  • [ ] cache zoom levels
  • [ ] allow to add and remove markers

Contributing

To contribute or develop locally:

Clone the repository:

git clone https://github.com/stardisblue/leaflet-clustering.git
cd leaflet-clustering

Install dependencies:

npm install

Run the development server:

npm run dev

Build the project:

npm run build

Run tests:

npm test