import {AccessorFunction, DefaultProps} from '@deck.gl/core'; import GeoCellLayer, {GeoCellLayerProps} from '../geo-cell-layer/GeoCellLayer'; import {getQuadkeyPolygon} from './quadkey-utils'; const defaultProps: DefaultProps = { getQuadkey: {type: 'accessor', value: (d: any) => d.quadkey} }; /** All properties supported by QuadkeyLayer. */ export type QuadkeyLayerProps = _QuadkeyLayerProps & GeoCellLayerProps; /** Properties added by QuadkeyLayer. */ type _QuadkeyLayerProps = { /** * Called for each data object to retrieve the quadkey string identifier. * * By default, it reads `quadkey` property of data object. */ getQuadkey?: AccessorFunction; }; /** Render filled and/or stroked polygons based on the [Quadkey](https://towardsdatascience.com/geospatial-indexing-with-quadkeys-d933dff01496) geospatial indexing system. */ export default class QuadkeyLayer extends GeoCellLayer< DataT, Required<_QuadkeyLayerProps> & ExtraProps > { static layerName = 'QuadkeyLayer'; static defaultProps = defaultProps; indexToBounds(): Partial | null { const {data, extruded, getQuadkey} = this.props; // To avoid z-fighting reduce polygon footprint when extruding const coverage = extruded ? 0.99 : 1; return { data, _normalize: false, positionFormat: 'XY', getPolygon: (x: DataT, objectInfo) => getQuadkeyPolygon(getQuadkey(x, objectInfo), coverage), updateTriggers: {getPolygon: coverage} }; } }