Skip to content

Commit ac96fc9

Browse files
committed
fix: polygon filter for point layers using GeoJSON column mode
When filtering points by drawing a polygon, layers using GeoJSON column mode failed because: 1. geojsonPosAccessor received data as {index, dataContainer} object from filter-utils but tried to access it as an array via d[geojson.fieldIdx], returning undefined 2. Even with correct data access, the accessor returned raw WKT strings (e.g. 'POINT (7.63 45.04)') instead of [lng, lat] coordinates Fix by: - Currying geojsonPosAccessor with dataContainer (matching the pattern used by pointPosAccessor and geoarrowPosAccessor) - Using dataContainer.valueAt() to properly access field values - Parsing WKT POINT strings into [lng, lat, alt] coordinate arrays - Supporting GeoJSON objects with coordinates property - Returning [NaN, NaN, 0] for invalid data so the existing Number.isFinite check in filter-utils gracefully excludes them Fixes #3278 Signed-off-by: pierreeurope <pierre.europe@pm.me>
1 parent 8c5030c commit ac96fc9

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

src/layers/src/point-layer/point-layer.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,34 @@ export const pointPosAccessor =
121121
altitude && altitude.fieldIdx > -1 ? dc.valueAt(d.index, altitude.fieldIdx) : 0
122122
];
123123

124+
/**
125+
* Parse a WKT POINT string (e.g. "POINT (7.63 45.04)") into [lng, lat] coordinates.
126+
* Returns null if the string cannot be parsed.
127+
*/
128+
export function parseWktPoint(wkt: string): [number, number] | null {
129+
if (typeof wkt !== 'string') return null;
130+
const match = wkt.match(/POINT\s*\(\s*([-\d.eE+]+)\s+([-\d.eE+]+)\s*\)/i);
131+
if (!match) return null;
132+
return [parseFloat(match[1]), parseFloat(match[2])];
133+
}
134+
124135
export const geojsonPosAccessor =
125136
({geojson}: {geojson: LayerColumn}) =>
126-
d =>
127-
d[geojson.fieldIdx];
137+
(dataContainer: DataContainerInterface) =>
138+
(d: {index: number}): number[] => {
139+
const value = dataContainer.valueAt(d.index, geojson.fieldIdx);
140+
if (value == null) return [NaN, NaN, 0];
141+
// Handle WKT point strings (e.g. "POINT (7.63 45.04)")
142+
if (typeof value === 'string') {
143+
const parsed = parseWktPoint(value);
144+
return parsed ? [parsed[0], parsed[1], 0] : [NaN, NaN, 0];
145+
}
146+
// Handle GeoJSON objects with coordinates
147+
if (value.coordinates) {
148+
return [value.coordinates[0], value.coordinates[1], 0];
149+
}
150+
return [NaN, NaN, 0];
151+
};
128152

129153
export const geoarrowPosAccessor =
130154
({geoarrow}: PointLayerColumnsConfig) =>
@@ -243,7 +267,7 @@ export default class PointLayer extends Layer {
243267
case COLUMN_MODE_GEOARROW:
244268
return geoarrowPosAccessor(this.config.columns)(dataContainer);
245269
case COLUMN_MODE_GEOJSON:
246-
return geojsonPosAccessor(this.config.columns);
270+
return geojsonPosAccessor(this.config.columns)(dataContainer);
247271
default:
248272
// COLUMN_MODE_POINTS
249273
return pointPosAccessor(this.config.columns)(dataContainer);

0 commit comments

Comments
 (0)