Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

feat: add GeoHash layer (#3666)

Igor Dykhta30b0f648de0b
diff --git a/SUMMARY.md b/SUMMARY.md
index 489d50792..d940c60e9 100644
--- a/SUMMARY.md
+++ b/SUMMARY.md
@@ -16,6 +16,7 @@
* [Point](docs/user-guides/c-types-of-layers/a-point.md)
* [S2 Layer](docs/user-guides/c-types-of-layers/l-s2.md)
* [A5 Layer](docs/user-guides/c-types-of-layers/q-a5.md)
+ * [GeoHash Layer](docs/user-guides/c-types-of-layers/r-geohash.md)
* [Icon](docs/user-guides/c-types-of-layers/g-icon.md)
* [Line](docs/user-guides/c-types-of-layers/c-line.md)
* [Cluster](docs/user-guides/c-types-of-layers/f-cluster.md)
diff --git a/docs/table-of-contents.json b/docs/table-of-contents.json
index df0385283..4e12d56df 100644
--- a/docs/table-of-contents.json
+++ b/docs/table-of-contents.json
@@ -47,7 +47,8 @@
{"entry": "docs/user-guides/c-types-of-layers/i-heatmap"},
{"entry": "docs/user-guides/c-types-of-layers/j-h3"},
{"entry": "docs/user-guides/c-types-of-layers/k.trip"},
- {"entry": "docs/user-guides/c-types-of-layers/q-a5"}
+ {"entry": "docs/user-guides/c-types-of-layers/q-a5"},
+ {"entry": "docs/user-guides/c-types-of-layers/r-geohash"}
]
}
]
diff --git a/docs/user-guides/README.md b/docs/user-guides/README.md
index 8232f433b..b6c544dfc 100644
--- a/docs/user-guides/README.md
+++ b/docs/user-guides/README.md
@@ -38,6 +38,7 @@ This guide will teach you how to perform data analysis in Kepler.gl by adding da
* [Trip](./c-types-of-layers/k-trip.md)
* [S2](./c-types-of-layers/l-s2.md)
* [A5](./c-types-of-layers/q-a5.md)
+* [GeoHash](./c-types-of-layers/r-geohash.md)
* [Vector Tile Layer](./c-types-of-layers/m-vector-tile-layer.md)
* [Raster Tile Layer](./c-types-of-layers/n-raster-tile-layer.md)
* [WMS Layer](./c-types-of-layers/o-wms-layer.md)
diff --git a/docs/user-guides/c-types-of-layers/README.md b/docs/user-guides/c-types-of-layers/README.md
index 940873a78..8a8ec7891 100644
--- a/docs/user-guides/c-types-of-layers/README.md
+++ b/docs/user-guides/c-types-of-layers/README.md
@@ -100,6 +100,12 @@ To use A5 layer, you need to assign a column containing [A5](https://a5geo.org)
The A5 layer is optional and disabled by default. Enable it with `enableA5Layer: true` in the application configuration.
+## GeoHash Layer
+
+To use GeoHash layer, you need to assign a column containing [Geohash](https://en.wikipedia.org/wiki/Geohash) cell identifiers. Kepler.gl auto-detects columns named `geohash`, `geo_hash`, or `geohash_id`.
+
+The GeoHash layer is optional and enabled by default. Disable it with `enableGeohashLayer: false` in the application configuration.
+
## Vector Tile Layer
![Vector Tile layer](https://4sq-studio-public.s3.us-west-2.amazonaws.com/statics/keplergl/documentation/layer-types/vector-tile.png 'Vector Tile Layer')
diff --git a/docs/user-guides/c-types-of-layers/r-geohash.md b/docs/user-guides/c-types-of-layers/r-geohash.md
new file mode 100644
index 000000000..92c9564b0
--- /dev/null
+++ b/docs/user-guides/c-types-of-layers/r-geohash.md
@@ -0,0 +1,32 @@
+# GeoHash Layer
+
+To use GeoHash layer, you need to assign a column containing [Geohash](https://en.wikipedia.org/wiki/Geohash) cell identifiers.
+
+### Enable the layer
+
+The GeoHash layer is optional and **enabled by default**. Disable it in your app config:
+
+```js
+import {initApplicationConfig} from '@kepler.gl/utils';
+
+initApplicationConfig({enableGeohashLayer: false});
+```
+
+### Naming Convention
+
+Kepler.gl **auto generates** a GeoHash layer from a column named `geohash`, `geo_hash`, or `geohash_id`.
+
+### Simple Dataset
+
+| geohash | value |
+| ------- | :-----------------: |
+| 9q8yyk | 0.5979242952642347 |
+| 9q8yyw | 0.5446256069712141 |
+| 9q8yy4 | 0.1187171597109975 |
+| 9q8zn8 | 0.2859146314037557 |
+| 9q8yvc | 0.19549012367504126 |
+| 9q8znf | 0.3373452974230604 |
+| 9q8ytx | 0.9218176408795662 |
+| 9q8zp5 | 0.23470692356446143 |
+
+[Back to table of contents](../README.md)
diff --git a/examples/demo-app/src/data/sample-geohash-data.js b/examples/demo-app/src/data/sample-geohash-data.js
new file mode 100644
index 000000000..801e6dda1
--- /dev/null
+++ b/examples/demo-app/src/data/sample-geohash-data.js
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+export default `geohash,value
+9q8yyk,0.5979242952642347
+9q8yyw,0.5446256069712141
+9q8yy4,0.1187171597109975
+9q8zn8,0.2859146314037557
+9q8yvc,0.19549012367504126
+9q8znf,0.3373452974230604
+9q8ytx,0.9218176408795662
+9q8zp5,0.23470692356446143
+`;
+
+export const dataId = 'geohash-data';
+export const config = {
+ version: 'v1',
+ config: {
+ visState: {
+ filters: [],
+ layers: [
+ {
+ type: 'geohash',
+ config: {
+ dataId,
+ label: 'GeoHash Layer',
+ color: [241, 92, 23],
+ columns: {
+ token: 'geohash'
+ },
+ isVisible: true,
+ visConfig: {
+ opacity: 0.8,
+ strokeColor: [253, 230, 230],
+ colorRange: {
+ name: 'Global Warming',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
+ }
+ }
+ },
+ visualChannels: {
+ colorField: {
+ name: 'value',
+ type: 'real'
+ },
+ colorScale: 'quantile'
+ }
+ }
+ ]
+ }
+ }
+};
diff --git a/examples/demo-app/src/reducers/index.js b/examples/demo-app/src/reducers/index.js
index 9540c7011..326866613 100644
--- a/examples/demo-app/src/reducers/index.js
+++ b/examples/demo-app/src/reducers/index.js
@@ -56,6 +56,7 @@ initApplicationConfig({
// NOTE: Cell winding must be counter-clockwise (CCW) to match the CDN icon convention.
initApplicationConfig({
enableA5Layer: true,
+ enableGeohashLayer: true,
customIcons: [
{
id: 'custom-star',
@@ -78,7 +79,8 @@ initApplicationConfig({
}
}
],
- customIconUrl: 'https://raw.githubusercontent.com/keplergl/kepler.gl-data/refs/heads/master/layers/icon/custom-icons.json'
+ customIconUrl:
+ 'https://raw.githubusercontent.com/keplergl/kepler.gl-data/refs/heads/master/layers/icon/custom-icons.json'
});
const {DEFAULT_MAP_CONTROLS} = uiStateUpdaters;
diff --git a/src/ai-assistant/src/tools/kepler-tools/layer-creation-tool.tsx b/src/ai-assistant/src/tools/kepler-tools/layer-creation-tool.tsx
index 46d8a6e5d..756121d64 100644
--- a/src/ai-assistant/src/tools/kepler-tools/layer-creation-tool.tsx
+++ b/src/ai-assistant/src/tools/kepler-tools/layer-creation-tool.tsx
@@ -29,7 +29,8 @@ export const addLayer = extendedTool<
'h3',
'trip',
's2',
- 'a5'
+ 'a5',
+ 'geohash'
]
>;
colorBy: z.ZodOptional<z.ZodString>;
@@ -92,7 +93,8 @@ For geojson datasets:
'h3',
'trip',
's2',
- 'a5'
+ 'a5',
+ 'geohash'
]),
colorBy: z.string().optional(),
colorType: z.enum(['breaks', 'unique']).optional(),
diff --git a/src/components/src/side-panel/layer-manager.tsx b/src/components/src/side-panel/layer-manager.tsx
index 91721cec7..8122626c1 100644
--- a/src/components/src/side-panel/layer-manager.tsx
+++ b/src/components/src/side-panel/layer-manager.tsx
@@ -207,6 +207,7 @@ function LayerManagerFactory(
const enableWMSLayer = getApplicationConfig().enableWMSLayer;
const enableFlowLayer = getApplicationConfig().enableFlowLayer;
const enableA5Layer = getApplicationConfig().enableA5Layer;
+ const enableGeohashLayer = getApplicationConfig().enableGeohashLayer;
const enableLayerGroups = getApplicationConfig().enableLayerGroups;
const filteredLayerClasses = useMemo(() => {
@@ -227,8 +228,19 @@ function LayerManagerFactory(
const {a5: _a5, ...rest} = filteredClasses;
filteredClasses = rest as LayerClassesType;
}
+ if (!enableGeohashLayer) {
+ const {geohash: _geohash, ...rest} = filteredClasses;
+ filteredClasses = rest as LayerClassesType;
+ }
return filteredClasses as LayerClassesType;
- }, [enableRasterTileLayer, enableWMSLayer, enableFlowLayer, enableA5Layer, layerClasses]);
+ }, [
+ enableRasterTileLayer,
+ enableWMSLayer,
+ enableFlowLayer,
+ enableA5Layer,
+ enableGeohashLayer,
+ layerClasses
+ ]);
return (
<div className="layer-manager">
diff --git a/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx b/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx
index 8ea14e77b..8c49b1e49 100644
--- a/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx
+++ b/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx
@@ -67,6 +67,7 @@ function DatasetLayerSectionFactory(
const enableFlowLayer = getApplicationConfig().enableFlowLayer;
const enableBitmapLayer = getApplicationConfig().enableBitmapLayer;
const enableA5Layer = getApplicationConfig().enableA5Layer;
+ const enableGeohashLayer = getApplicationConfig().enableGeohashLayer;
const filteredLayerClasses = useMemo(() => {
let filteredClasses = layerClasses;
@@ -90,6 +91,10 @@ function DatasetLayerSectionFactory(
const {a5: _a5, ...rest} = filteredClasses;
filteredClasses = rest as LayerClassesType;
}
+ if (!enableGeohashLayer) {
+ const {geohash: _geohash, ...rest} = filteredClasses;
+ filteredClasses = rest as LayerClassesType;
+ }
return filteredClasses as LayerClassesType;
}, [
enableRasterTileLayer,
@@ -97,6 +102,7 @@ function DatasetLayerSectionFactory(
enableFlowLayer,
enableBitmapLayer,
enableA5Layer,
+ enableGeohashLayer,
layerClasses
]);
diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
index 4c922f90e..ab3442b4a 100644
--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
@@ -7,7 +7,13 @@ import React, {Component, Fragment, useCallback, useRef, useState} from 'react';
import styled from 'styled-components';
import ItemSelector from '../../common/item-selector/item-selector';
-import {Input, InputLight, PanelLabel, PanelLabelWrapper, SidePanelSection} from '../../common/styled-components';
+import {
+ Input,
+ InputLight,
+ PanelLabel,
+ PanelLabelWrapper,
+ SidePanelSection
+} from '../../common/styled-components';
import SourceDataSelectorFactory from '../common/source-data-selector';
import AggrScaleSelectorFactory from './aggr-scale-selector';
@@ -39,7 +45,13 @@ import {
CUSTOM_SCENEGRAPH_MODEL_ID,
BitmapDatasetMetadata
} from '@kepler.gl/constants';
-import {AggregationLayer, Layer, LayerBaseConfig, VisualChannel, COLUMN_MODE_GEOJSON} from '@kepler.gl/layers';
+import {
+ AggregationLayer,
+ Layer,
+ LayerBaseConfig,
+ VisualChannel,
+ COLUMN_MODE_GEOJSON
+} from '@kepler.gl/layers';
import {matchDatasetType, Datasets} from '@kepler.gl/table';
import {ColorUI, LayerVisConfig, NestedPartial} from '@kepler.gl/types';
@@ -107,7 +119,8 @@ const StyledLayerVisualConfigurator = styled.div.attrs({
`;
const BitmapDropZone = styled.div<{$isDragging: boolean}>`
- border: 2px dashed ${props => (props.$isDragging ? props.theme.activeColor : props.theme.borderColor)};
+ border: 2px dashed
+ ${props => (props.$isDragging ? props.theme.activeColor : props.theme.borderColor)};
border-radius: 4px;
padding: 12px;
text-align: center;
@@ -177,13 +190,10 @@ const BitmapImageSourceSection: React.FC<BitmapImageSourceProps> = ({dataset, on
[dataset, onChange]
);
- const onUrlChange = useCallback(
- (e: React.ChangeEvent<HTMLInputElement>) => {
- setUrl(e.target.value);
- setError(null);
- },
- []
- );
+ const onUrlChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
+ setUrl(e.target.value);
+ setError(null);
+ }, []);
const onUrlBlur = useCallback(() => {
if (url) {
@@ -268,7 +278,9 @@ const BitmapImageSourceSection: React.FC<BitmapImageSourceProps> = ({dataset, on
/>
<BitmapDropZoneWrapper>
{isCurrentDataUri && (
- <BitmapClearButton onClick={onClearLocal} title="Clear image">✕</BitmapClearButton>
+ <BitmapClearButton onClick={onClearLocal} title="Clear image">
+ ✕
+ </BitmapClearButton>
)}
<BitmapDropZone
$isDragging={isDragging}
@@ -277,7 +289,9 @@ const BitmapImageSourceSection: React.FC<BitmapImageSourceProps> = ({dataset, on
onDragLeave={onDragLeave}
onClick={onDropZoneClick}
>
- {isCurrentDataUri ? 'Local image loaded. Drop another to replace.' : 'Drop image here or click to select'}
+ {isCurrentDataUri
+ ? 'Local image loaded. Drop another to replace.'
+ : 'Drop image here or click to select'}
</BitmapDropZone>
</BitmapDropZoneWrapper>
<input
@@ -301,7 +315,7 @@ const AlignModeContainer = styled.div`
const AlignModeStatus = styled.div<{$highlight?: boolean}>`
padding: 6px 8px;
border-radius: 4px;
- background: ${props => props.$highlight ? props.theme.panelBackgroundHover : 'transparent'};
+ background: ${props => (props.$highlight ? props.theme.panelBackgroundHover : 'transparent')};
margin-bottom: 6px;
line-height: 1.4;
`;
@@ -1487,6 +1501,20 @@ export default function LayerConfiguratorFactory(
);
}
+ _renderGeohashLayerConfig({
+ layer,
+ visConfiguratorProps,
+ layerConfiguratorProps,
+ layerChannelConfigProps
+ }) {
+ return this._renderA5LayerConfig({
+ layer,
+ visConfiguratorProps,
+ layerConfiguratorProps,
+ layerChannelConfigProps
+ });
+ }
+
_renderA5LayerConfig({
layer,
visConfiguratorProps,
@@ -1611,10 +1639,7 @@ export default function LayerConfiguratorFactory(
return (
<StyledLayerVisualConfigurator>
<LayerConfigGroup label={'layer.imageSource'} collapsible>
- <BitmapImageSourceSection
- dataset={dataset}
- onChange={visConfiguratorProps.onChange}
- />
+ <BitmapImageSourceSection dataset={dataset} onChange={visConfiguratorProps.onChange} />
</LayerConfigGroup>
<LayerConfigGroup label={'layer.appearance'}>
<VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} />
diff --git a/src/constants/src/layers.ts b/src/constants/src/layers.ts
index 8d5990764..70096efe1 100644
--- a/src/constants/src/layers.ts
+++ b/src/constants/src/layers.ts
@@ -608,6 +608,7 @@ export const LAYER_TYPES = keyMirror({
trip: null,
s2: null,
a5: null,
+ geohash: null,
flow: null,
vectorTile: null,
rasterTile: null,
diff --git a/src/deckgl-types.d.ts b/src/deckgl-types.d.ts
index 582c31dee..f7c6ac35b 100644
--- a/src/deckgl-types.d.ts
+++ b/src/deckgl-types.d.ts
@@ -105,6 +105,7 @@ declare module '@deck.gl/geo-layers' {
export {default as H3ClusterLayer} from '@deck.gl/geo-layers/dist/h3-layers/h3-cluster-layer';
export {default as S2Layer} from '@deck.gl/geo-layers/dist/s2-layer/s2-layer';
export {default as A5Layer} from '@deck.gl/geo-layers/dist/a5-layer/a5-layer';
+ export {default as GeohashLayer} from '@deck.gl/geo-layers/dist/geohash-layer/geohash-layer';
export {default as TripsLayer} from '@deck.gl/geo-layers/dist/trips-layer/trips-layer';
export {default as TileLayer} from '@deck.gl/geo-layers/dist/tile-layer/tile-layer';
export {default as MVTLayer} from '@deck.gl/geo-layers/dist/mvt-layer/mvt-layer';
@@ -115,6 +116,7 @@ declare module '@deck.gl/geo-layers' {
export type {H3HexagonLayerProps} from '@deck.gl/geo-layers/dist/h3-layers/h3-hexagon-layer';
export type {S2LayerProps} from '@deck.gl/geo-layers/dist/s2-layer/s2-layer';
export type {A5LayerProps} from '@deck.gl/geo-layers/dist/a5-layer/a5-layer';
+ export type {GeohashLayerProps} from '@deck.gl/geo-layers/dist/geohash-layer/geohash-layer';
export type {
TileLayerProps,
TileLayerPickingInfo
diff --git a/src/layers/src/geohash-layer/geohash-layer-icon.tsx b/src/layers/src/geohash-layer/geohash-layer-icon.tsx
new file mode 100644
index 000000000..2a3c18aad
--- /dev/null
+++ b/src/layers/src/geohash-layer/geohash-layer-icon.tsx
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import React from 'react';
+import {Base, BaseProps} from '../base';
+
+const GeohashLayerIcon: React.FC<Partial<BaseProps>> = ({
+ height = '18px',
+ predefinedClassName = 'geohash-layer-icon',
+ ...props
+}) => (
+ <Base height={height} predefinedClassName={predefinedClassName} {...props}>
+ <path d="M8,12H56V52H8Zm4,4V48H52V16Z" />
+ <path d="M20,22H44V42H20Zm4,4V38H40V26Z" />
+ </Base>
+);
+
+export default GeohashLayerIcon;
diff --git a/src/layers/src/geohash-layer/geohash-layer.ts b/src/layers/src/geohash-layer/geohash-layer.ts
new file mode 100644
index 000000000..ea13d0a08
--- /dev/null
+++ b/src/layers/src/geohash-layer/geohash-layer.ts
@@ -0,0 +1,408 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import {GeohashLayer as DeckGeohashLayer} from '@deck.gl/geo-layers';
+import {GeoJsonLayer} from '@deck.gl/layers';
+import type {Feature} from 'geojson';
+import {
+ HIGHLIGH_COLOR_3D,
+ CHANNEL_SCALES,
+ LAYER_VIS_CONFIGS,
+ DEFAULT_COLOR_UI
+} from '@kepler.gl/constants';
+import {default as KeplerTable} from '@kepler.gl/table';
+import Layer, {
+ LayerBaseConfig,
+ LayerBaseConfigPartial,
+ LayerColorConfig,
+ LayerSizeConfig,
+ LayerStrokeColorConfig,
+ LayerHeightConfig
+} from '../base-layer';
+import {
+ ColorRange,
+ Merge,
+ RGBColor,
+ VisConfigBoolean,
+ VisConfigColorRange,
+ VisConfigColorSelect,
+ VisConfigNumber,
+ VisConfigRange,
+ LayerColumn
+} from '@kepler.gl/types';
+import GeohashLayerIcon from './geohash-layer-icon';
+import {
+ geohashToPolygonGeo,
+ getGeohashCenter,
+ normalizeGeohash,
+ validGeohash
+} from './geohash-utils';
+import {DataContainerInterface, createDataContainer} from '@kepler.gl/utils';
+
+export type GeohashLayerVisConfigSettings = {
+ opacity: VisConfigNumber;
+ colorRange: VisConfigColorRange;
+ filled: VisConfigBoolean;
+ thickness: VisConfigNumber;
+ strokeColor: VisConfigColorSelect;
+ strokeColorRange: VisConfigColorRange;
+ sizeRange: VisConfigRange;
+ stroked: VisConfigBoolean;
+ enable3d: VisConfigBoolean;
+ elevationScale: VisConfigNumber;
+ enableElevationZoomFactor: VisConfigBoolean;
+ heightRange: VisConfigRange;
+ wireframe: VisConfigBoolean;
+};
+
+export type GeohashLayerColumnsConfig = {
+ token: LayerColumn;
+};
+
+export type GeohashLayerVisConfig = {
+ opacity: number;
+ colorRange: ColorRange;
+ filled: boolean;
+ thickness: number;
+ strokeColor: RGBColor;
+ strokeColorRange: ColorRange;
+ sizeRange: [number, number];
+ stroked: boolean;
+ enable3d: boolean;
+ elevationScale: number;
+ enableElevationZoomFactor: boolean;
+ heightRange: [number, number];
+ wireframe: boolean;
+};
+
+export type GeohashLayerVisualChannelConfig = LayerColorConfig &
+ LayerSizeConfig &
+ LayerStrokeColorConfig &
+ LayerHeightConfig;
+export type GeohashLayerConfig = Merge<
+ LayerBaseConfig,
+ {columns: GeohashLayerColumnsConfig; visConfig: GeohashLayerVisConfig}
+> &
+ GeohashLayerVisualChannelConfig;
+
+export type GeohashLayerData = {
+ index: number;
+ token: string;
+};
+
+const zoomFactorValue = 8;
+const DEFAULT_LINE_SCALE_VALUE = 8;
+
+export const GEOHASH_TOKEN_FIELDS: {
+ token: ['geohash', 'geo_hash', 'geohash_id'];
+} = {
+ token: ['geohash', 'geo_hash', 'geohash_id']
+};
+
+export const geohashRequiredColumns: ['token'] = ['token'];
+export const GeohashTokenAccessor =
+ ({token}: GeohashLayerColumnsConfig) =>
+ (dc: DataContainerInterface) =>
+ d =>
+ dc.valueAt(d.index, token.fieldIdx);
+
+export const defaultElevation = 500;
+export const defaultLineWidth = 1;
+
+export const GeohashVisConfigs: {
+ // Filled color
+ opacity: 'opacity';
+ colorRange: 'colorRange';
+ filled: VisConfigBoolean;
+
+ // stroke
+ thickness: VisConfigNumber;
+ strokeColor: 'strokeColor';
+ strokeColorRange: 'strokeColorRange';
+ sizeRange: 'strokeWidthRange';
+ stroked: 'stroked';
+
+ // height
+ enable3d: 'enable3d';
+ elevationScale: 'elevationScale';
+ enableElevationZoomFactor: 'enableElevationZoomFactor';
+ fixedHeight: 'fixedHeight';
+ heightRange: 'elevationRange';
+
+ // wireframe
+ wireframe: 'wireframe';
+} = {
+ // Filled color
+ opacity: 'opacity',
+ colorRange: 'colorRange',
+ filled: {
+ ...LAYER_VIS_CONFIGS.filled,
+ type: 'boolean',
+ label: 'Fill Color',
+ defaultValue: true,
+ property: 'filled'
+ },
+
+ // stroke
+ thickness: {
+ ...LAYER_VIS_CONFIGS.thickness,
+ defaultValue: 0.5
+ },
+ strokeColor: 'strokeColor',
+ strokeColorRange: 'strokeColorRange',
+ sizeRange: 'strokeWidthRange',
+ stroked: 'stroked',
+
+ // height
+ enable3d: 'enable3d',
+ elevationScale: 'elevationScale',
+ enableElevationZoomFactor: 'enableElevationZoomFactor',
+ fixedHeight: 'fixedHeight',
+ heightRange: 'elevationRange',
+
+ // wireframe
+ wireframe: 'wireframe'
+};
+
+export default class GeohashGeometryLayer extends Layer {
+ dataToFeature: any;
+ declare visConfigSettings: GeohashLayerVisConfigSettings;
+ declare config: GeohashLayerConfig;
+ constructor(props) {
+ super(props);
+ this.registerVisConfig(GeohashVisConfigs);
+ this.getPositionAccessor = (dataContainer: DataContainerInterface) =>
+ GeohashTokenAccessor(this.config.columns)(dataContainer);
+ }
+
+ get type(): 'geohash' {
+ return 'geohash';
+ }
+
+ get name(): 'GeoHash' {
+ return 'GeoHash';
+ }
+
+ get requiredLayerColumns() {
+ return geohashRequiredColumns;
+ }
+
+ get layerIcon() {
+ return GeohashLayerIcon;
+ }
+
+ get visualChannels() {
+ const visualChannels = super.visualChannels;
+ return {
+ color: {
+ ...visualChannels.color,
+ accessor: 'getFillColor'
+ },
+ size: {
+ ...visualChannels.size,
+ property: 'stroke',
+ accessor: 'getLineWidth',
+ condition: config => config.visConfig.stroked,
+ defaultValue: defaultLineWidth
+ },
+ strokeColor: {
+ property: 'strokeColor',
+ field: 'strokeColorField',
+ scale: 'strokeColorScale',
+ domain: 'strokeColorDomain',
+ range: 'strokeColorRange',
+ key: 'strokeColor',
+ channelScaleType: CHANNEL_SCALES.color,
+ accessor: 'getLineColor',
+ condition: config => config.visConfig.stroked,
+ nullValue: visualChannels.color.nullValue,
+ defaultValue: config => config.visConfig.strokeColor || config.color
+ },
+ height: {
+ property: 'height',
+ field: 'heightField',
+ scale: 'heightScale',
+ domain: 'heightDomain',
+ range: 'heightRange',
+ key: 'height',
+ channelScaleType: CHANNEL_SCALES.size,
+ accessor: 'getElevation',
+ condition: config => config.visConfig.enable3d,
+ nullValue: 0,
+ defaultValue: defaultElevation
+ }
+ };
+ }
+
+ getDefaultLayerConfig(props: LayerBaseConfigPartial) {
+ const defaultLayerConfig = super.getDefaultLayerConfig(props ?? {});
+ return {
+ ...defaultLayerConfig,
+
+ // add height visual channel
+ heightField: null,
+ heightDomain: [0, 1],
+ heightScale: 'linear',
+
+ // add stroke color visual channel
+ strokeColorField: null,
+ strokeColorDomain: [0, 1],
+ strokeColorScale: 'quantile',
+ colorUI: {
+ ...defaultLayerConfig.colorUI,
+ strokeColorRange: DEFAULT_COLOR_UI
+ }
+ };
+ }
+
+ static findDefaultLayerProps({fields = []}: KeplerTable) {
+ const foundColumns = this.findDefaultColumnField(GEOHASH_TOKEN_FIELDS, fields);
+ if (!foundColumns || !foundColumns.length) {
+ return {props: []};
+ }
+
+ return {
+ props: foundColumns.map(columns => ({
+ isVisible: true,
+ label: 'GeoHash',
+ columns
+ }))
+ };
+ }
+
+ calculateDataAttribute({filteredIndex}: KeplerTable, getGeohashToken) {
+ const data: GeohashLayerData[] = [];
+ for (let i = 0; i < filteredIndex.length; i++) {
+ const index = filteredIndex[i];
+ const token = getGeohashToken({index});
+ const normalized = normalizeGeohash(token);
+ if (normalized) {
+ data.push({
+ index,
+ token: normalized
+ });
+ }
+ }
+ return data;
+ }
+
+ updateLayerMeta(dataset: KeplerTable, getGeohashToken) {
+ const {dataContainer} = dataset;
+ const centroids = dataContainer.reduce(
+ (acc, entry, index) => {
+ const token = getGeohashToken({index});
+ if (validGeohash(token)) {
+ const center = getGeohashCenter(token);
+ if (center) {
+ acc.push(center);
+ }
+ }
+
+ return acc;
+ },
+ [],
+ true
+ );
+
+ const centroidsDataContainer = createDataContainer(centroids);
+ const bounds = this.getPointsBounds(centroidsDataContainer, (d, dc) => [
+ dc.valueAt(d.index, 0),
+ dc.valueAt(d.index, 1)
+ ]);
+ this.dataToFeature = {centroids};
+ this.updateMeta({bounds});
+ }
+
+ formatLayerData(datasets, oldLayerData) {
+ if (this.config.dataId === null) {
+ return {};
+ }
+ const {gpuFilter, dataContainer} = datasets[this.config.dataId];
+ const getGeohashToken = this.getPositionAccessor(dataContainer);
+ const {data} = this.updateData(datasets, oldLayerData);
+
+ const accessors = this.getAttributeAccessors({dataContainer});
+
+ return {
+ data,
+ getGeohashToken,
+ getFilterValue: gpuFilter.filterValueAccessor(dataContainer)(),
+ ...accessors
+ };
+ }
+
+ /**
+ * Composite deck.gl layers report sublayer ids (e.g. `${id}-cell-fill`).
+ * Treat those as belonging to this layer so hover outlines can render.
+ */
+ isLayerHovered(objectInfo): boolean {
+ const layerId = objectInfo?.layer?.id ?? objectInfo?.layer?.props?.id;
+ return Boolean(
+ objectInfo?.picked &&
+ typeof layerId === 'string' &&
+ (layerId === this.id || layerId.startsWith(`${this.id}-`))
+ );
+ }
+
+ renderLayer(opts) {
+ const {data, gpuFilter, objectHovered, interactionConfig, mapState} = opts;
+
+ const defaultLayerProps = this.getDefaultDeckLayerProps(opts);
+
+ const eleZoomFactor = this.getElevationZoomFactor(mapState);
+ const zoomFactor = this.getZoomFactor(mapState);
+ const {config} = this;
+ const {visConfig} = config;
+ const hoveredObject = this.hasHoveredObject(objectHovered);
+
+ const updateTriggers = {
+ ...this.getVisualChannelUpdateTriggers(),
+ getFilterValue: gpuFilter.filterValueUpdateTriggers
+ };
+
+ return [
+ new DeckGeohashLayer({
+ ...defaultLayerProps,
+ ...interactionConfig,
+ ...data,
+ getGeohash: (d: any) => d.token,
+
+ autoHighlight: visConfig.enable3d,
+ highlightColor: HIGHLIGH_COLOR_3D,
+
+ // stroke
+ lineWidthScale: visConfig.thickness * zoomFactor * zoomFactorValue,
+ stroked: visConfig.stroked,
+ lineMiterLimit: 2,
+
+ // Filled color
+ filled: visConfig.filled,
+ opacity: visConfig.opacity,
+ wrapLongitude: false,
+
+ // Elevation
+ elevationScale: visConfig.elevationScale * eleZoomFactor,
+ extruded: visConfig.enable3d,
+
+ wireframe: visConfig.wireframe,
+
+ pickable: true,
+
+ updateTriggers
+ }),
+ // hover outline (2D); 3D uses autoHighlight
+ ...(hoveredObject && !visConfig.enable3d
+ ? [
+ new GeoJsonLayer({
+ ...this.getDefaultHoverLayerProps(),
+ visible: defaultLayerProps.visible,
+ data: [geohashToPolygonGeo(hoveredObject)].filter(Boolean) as Feature[],
+ getLineColor: config.highlightColor,
+ lineWidthScale: DEFAULT_LINE_SCALE_VALUE * zoomFactor,
+ wrapLongitude: false
+ })
+ ]
+ : [])
+ ];
+ }
+}
diff --git a/src/layers/src/geohash-layer/geohash-utils.ts b/src/layers/src/geohash-layer/geohash-utils.ts
new file mode 100644
index 000000000..de969a8ee
--- /dev/null
+++ b/src/layers/src/geohash-layer/geohash-utils.ts
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import type {Feature, LineString, Polygon} from 'geojson';
+
+const BASE32_CODES = '0123456789bcdefghjkmnpqrstuvwxyz';
+const BASE32_CODES_DICT: Record<string, number> = {};
+for (let i = 0; i < BASE32_CODES.length; i++) {
+ BASE32_CODES_DICT[BASE32_CODES.charAt(i)] = i;
+}
+
+const GEOHASH_RE = /^[0123456789bcdefghjkmnpqrstuvwxyz]+$/;
+const MIN_GEOHASH_LENGTH = 1;
+const MAX_GEOHASH_LENGTH = 12;
+
+const MIN_LAT = -90;
+const MAX_LAT = 90;
+const MIN_LON = -180;
+const MAX_LON = 180;
+
+export function maybeStripQuotes(token: string): string {
+ if (token.length >= 2) {
+ const first = token[0];
+ const last = token[token.length - 1];
+ if ((first === "'" && last === "'") || (first === '"' && last === '"')) {
+ return token.slice(1, -1);
+ }
+ }
+ return token;
+}
+
+/**
+ * Validate a geohash string (base32, length 1–12).
+ */
+export function validGeohash(token: unknown): boolean {
+ if (typeof token !== 'string') {
+ return false;
+ }
+ const cleaned = maybeStripQuotes(token).trim().toLowerCase();
+ return (
+ cleaned.length >= MIN_GEOHASH_LENGTH &&
+ cleaned.length <= MAX_GEOHASH_LENGTH &&
+ GEOHASH_RE.test(cleaned)
+ );
+}
+
+/**
+ * Normalize a geohash to a lowercase unquoted string.
+ */
+export function normalizeGeohash(token: unknown): string | null {
+ if (typeof token !== 'string') {
+ return null;
+ }
+ const cleaned = maybeStripQuotes(token).trim().toLowerCase();
+ if (!validGeohash(cleaned)) {
+ return null;
+ }
+ return cleaned;
+}
+
+/**
+ * Decode a geohash to a bounding box [minLat, minLon, maxLat, maxLon].
+ * Adapted from deck.gl GeohashLayer / ngeohash decode_bbox.
+ */
+export function getGeohashBounds(geohash: string): [number, number, number, number] | null {
+ const normalized = normalizeGeohash(geohash);
+ if (!normalized) {
+ return null;
+ }
+
+ let isLon = true;
+ let maxLat = MAX_LAT;
+ let minLat = MIN_LAT;
+ let maxLon = MAX_LON;
+ let minLon = MIN_LON;
+
+ for (let i = 0; i < normalized.length; i++) {
+ const hashValue = BASE32_CODES_DICT[normalized[i]];
+ for (let bits = 4; bits >= 0; bits--) {
+ const bit = (hashValue >> bits) & 1;
+ if (isLon) {
+ const mid = (maxLon + minLon) / 2;
+ if (bit === 1) {
+ minLon = mid;
+ } else {
+ maxLon = mid;
+ }
+ } else {
+ const mid = (maxLat + minLat) / 2;
+ if (bit === 1) {
+ minLat = mid;
+ } else {
+ maxLat = mid;
+ }
+ }
+ isLon = !isLon;
+ }
+ }
+
+ return [minLat, minLon, maxLat, maxLon];
+}
+
+/**
+ * Retrieve geohash cell center as [lng, lat].
+ */
+export function getGeohashCenter(token: string): [number, number] | null {
+ const bounds = getGeohashBounds(token);
+ if (!bounds) {
+ return null;
+ }
+ const [minLat, minLon, maxLat, maxLon] = bounds;
+ return [(minLon + maxLon) / 2, (minLat + maxLat) / 2];
+}
+
+/**
+ * Convert a geohash token to a GeoJSON Feature for hover outline rendering.
+ */
+export function geohashToPolygonGeo(
+ object?: {token?: string},
+ properties?: {isClosed?: boolean; [key: string]: any}
+): Feature<LineString | Polygon> | null {
+ if (!object?.token) {
+ return null;
+ }
+
+ const bounds = getGeohashBounds(object.token);
+ if (!bounds) {
+ return null;
+ }
+
+ const [minLat, minLon, maxLat, maxLon] = bounds;
+ const vertices: [number, number][] = [
+ [maxLon, maxLat],
+ [maxLon, minLat],
+ [minLon, minLat],
+ [minLon, maxLat],
+ [maxLon, maxLat]
+ ];
+
+ if (properties?.isClosed) {
+ return {
+ type: 'Feature',
+ geometry: {
+ type: 'Polygon',
+ coordinates: [vertices]
+ },
+ properties: properties ?? null
+ };
+ }
+
+ return {
+ type: 'Feature',
+ geometry: {
+ type: 'LineString',
+ coordinates: vertices
+ },
+ properties: properties ?? null
+ };
+}
diff --git a/src/layers/src/index.ts b/src/layers/src/index.ts
index ce87ce48a..2a5a53146 100644
--- a/src/layers/src/index.ts
+++ b/src/layers/src/index.ts
@@ -43,9 +43,12 @@ import {default as S2GeometryLayer} from './s2-geometry-layer/s2-geometry-layer'
export {defaultElevation as s2DefaultElevation} from './s2-geometry-layer/s2-geometry-layer';
import {default as A5GeometryLayer} from './a5-layer/a5-layer';
export {defaultElevation as a5DefaultElevation} from './a5-layer/a5-layer';
+import {default as GeohashGeometryLayer} from './geohash-layer/geohash-layer';
+export {defaultElevation as geohashDefaultElevation} from './geohash-layer/geohash-layer';
import {default as FlowLayer} from './flow-layer/flow-layer';
export {getS2Center} from './s2-geometry-layer/s2-utils';
export {getA5Center} from './a5-layer/a5-utils';
+export {getGeohashCenter} from './geohash-layer/geohash-utils';
export {default as AggregationLayer} from './aggregation-layer';
import {default as VectorTileLayer} from './vector-tile/vector-tile-layer';
@@ -108,6 +111,7 @@ export const KeplerGlLayers = {
TripLayer,
S2GeometryLayer,
A5GeometryLayer,
+ GeohashGeometryLayer,
FlowLayer,
VectorTileLayer,
RasterTileLayer,
@@ -132,6 +136,7 @@ export const LayerClasses = {
[LAYER_TYPES.trip]: TripLayer,
[LAYER_TYPES.s2]: S2GeometryLayer,
[LAYER_TYPES.a5]: A5GeometryLayer,
+ [LAYER_TYPES.geohash]: GeohashGeometryLayer,
[LAYER_TYPES.flow]: FlowLayer,
[LAYER_TYPES['vectorTile']]: VectorTileLayer,
[LAYER_TYPES['rasterTile']]: RasterTileLayer,
@@ -145,10 +150,7 @@ export * from './h3-hexagon-layer';
export {default as Table} from './table';
export {getEditorLayer} from './editor-layer/editor-layer';
-export {
- formatCircleRadiusLabel,
- formatLineLengthLabel
-} from './editor-layer/editor-measure-labels';
+export {formatCircleRadiusLabel, formatLineLengthLabel} from './editor-layer/editor-measure-labels';
export {
default as ScenegraphLayer,
diff --git a/src/localization/src/translations/ca.ts b/src/localization/src/translations/ca.ts
index 5f4cb473e..cd252916a 100644
--- a/src/localization/src/translations/ca.ts
+++ b/src/localization/src/translations/ca.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'viatge',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'mosaic vectorial',
@@ -235,7 +236,7 @@ export default {
title: 'Anotacions',
addAnnotation: 'Afegir',
type: 'Tipus',
- lineWidth: "Amplada de línia",
+ lineWidth: 'Amplada de línia',
color: 'Color'
},
effectDescription: {
@@ -314,10 +315,10 @@ export default {
layerSettings: 'Configuració de capa',
closePanel: 'Tanca panel actual',
switchToDualView: 'Canvia a la vista de mapa dual',
- selectSplitMode: "Selecciona el mode de vista del mapa",
- singleView: "Únic",
- dualView: "Doble",
- swipeView: "Comparar",
+ selectSplitMode: 'Selecciona el mode de vista del mapa',
+ singleView: 'Únic',
+ dualView: 'Doble',
+ swipeView: 'Comparar',
showLegend: 'mostra llegenda',
disable3DMap: 'Desactiva mapa 3D',
DrawOnMap: 'Dibuixa al mapa',
@@ -351,8 +352,8 @@ export default {
syncTimelineEnd: 'Fi del període de temps del filtre actual',
showEffectPanel: "Mostra el panell d'efectes",
hideEffectPanel: "Amaga el panell d'efectes",
- showAnnotationPanel: "Mostra les anotacions",
- hideAnnotationPanel: "Amaga les anotacions",
+ showAnnotationPanel: 'Mostra les anotacions',
+ hideAnnotationPanel: 'Amaga les anotacions',
removeAnnotation: "Elimina l'anotació",
duplicateAnnotation: "Duplica l'anotació",
hideAnnotation: "Amaga l'anotació",
diff --git a/src/localization/src/translations/cn.ts b/src/localization/src/translations/cn.ts
index 1a0485ab3..2020179cc 100644
--- a/src/localization/src/translations/cn.ts
+++ b/src/localization/src/translations/cn.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'trip',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'vector tile',
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 1e898e2e4..0a544fe9d 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -132,6 +132,7 @@ export default {
hexagonid: 'H3',
trip: 'trip',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'vector tile',
diff --git a/src/localization/src/translations/es.ts b/src/localization/src/translations/es.ts
index a84efd296..f12ca3979 100644
--- a/src/localization/src/translations/es.ts
+++ b/src/localization/src/translations/es.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'viaje',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'mosaico vectorial',
diff --git a/src/localization/src/translations/fi.ts b/src/localization/src/translations/fi.ts
index b45be9765..e221a1778 100644
--- a/src/localization/src/translations/fi.ts
+++ b/src/localization/src/translations/fi.ts
@@ -116,6 +116,7 @@ export default {
hexagonid: 'H3',
trip: 'matka',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'virtaus',
vectortile: 'vektoritiili',
diff --git a/src/localization/src/translations/ja.ts b/src/localization/src/translations/ja.ts
index 91903b183..ba7face12 100644
--- a/src/localization/src/translations/ja.ts
+++ b/src/localization/src/translations/ja.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'trip',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'vector tile',
diff --git a/src/localization/src/translations/pt.ts b/src/localization/src/translations/pt.ts
index 2992db6b3..47dab1806 100644
--- a/src/localization/src/translations/pt.ts
+++ b/src/localization/src/translations/pt.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'viagem',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'flow',
vectortile: 'mosaico vetorial',
diff --git a/src/localization/src/translations/ru.ts b/src/localization/src/translations/ru.ts
index 953193b63..e23d3c980 100644
--- a/src/localization/src/translations/ru.ts
+++ b/src/localization/src/translations/ru.ts
@@ -117,6 +117,7 @@ export default {
hexagonid: 'H3',
trip: 'пути',
s2: 'S2',
+ geohash: 'GeoHash',
'3d': '3D',
flow: 'поток',
vectortile: 'векторный тайл',
diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.ts
index d5cd5b05e..ed01dd2a8 100644
--- a/src/utils/src/application-config.ts
+++ b/src/utils/src/application-config.ts
@@ -138,6 +138,10 @@ export type KeplerApplicationConfig = {
// A5 DGGS layer is optional. Disabled by default; enable via initApplicationConfig.
enableA5Layer?: boolean;
+ // GeoHash layer config
+ // GeoHash layer is optional. Enabled by default; disable via initApplicationConfig.
+ enableGeohashLayer?: boolean;
+
/** Whether to show example URLs in tileset setup forms (vector tile, raster tile, WMS, 3D tile) */
showInlineTilesetExamples?: boolean;
@@ -303,6 +307,9 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {
// A5 layer config
enableA5Layer: true,
+ // GeoHash layer config
+ enableGeohashLayer: true,
+
showInlineTilesetExamples: true,
// Image export config
diff --git a/src/utils/src/dataset-utils.ts b/src/utils/src/dataset-utils.ts
index 66ad012d4..fc7d2d8d6 100644
--- a/src/utils/src/dataset-utils.ts
+++ b/src/utils/src/dataset-utils.ts
@@ -85,6 +85,7 @@ const EXCLUDED_DEFAULT_FIELDS = [
'h3',
's2',
'a5',
+ 'geohash',
// Geographic coords (but not z/elevation/altitude
// since that might be a metric)
'lat',
diff --git a/test/browser/layer-tests/geohash-layer-specs.js b/test/browser/layer-tests/geohash-layer-specs.js
new file mode 100644
index 000000000..482ebd933
--- /dev/null
+++ b/test/browser/layer-tests/geohash-layer-specs.js
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import test from 'tape';
+
+import {
+ testCreateCases,
+ testFormatLayerDataCases,
+ testRenderLayerCases
+} from 'test/helpers/layer-utils';
+import {geohashDefaultElevation as defaultElevation, KeplerGlLayers} from '@kepler.gl/layers';
+import {getGpuFilterProps, KeplerTable} from '@kepler.gl/table';
+import {processCsvData} from '@kepler.gl/processors';
+import {getGeohashCenter} from '@kepler.gl/layers';
+
+const {GeohashGeometryLayer} = KeplerGlLayers;
+
+const dataId = 'geohash-test-data';
+const geohashCsv = `geohash,value,types
+9q8yyk,0.5,type_a
+9q8yyw,1.5,type_b
+9q8yy4,2.5,type_a
+9q8zn8,3.5,type_c
+9q8yvc,4.5,type_b
+`;
+
+const {rows, fields} = processCsvData(geohashCsv);
+
+function createGeohashDataset(filteredIndex) {
+ const dataset = new KeplerTable({
+ info: {id: dataId, label: 'geohash-data'},
+ color: [255, 0, 0]
+ });
+ dataset.importData({
+ data: {fields, rows}
+ });
+ if (filteredIndex != null) {
+ dataset.filteredIndex = filteredIndex;
+ dataset.filteredIndexForDomain = filteredIndex;
+ }
+ dataset.gpuFilter = getGpuFilterProps([], dataId, dataset.fields);
+ return dataset;
+}
+
+test('#GeohashGeometry -> constructor', t => {
+ const TEST_CASES = [
+ {
+ props: {
+ dataId: 'smoothie',
+ isVisible: true,
+ label: 'test geohash layer'
+ },
+ test: layer => {
+ t.ok(layer.config.dataId === 'smoothie', 'GeohashGeometryLayer dataId should be correct');
+ t.ok(layer.type === 'geohash', 'type should be geohash');
+ t.deepEqual(
+ Object.keys(layer.visConfigSettings),
+ [
+ 'opacity',
+ 'colorRange',
+ 'filled',
+ 'thickness',
+ 'strokeColor',
+ 'strokeColorRange',
+ 'sizeRange',
+ 'stroked',
+ 'enable3d',
+ 'elevationScale',
+ 'enableElevationZoomFactor',
+ 'fixedHeight',
+ 'heightRange',
+ 'wireframe'
+ ],
+ 'should provide the correct visConfigSettings properties'
+ );
+ }
+ }
+ ];
+
+ testCreateCases(t, GeohashGeometryLayer, TEST_CASES);
+ t.end();
+});
+
+test('#GeohashGeometry -> formatLayerData', t => {
+ const filteredIndex = [0, 2, 4];
+ const dataset = createGeohashDataset(filteredIndex);
+
+ const TEST_CASES = [
+ {
+ name: 'geohash layer',
+ layer: {
+ type: 'geohash',
+ id: 'test_layer_1',
+ config: {
+ dataId,
+ label: 'GeoHash',
+ color: [2, 3, 4],
+ columns: {
+ token: 'geohash'
+ },
+ isVisible: true
+ }
+ },
+ datasets: {
+ [dataId]: dataset
+ },
+ assert: result => {
+ const {layerData, layer} = result;
+ const expectedData = [
+ {index: 0, token: '9q8yyk'},
+ {index: 2, token: '9q8yy4'},
+ {index: 4, token: '9q8yvc'}
+ ];
+
+ t.deepEqual(layerData.data, expectedData, 'should format correct geohash layerData');
+ t.deepEqual(layerData.getFillColor, [2, 3, 4], 'getFillColor should be a constant');
+ t.deepEqual(layerData.getElevation, defaultElevation, 'getElevation should be a constant');
+
+ const expectedBounds = expectedData.reduce(
+ (acc, d) => {
+ const center = getGeohashCenter(d.token);
+ return [
+ Math.min(acc[0], center[0]),
+ Math.min(acc[1], center[1]),
+ Math.max(acc[2], center[0]),
+ Math.max(acc[3], center[1])
+ ];
+ },
+ [Infinity, Infinity, -Infinity, -Infinity]
+ );
+
+ // Bounds are computed from all rows in updateLayerMeta, not filtered ones
+ t.ok(layer.meta.bounds, 'should have bounds in meta');
+ t.ok(layer.meta.bounds[0] <= expectedBounds[0], 'west bound');
+ t.ok(layer.meta.bounds[1] <= expectedBounds[1], 'south bound');
+ t.ok(layer.meta.bounds[2] >= expectedBounds[2], 'east bound');
+ t.ok(layer.meta.bounds[3] >= expectedBounds[3], 'north bound');
+ }
+ }
+ ];
+
+ testFormatLayerDataCases(t, GeohashGeometryLayer, TEST_CASES);
+ t.end();
+});
+
+test('#GeohashGeometry -> renderLayer', t => {
+ const filteredIndex = [0, 2, 4];
+ const dataset = createGeohashDataset(filteredIndex);
+
+ const TEST_CASES = [
+ {
+ name: 'geohash layer',
+ layer: {
+ type: 'geohash',
+ id: 'test_layer_1',
+ config: {
+ dataId,
+ label: 'GeoHash',
+ color: [2, 3, 4],
+ columns: {
+ token: 'geohash'
+ },
+ isVisible: true
+ }
+ },
+ datasets: {
+ [dataId]: dataset
+ },
+ assert: (deckLayers, layer) => {
+ t.equal(layer.type, 'geohash', 'should create 1 geohash layer');
+ t.equal(deckLayers.length, 4, 'Should create 4 deck.gl layers');
+
+ const expectedLayerIds = [
+ 'test_layer_1',
+ 'test_layer_1-cell',
+ 'test_layer_1-cell-fill',
+ 'test_layer_1-cell-stroke'
+ ];
+
+ t.deepEqual(
+ deckLayers.map(l => l.id),
+ expectedLayerIds,
+ 'should create composite GeoHash cell layers'
+ );
+
+ const {props: layerProps} = deckLayers[0];
+
+ const expectedProps = {
+ opacity: layer.config.visConfig.opacity,
+ filled: true,
+ wrapLongitude: false,
+ autoHighlight: false,
+ highlightColor: [255, 255, 255, 60],
+ extruded: false
+ };
+
+ Object.keys(expectedProps).forEach(key => {
+ t.deepEqual(layerProps[key], expectedProps[key], `should have correct props.${key}`);
+ });
+ }
+ }
+ ];
+
+ testRenderLayerCases(t, GeohashGeometryLayer, TEST_CASES);
+ t.end();
+});
+
+test('#GeohashGeometry -> findDefaultLayerProps', t => {
+ const dataset = createGeohashDataset();
+ const {props} = GeohashGeometryLayer.findDefaultLayerProps(dataset);
+ t.equal(props.length, 1, 'should find one GeoHash layer prop');
+ t.equal(props[0].columns.token.value, 'geohash', 'should auto-detect geohash column');
+ t.end();
+});
diff --git a/test/browser/layer-tests/index.js b/test/browser/layer-tests/index.js
index cff285c31..3dfe0a1d6 100644
--- a/test/browser/layer-tests/index.js
+++ b/test/browser/layer-tests/index.js
@@ -18,6 +18,7 @@ import './scenegraph-layer-specs';
import './trip-layer-specs';
import './s2-geometry-layer-specs';
import './a5-layer-specs';
+import './geohash-layer-specs';
import './wms-layer-specs';
import './flow-layer-specs';
import './aggregation-layer-geojson-specs';
diff --git a/test/node/utils/geohash-utils-test.js b/test/node/utils/geohash-utils-test.js
new file mode 100644
index 000000000..5bb736efc
--- /dev/null
+++ b/test/node/utils/geohash-utils-test.js
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import test from 'tape';
+import {getGeohashCenter} from '@kepler.gl/layers';
+
+test('Utils -> getGeohashCenter', t => {
+ const token = '9q8yyk';
+ const center = getGeohashCenter(token);
+ t.ok(center, 'should return a center');
+ t.equal(center.length, 2, 'center should be [lng, lat]');
+ t.ok(Math.abs(center[0] + 122.415) < 0.01, 'lng should be near SF');
+ t.ok(Math.abs(center[1] - 37.774) < 0.01, 'lat should be near SF');
+ t.equal(getGeohashCenter('AAAA'), null, 'invalid token returns null');
+ t.equal(getGeohashCenter(''), null, 'empty token returns null');
+ t.equal(getGeohashCenter('ailo'), null, 'tokens with invalid base32 letters return null');
+ t.deepEqual(
+ getGeohashCenter("'9q8yyk'"),
+ getGeohashCenter('9q8yyk'),
+ 'strips surrounding quotes'
+ );
+ t.deepEqual(getGeohashCenter('DR5RG'), getGeohashCenter('dr5rg'), 'geohash is case-insensitive');
+ t.end();
+});
diff --git a/test/node/utils/index.js b/test/node/utils/index.js
index 724d623c3..9f12619b6 100644
--- a/test/node/utils/index.js
+++ b/test/node/utils/index.js
@@ -21,6 +21,7 @@ import './util-test';
import './export-utils-test';
import './s2-utils-test';
import './a5-utils-test';
+import './geohash-utils-test';
import './editor-utils-test';
import './editor-feature-utils-test';
import './kepler-gl-utils-test';