|
| 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