s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
108 lines • 3.78 kB
TypeScript
import { Tile } from '../dataStructures';
import { PointShape as Point, PointIndex } from './pointIndex';
import type { PointShape } from './pointIndex';
import type { Face, JSONCollection, Point3D, Projection, Properties, S2CellId } from '../geometry';
import type { VectorStore, VectorStoreConstructor } from '../dataStore/vector';
/** The kind of input required to store a point for proper indexing */
export type ClusterStore = VectorStoreConstructor<PointShape<Cluster>>;
/** Options for point clustering */
export interface ClusterOptions {
/** type of store to use. Defaults to an in memory store */
store?: ClusterStore;
/** projection to use */
projection?: Projection;
/** Name of the layer to build when requesting a tile */
layerName?: string;
/** min zoom to generate clusters on */
minzoom?: number;
/** max zoom level to cluster the points on */
maxzoom?: number;
/** cluster radius in pixels relative to a 512x512 pixel tile */
radius?: number;
}
/** A cluster is a storage device to maintain groups of information in a cluster */
export interface Cluster {
properties: Properties;
visited: boolean;
sum: number;
}
/** Compare two data items, return true to merge data */
export type Comparitor = (a: Properties, b: Properties) => boolean;
/**
* # Point Cluster
*
* ## Description
* A cluster store to index points at each zoom level
*
* ## Usage
* ```ts
* import { PointCluster } from 's2-tools';
* const pointCluster = new PointCluster();
*
* // add a lon-lat
* pointCluster.insertLonLat(lon, lat, data);
* // add an STPoint
* pointCluster.insertFaceST(face, s, t, data);
*
* // after adding data build the clusters
* await pointCluster.buildClusters();
*
* // get the clusters for a tile
* const tile = await pointCluster.getTile(id);
* // or get the raw cluster data
* const clusters = await pointCluster.getCellData(id);
* ```
*/
export declare class PointCluster {
#private;
projection: Projection;
layerName: string;
minzoom: number;
maxzoom: number;
radius: number;
extent: number;
indexes: Map<number, PointIndex<Cluster>>;
/**
* @param data - if provided, the data to index
* @param options - cluster options on how to build the cluster
* @param maxzoomStore - the store to use for the maxzoom index
*/
constructor(data?: JSONCollection, options?: ClusterOptions, maxzoomStore?: VectorStore<PointShape<Cluster>>);
/**
* Add a point to the maxzoom index
* @param point - the point to add
* @param data - the data associated with the point
*/
insert(point: Point3D, data: Properties): void;
/**
* Add a lon-lat pair to the cluster
* @param lon - longitude in degrees
* @param lat - latitude in degrees
* @param data - the data associated with the point
*/
insertLonLat(lon: number, lat: number, data: Properties): void;
/**
* Insert an STPoint to the index
* @param face - the face of the cell
* @param s - the s coordinate
* @param t - the t coordinate
* @param data - the data associated with the point
*/
insertFaceST(face: Face, s: number, t: number, data: Properties): void;
/**
* Build the clusters when done adding points
* @param cmp_ - custom compare function
*/
buildClusters(cmp_?: Comparitor): Promise<void>;
/**
* @param id - the cell id
* @returns - the data within the range of the tile id
*/
getCellData(id: S2CellId): Promise<undefined | Point<Cluster>[]>;
/**
* @param id - the id of the vector tile
* @returns - the vector tile
*/
getTile(id: S2CellId): Promise<undefined | Tile>;
}
//# sourceMappingURL=pointCluster.d.ts.map