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

mutable-supercluster

v1.1.0

Published

A library for fast and mutable geospatial point clustering.

Downloads

50

Readme

mutable-supercluster Test NPM Version

This repository is a fork from mapbox/supercluster, further inspired by rorystephenson/supercluster_dart.

A Node.js library for fast and mutable geospatial point clustering.

const index = new Supercluster({
  radius: 40,
  maxZoom: 16,
  getId: (point) => point.id,
});
index.load(points);

const clusters = index.getClusters([-180, -85, 180, 85], 2);

Install

Install using NPM (npm install mutable-supercluster), then:

// import as a ES module in Node
import Supercluster from "mutable-supercluster";

Methods

load(points)

Loads an array of GeoJSON Feature objects. Each feature's geometry must be a GeoJSON Point. Loading the points is destructive, so the provided list will be cleared.

getClusters(bbox, zoom)

For the given bbox array ([westLng, southLat, eastLng, northLat]) and integer zoom, returns an array of clusters and points as GeoJSON Feature objects.

getTile(z, x, y)

For a given zoom and x/y coordinates, returns a geojson-vt-compatible JSON tile object with cluster/point features.

getChildren(clusterId)

Returns the children of a cluster (on the next zoom level) given its id (cluster_id value from feature properties).

getLeaves(clusterId, limit = 10, offset = 0)

Returns all the points of a cluster (given its cluster_id), with pagination support: limit is the number of points to return (set to Infinity for all points), and offset is the amount of points to skip (for pagination).

getClusterExpansionZoom(clusterId)

Returns the zoom on which the cluster expands into several children (useful for "click to zoom" feature) given the cluster's cluster_id.

updatePointProperties(id, properties)

Updates the point in the cluster with the same id (according to getId), with the given properties. If the given id is not present in the cluster, this method will throw an error. The location of the point (point.geometry.coordinates) can not be updated through this method.

addPoint(point)

Adds the given point to the cluster. Just like load(), the given point must be a GeoJSON Feature with its geometry a GeoJSON Point.

removePoint(id)

Removes the point with the same id (according to getId) from the cluster.

Options

| Option | Default | Description | | ---------- | ------- | ------------------------------------------------------------------------ | | minZoom | 0 | Minimum zoom level at which clusters are generated. | | maxZoom | 16 | Maximum zoom level at which clusters are generated. | | minPoints | 2 | Minimum number of points to form a cluster. | | radius | 40 | Cluster radius, in pixels. | | extent | 512 | (Tiles) Tile extent. Radius is calculated relative to this value. | | zoomFactor | 2 | The factor with which the detail increases each zoom level. | | nodeSize | 9 | Size of the R-tree nodes. Affects performance. | | log | false | Whether timing info should be logged. | | generateId | false | Whether to generate ids for input features in vector tiles. | | getId | null | An function that accesses a unique id field in a point. Can not be null. |

Property map/reduce options

In addition to the options above, Supercluster supports property aggregation with the following two options:

  • map: a function that returns cluster properties corresponding to a single point.
  • reduce: a reduce function that merges properties of two clusters into one.

Example of setting up a sum cluster property that accumulates the sum of myValue property values:

const index = new Supercluster({
  map: (props) => ({ sum: props.myValue }),
  reduce: (accumulated, props) => {
    accumulated.sum += props.sum;
  },
});

The map/reduce options must satisfy these conditions to work correctly:

  • map must return a new object, not existing properties of a point, otherwise it will get overwritten.
  • reduce must not mutate the second argument (props).

Developing Supercluster

npm install       # install dependencies
npm run build     # generate dist/supercluster.js and dist/supercluster.min.js
npm test          # run tests