Skip to content

Commit a4a3719

Browse files
committed
chore: implement typescript types
1 parent 29225da commit a4a3719

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
},
1414
"main": "dist/react-map-gl-cluster.cjs.js",
1515
"module": "dist/react-map-gl-cluster.esm.js",
16+
"types": "src/index.d.ts",
1617
"files": [
18+
"src/index.d.ts",
1719
"dist"
1820
],
1921
"scripts": {
@@ -45,6 +47,8 @@
4547
"@babel/preset-flow": "^7.9.0",
4648
"@babel/preset-react": "^7.9.4",
4749
"@turf/random": "^6.0.2",
50+
"@types/react": "^16.9.56",
51+
"@types/supercluster": "^5.0.3",
4852
"@urbica/react-map-gl": "^1.13.0",
4953
"babel-eslint": "^10.1.0",
5054
"babel-loader": "^8.1.0",

src/index.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* eslint-disable react/no-unused-prop-types */
2+
/* eslint-disable flowtype/no-types-missing-file-annotation */
3+
import { Component, PureComponent } from 'react'
4+
import Supercluster from 'supercluster'
5+
6+
export type SuperclusterFeature = {
7+
type: 'Feature',
8+
id: number,
9+
properties: {
10+
cluster: true,
11+
cluster_id: number,
12+
point_count: number,
13+
point_count_abbreviated: string | number
14+
},
15+
geometry: {
16+
type: 'Point',
17+
coordinates: [number, number]
18+
}
19+
};
20+
21+
export type ClusterComponentProps = {
22+
longitude: number,
23+
latitude: number,
24+
clusterId: number,
25+
pointCount: number,
26+
pointCountAbbreviated: string | number
27+
};
28+
29+
export type ClusterMapFunction = (props: Record<string, any>) => any;
30+
31+
export type ClusterReduceFunction = (
32+
accumulated: Record<string, any>,
33+
props: Record<string, any>,
34+
) => void;
35+
36+
export type ClusterComponent = Component<ClusterComponentProps, any>
37+
| React.FC<ClusterComponentProps>
38+
39+
40+
type Props = {
41+
/** Minimum zoom level at which clusters are generated */
42+
minZoom?: number,
43+
44+
/** Maximum zoom level at which clusters are generated */
45+
maxZoom?: number,
46+
47+
/** Cluster radius, in pixels */
48+
radius?: number,
49+
50+
/** (Tiles) Tile extent. Radius is calculated relative to this value */
51+
extent?: number,
52+
53+
/** Size of the KD-tree leaf node. Affects performance */
54+
nodeSize?: number,
55+
56+
/**
57+
* A function that returns cluster properties
58+
* corresponding to a single point.
59+
* */
60+
// eslint-disable-next-line react/no-unused-prop-types
61+
map?: ClusterMapFunction,
62+
63+
/** A reduce function that merges properties of two clusters into one. */
64+
// eslint-disable-next-line react/no-unused-prop-types
65+
reduce?: ClusterReduceFunction,
66+
67+
/** React Component for rendering Cluster */
68+
component: ClusterComponent,
69+
}
70+
71+
72+
export default class Cluster extends PureComponent<Props, any> {
73+
getCluster(): Supercluster
74+
}

0 commit comments

Comments
 (0)