UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

65 lines (64 loc) 1.99 kB
import PointIndex from './pointIndex.js'; import { Tile } from 'gis-tools/index.js'; import type { ClusterOptions } from './index.js'; import type { Face, JSONCollection, S2CellId, VectorPointFeature } from 'gis-tools/index.js'; /** Comparison function - if true the features can be grouped */ export type Comparator = (a: VectorPointFeature, b: VectorPointFeature) => boolean; /** A clustered point */ export interface Cluster { ref: VectorPointFeature; visited: boolean; sum: number; } /** Options for point clustering that are filled with values */ export interface OptionsComputed { /** min zoom to generate clusters on */ minzoom: number; /** max zoom level to cluster the points on */ maxzoom: number; /** cluster radius in pixels */ radius: number; /** tile extent (radius is calculated relative to it) */ extent: number; /** size of the KD-tree leaf node, effects performance */ nodeSize: number; } /** * # Point Cluster * * A point cluster for Web Mercator tiles */ export default class PointCluser { #private; minzoom: number; maxzoom: number; options: OptionsComputed; base: PointIndex<Cluster>; indexes: Array<PointIndex<Cluster>>; points: VectorPointFeature[]; faces: Set<Face>; projection: string; /** @param options - cluster options */ constructor(options?: ClusterOptions); /** * Add a collection of points * @param data - a collection of points to add */ addManyPoints(data: JSONCollection): void; /** * Add a single point * @param point - a point to add */ addPoint(point: VectorPointFeature): void; /** * Cluster the points * @param cmp - optional comparator function */ cluster(cmp?: Comparator): void; /** * Get a tile from the point cluster * @param id - the tile id * @returns a tile filled with cluster points that are in the tile */ getTile(id: S2CellId): Tile; }