mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
supercluster: added initial,map,reduce to Options
This commit is contained in:
committed by
Kenneth Lee
parent
99f93266bb
commit
b3f06feb45
21
types/supercluster/index.d.ts
vendored
21
types/supercluster/index.d.ts
vendored
@@ -33,6 +33,27 @@ export interface Options {
|
||||
* Whether timing info should be logged.
|
||||
*/
|
||||
log?: boolean;
|
||||
/**
|
||||
* a reduce function for calculating custom cluster properties
|
||||
*
|
||||
* @example
|
||||
* function (accumulated, props) { accumulated.sum += props.sum; }
|
||||
*/
|
||||
reduce?: (accumulated: any, props: any) => void;
|
||||
/**
|
||||
* initial properties of a cluster (before running the reducer)
|
||||
*
|
||||
* @example
|
||||
* function () { return {sum: 0}; }
|
||||
*/
|
||||
initial?: () => any;
|
||||
/**
|
||||
* properties to use for individual points when running the reducer
|
||||
*
|
||||
* @example
|
||||
* function (props) { return {sum: props.my_value}; }
|
||||
*/
|
||||
map?: (props: any) => any;
|
||||
}
|
||||
|
||||
export class Supercluster {
|
||||
|
||||
@@ -2,21 +2,36 @@ import supercluster, { Point } from 'supercluster';
|
||||
|
||||
const point1: Point = {
|
||||
type: 'Feature',
|
||||
properties: {},
|
||||
properties: {my_value: 2},
|
||||
geometry: { type: 'Point', coordinates: [10, 20] }
|
||||
};
|
||||
const point2: Point = {
|
||||
type: 'Feature',
|
||||
properties: {},
|
||||
properties: {my_value: 3},
|
||||
geometry: { type: 'Point', coordinates: [20, 30] }
|
||||
};
|
||||
const points = [point1, point2];
|
||||
|
||||
const initialFunction = () => {
|
||||
return {sum: 0};
|
||||
};
|
||||
|
||||
const mapFunction = (props: any) => {
|
||||
return {sum: props.my_value};
|
||||
};
|
||||
|
||||
const reduceFunction = (accumulated: any, props: any) => {
|
||||
accumulated.sum += props.sum;
|
||||
};
|
||||
|
||||
const index = supercluster({
|
||||
radius: 40,
|
||||
maxZoom: 16,
|
||||
extent: 256,
|
||||
log: true
|
||||
log: true,
|
||||
initial: initialFunction,
|
||||
map: mapFunction,
|
||||
reduce: reduceFunction,
|
||||
});
|
||||
index.load(points);
|
||||
const clusters = index.getClusters([-180, -85, 180, 85], 2);
|
||||
|
||||
Reference in New Issue
Block a user