fix(chart): implement geohash decoding (#37027)

This commit is contained in:
Reynold Morel
2026-01-23 18:15:29 -04:00
committed by GitHub
parent e4f649e49c
commit b99fc582e4
2 changed files with 61 additions and 0 deletions

View File

@@ -69,6 +69,37 @@ describe('Polygon transformProps', () => {
emitCrossFilters: false,
};
const mockedChartPropsWithGeoHash: Partial<ChartProps> = {
...mockChartProps,
rawFormData: {
line_column: 'geohash',
line_type: 'geohash',
viewport: {},
},
queriesData: [
{
data: [
{
geohash: '9q8yt',
'sum(population)': 9800,
},
{
geohash: '9q8yk',
'sum(population)': 13100,
},
{
geohash: '9q8yv',
'sum(population)': 15600,
},
{
geohash: '9q8yq',
'sum(population)': 7500,
},
],
},
],
};
test('should use constant elevation value when point_radius_fixed type is "fix"', () => {
const fixProps = {
...mockChartProps,
@@ -257,4 +288,23 @@ describe('Polygon transformProps', () => {
expect(features).toHaveLength(1);
expect(features[0]?.elevation).toBeUndefined();
});
test('should handle geohash decoding successfully', () => {
const props = {
...mockedChartPropsWithGeoHash,
rawFormData: {
...mockedChartPropsWithGeoHash.rawFormData,
point_radius_fixed: {
type: 'fix',
value: '1000',
},
},
};
const result = transformProps(props as ChartProps);
const features = result.payload.data.features as PolygonFeature[];
expect(features.flatMap(p => p?.polygon || [])).toHaveLength(20); // 4 geohashes x 5 corners each
expect(features[0]?.elevation).toBe(1000);
});
});

View File

@@ -26,6 +26,7 @@ import {
addPropertiesToFeature,
} from '../transformUtils';
import { DeckPolygonFormData } from './buildQuery';
import { decode_bbox } from 'ngeohash';
function parseElevationValue(value: string): number | undefined {
const parsed = parseFloat(value);
@@ -122,6 +123,16 @@ function processPolygonData(
break;
}
case 'geohash':
polygonCoords = [];
const decoded = decode_bbox(String(rawPolygonData));
if (decoded) {
polygonCoords.push([decoded[1], decoded[0]]); // SW (minLon, minLat)
polygonCoords.push([decoded[1], decoded[2]]); // NW (minLon, maxLat)
polygonCoords.push([decoded[3], decoded[2]]); // NE (maxLon, maxLat)
polygonCoords.push([decoded[3], decoded[0]]); // SE (maxLon, minLat)
polygonCoords.push([decoded[1], decoded[0]]); // SW (close polygon)
}
break;
case 'zipcode':
default: {
polygonCoords = Array.isArray(rawPolygonData) ? rawPolygonData : [];