diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.test.ts b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.test.ts index 50725fefe6f..a7b7be3ab9a 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.test.ts +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.test.ts @@ -69,6 +69,37 @@ describe('Polygon transformProps', () => { emitCrossFilters: false, }; + const mockedChartPropsWithGeoHash: Partial = { + ...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); + }); }); diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.ts b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.ts index 3c55142d39e..bb070d92e36 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.ts +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Polygon/transformProps.ts @@ -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 : [];