Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

marker-cluster

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marker-cluster

typescript library for point clustering

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126
decreased by-11.27%
Maintainers
1
Weekly downloads
 
Created
Source

marker-cluster

Library for point clustering

Why should I use MarkerCluster?
  • it is really fast
  • it could leverage Worker to avoid freezing while clustering a large amount of points (browsers only)
  • it does not dictate supplied points format
  • format of returned points is customizable

Example

import MarkerCluster from "marker-cluster";

type Point = { lat: number; lng: number };

const points: Point[] = [
  { lat: -31.56391, lng: 147.154312 },
  { lat: -33.718234, lng: 150.363181 },
  { lat: -33.727111, lng: 150.371124 },
  { lat: -33.848588, lng: 151.209834 },
];

const markerCluster = new MarkerCluster<Point>((v) => [v.lng, v.lat], {
  radius: 75,
});

markerCluster.load(points);

// or

await markerCluster.loadAsync(points);

const currPoints = markerCluster.getPoints(
  2,
  -180,
  -85,
  180,
  85,
  (point, lng, lat) => ({ point, lng, lat }),
  (lng, lat, count, clusterId) => ({ count, clusterId, lng, lat })
);

Class: MarkerCluster<T>

Constructor

Methods

Properties

Constructor

constructor(getLngLat: (item: T) => [lng: number, lat: number], options: MarkerClusterOptions)
NameTypeDescriptionDefault
extent?numbertile extent (radius is calculated relative to it)256
maxZoom?numbermax zoom level to cluster the points on16
minZoom?numbermin zoom level to cluster the points on0
radius?numbercluster radius in pixels60

Methods

load

load(points: T[]): void

Loads given points

Parameters
NameTypeDescription
pointsT[]points for clustering

loadAsync

async loadAsync(points: T[]): Promise<void>

Same to load, but do clustering at another thread

Note: this method use Worker


cleanUp

cleanUp(): void

if loadAsync was called, use this method before MarkerCluster instance has gone


getPoints

getPoints<M, C>(
  zoom: number,
  westLng: number,
  southLat: number,
  eastLng: number,
  northLat: number,
  markerMapper: (point: T, lng: number, lat: number) => M,
  clusterMapper: (lng: number, lat: number, count: number, clusterId: number) => C,
  expand?: number
): (M | C)[]
Parameters
NameTypeDescription
expand?numberfor values in range (0..1) considered as percentage, otherwise as absolute pixels value to expand given boundary.

Returns

Array of clusters and points for the given zoom and boundary


getZoom

getZoom(clusterId: number): number
Returns

Zoom level on which the cluster splits into several children, or -1 if it cluster of several points with same coords


getChildren

getChildren(clusterId: number): (T | { clusterId: number; count: number })[]

Properties

points

points?: T[]

points from last executed loadAsync or load


worker

worker?: Worker;

Worker instance, inits at first loadAsync call


License

MIT © Krombik

Keywords

FAQs

Package last updated on 14 Jun 2022

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