@deck.gl/carto
Version:
CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.
52 lines (43 loc) • 1.56 kB
text/typescript
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import {AccessorFunction, DefaultProps} from '@deck.gl/core';
import {
_GeoCellLayer as GeoCellLayer,
_GeoCellLayerProps as GeoCellLayerProps
} from '@deck.gl/geo-layers';
import {getQuadbinPolygon} from './quadbin-utils';
const defaultProps: DefaultProps<QuadbinLayerProps> = {
getQuadbin: {type: 'accessor', value: (d: any) => d.quadbin}
};
/** All properties supported by QuadbinLayer. */
export type QuadbinLayerProps<DataT = unknown> = _QuadbinLayerProps<DataT> &
GeoCellLayerProps<DataT>;
/** Properties added by QuadbinLayer. */
type _QuadbinLayerProps<DataT> = {
/**
* Called for each data object to retrieve the quadbin string identifier.
*
* By default, it reads `quadbin` property of data object.
*/
getQuadbin?: AccessorFunction<DataT, bigint>;
};
export default class QuadbinLayer<DataT = any, ExtraProps extends {} = {}> extends GeoCellLayer<
DataT,
Required<_QuadbinLayerProps<DataT>> & ExtraProps
> {
static layerName = 'QuadbinLayer';
static defaultProps = defaultProps;
indexToBounds(): Partial<GeoCellLayer['props']> | null {
const {data, extruded, getQuadbin} = 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) => getQuadbinPolygon(getQuadbin(x, objectInfo), coverage),
updateTriggers: {getPolygon: coverage}
};
}
}