mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Improve supercluster types (#20348)
* Improve supercluster types * Remove remaining declare
This commit is contained in:
committed by
Ryan Cavanaugh
parent
7c80443b31
commit
430e451626
Vendored
+35
-35
@@ -1,11 +1,13 @@
|
||||
// Type definitions for supercluster 2.3
|
||||
// Type definitions for supercluster 3.0
|
||||
// Project: https://github.com/mapbox/supercluster
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as GeoJSON from 'geojson';
|
||||
|
||||
interface Options {
|
||||
export as namespace supercluster;
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* Minimum zoom level at which clusters are generated.
|
||||
*/
|
||||
@@ -32,32 +34,32 @@ interface Options {
|
||||
log?: boolean;
|
||||
}
|
||||
|
||||
declare class Supercluster {
|
||||
export class Supercluster {
|
||||
/**
|
||||
* Loads an array of GeoJSON.Feature objects. Each feature's geometry must be a GeoJSON.Point. Once loaded, index is immutable.
|
||||
*/
|
||||
load(points: supercluster.Points): Supercluster;
|
||||
load(points: Points): Supercluster;
|
||||
/**
|
||||
* For the given bbox array ([westLng, southLat, eastLng, northLat]) and integer zoom, returns an array of clusters and points as GeoJSON.Feature objects.
|
||||
*/
|
||||
getClusters(bbox: supercluster.BBox, zoom: number): supercluster.Clusters;
|
||||
getClusters(bbox: BBox, zoom: number): Clusters;
|
||||
|
||||
/**
|
||||
* For a given zoom and x/y coordinates, returns a geojson-vt-compatible JSON tile object with cluster/point features.
|
||||
*/
|
||||
getTile(z: number, x: number, y: number): supercluster.Tile;
|
||||
getTile(z: number, x: number, y: number): Tile;
|
||||
|
||||
/**
|
||||
* Returns the children of a cluster (on the next zoom level) given its id (cluster_id value from feature properties) and zoom the cluster was from.
|
||||
*/
|
||||
getChildren(clusterId: number, clusterZoom: number): supercluster.Clusters;
|
||||
getChildren(clusterId: number, clusterZoom: number): Clusters;
|
||||
|
||||
/**
|
||||
* Returns all the points of a cluster (given its cluster_id and zoom),
|
||||
* 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).
|
||||
*/
|
||||
getLeaves(clusterId: number, clusterZoom: number, limit?: number, offset?: number): supercluster.Clusters;
|
||||
getLeaves(clusterId: number, clusterZoom: number, limit?: number, offset?: number): Clusters;
|
||||
|
||||
/**
|
||||
* Returns the zoom on which the cluster expands into several children (useful for "click to zoom" feature), given the cluster's cluster_id and zoom.
|
||||
@@ -68,31 +70,29 @@ declare class Supercluster {
|
||||
/**
|
||||
* A very fast JavaScript library for geospatial point clustering for browsers and Node.
|
||||
*/
|
||||
declare function supercluster(options: Options): Supercluster;
|
||||
declare namespace supercluster {
|
||||
type Point = GeoJSON.Feature<GeoJSON.Point>;
|
||||
type Points = Point[];
|
||||
type Clusters = Cluster[];
|
||||
type TileFeatures = TileFeature[];
|
||||
type BBox = [number, number, number, number];
|
||||
interface ClusterProperties {
|
||||
cluster?: boolean;
|
||||
cluster_id?: number;
|
||||
point_count?: number;
|
||||
point_count_abbreviated?: number;
|
||||
sum?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
interface Cluster extends Point {
|
||||
properties: ClusterProperties;
|
||||
}
|
||||
interface TileFeature {
|
||||
type: 1;
|
||||
geometry: Array<[number, number]>;
|
||||
tags: ClusterProperties;
|
||||
}
|
||||
interface Tile {
|
||||
features: TileFeatures;
|
||||
}
|
||||
export default function supercluster(options: Options): Supercluster;
|
||||
|
||||
export type Point = GeoJSON.Feature<GeoJSON.Point>;
|
||||
export type Points = Point[];
|
||||
export type Clusters = Cluster[];
|
||||
export type TileFeatures = TileFeature[];
|
||||
export type BBox = [number, number, number, number];
|
||||
export interface ClusterProperties {
|
||||
cluster?: boolean;
|
||||
cluster_id?: number;
|
||||
point_count?: number;
|
||||
point_count_abbreviated?: number;
|
||||
sum?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface Cluster extends Point {
|
||||
properties: ClusterProperties;
|
||||
}
|
||||
export interface TileFeature {
|
||||
type: 1;
|
||||
geometry: Array<[number, number]>;
|
||||
tags: ClusterProperties;
|
||||
}
|
||||
export interface Tile {
|
||||
features: TileFeatures;
|
||||
}
|
||||
export = supercluster;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as supercluster from 'supercluster';
|
||||
import { Point } from 'supercluster';
|
||||
import supercluster, { Point } from 'supercluster';
|
||||
|
||||
const point1: Point = {
|
||||
type: 'Feature',
|
||||
|
||||
Reference in New Issue
Block a user