From 430e4516263e8cc5ea5cfe50b9f86c57e5269d24 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Fri, 6 Oct 2017 21:44:28 +0100 Subject: [PATCH] Improve supercluster types (#20348) * Improve supercluster types * Remove remaining declare --- types/supercluster/index.d.ts | 70 ++++++++++++------------ types/supercluster/supercluster-tests.ts | 3 +- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/types/supercluster/index.d.ts b/types/supercluster/index.d.ts index 6d3e6c3895..2954bb3763 100644 --- a/types/supercluster/index.d.ts +++ b/types/supercluster/index.d.ts @@ -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 // 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; - 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; +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; diff --git a/types/supercluster/supercluster-tests.ts b/types/supercluster/supercluster-tests.ts index 36993be0c2..2fe5eeff39 100644 --- a/types/supercluster/supercluster-tests.ts +++ b/types/supercluster/supercluster-tests.ts @@ -1,5 +1,4 @@ -import * as supercluster from 'supercluster'; -import { Point } from 'supercluster'; +import supercluster, { Point } from 'supercluster'; const point1: Point = { type: 'Feature',