/
geohash-layer.ts
39 lines (34 loc) · 1.21 KB
/
geohash-layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {AccessorFunction, DefaultProps} from '@deck.gl/core';
import GeoCellLayer from '../geo-cell-layer/GeoCellLayer';
import {getGeohashPolygon} from './geohash-utils';
const defaultProps: DefaultProps<GeohashLayerProps> = {
getGeohash: {type: 'accessor', value: (d: any) => d.geohash}
};
/**
* Properties of `GeohashLayer`.
*/
export type GeohashLayerProps<DataT = unknown> = {
/**
* Called for each data object to retrieve the geohash string identifier.
*
* By default, it reads `geohash` property of data object.
*/
getGeohash?: AccessorFunction<DataT, string>;
};
/** Render filled and/or stroked polygons based on the [Geohash](https://en.wikipedia.org/wiki/Geohash) geospatial indexing system. */
export default class GeohashLayer<DataT = any, ExtraProps extends {} = {}> extends GeoCellLayer<
DataT,
Required<GeohashLayerProps> & ExtraProps
> {
static layerName = 'GeohashLayer';
static defaultProps = defaultProps;
indexToBounds(): Partial<GeoCellLayer['props']> | null {
const {data, getGeohash} = this.props;
return {
data,
_normalize: false,
positionFormat: 'XY',
getPolygon: (x: DataT, objectInfo) => getGeohashPolygon(getGeohash(x, objectInfo))
};
}
}