import {AccessorFunction, DefaultProps} from '@deck.gl/core'; import GeoCellLayer from '../geo-cell-layer/GeoCellLayer'; import {getGeohashPolygon} from './geohash-utils'; const defaultProps: DefaultProps = { getGeohash: {type: 'accessor', value: (d: any) => d.geohash} }; /** * Properties of `GeohashLayer`. */ export type GeohashLayerProps = { /** * Called for each data object to retrieve the geohash string identifier. * * By default, it reads `geohash` property of data object. */ getGeohash?: AccessorFunction; }; /** Render filled and/or stroked polygons based on the [Geohash](https://en.wikipedia.org/wiki/Geohash) geospatial indexing system. */ export default class GeohashLayer extends GeoCellLayer< DataT, Required & ExtraProps > { static layerName = 'GeohashLayer'; static defaultProps = defaultProps; indexToBounds(): Partial | null { const {data, getGeohash} = this.props; return { data, _normalize: false, positionFormat: 'XY', getPolygon: (x: DataT, objectInfo) => getGeohashPolygon(getGeohash(x, objectInfo)) }; } }