Skip to content

[Bug] Can't filter geojson column mode points by polygon #3278

@leverglowh

Description

@leverglowh

Describe the bug
When filtering by drawing a polygon or rectangle, it has no effect on point layers with column mode geojson.
This is happening because

  1. inside the function geojsonPosAccessor in the file point-layer.ts, d is normally an array, so accessing the position value with d[geojson.fieldIdx] works and returns a string "POINT (yy xx)".
    But when I click filter, and the function is called from filter-utils.ts line 387, d is an object with this structure: { index: 0, dataContainer: {...} }, leading to pos being undefined.
  2. Even if we arrive at line 387 in filter-utils.ts with the geojson value, say like this:
    export const geojsonPosAccessor =
      ({geojson}: {geojson: LayerColumn}) =>
      d => {
        if (Array.isArray(d)) {
          return d[geojson.fieldIdx];
        } else if (typeof d === 'object' && d.dataContainer) {
          return d.dataContainer.valueAt(d.index, geojson.fieldIdx);
        }
      };
    it still expects an array of coordinates, throwing Uncaught TypeError: pos.every is not a function on the same line.
    A solution could be just extract the coordinates from the geojson string using regex, something like
    // Vibe coding solution warning
    if (isPointGeometry) {
      // Parse "POINT (lng lat)"
      const match = geometry.match(
          /POINT\s*\(\s*([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s*\)/
      );
      if (!match) return;
      lng = parseFloat(match[1]);
      lat = parseFloat(match[2]);
    }
    But it's ugly, so here I am.
    Maybe we can add an ad hoc helper function inside the point layer class to get the coordinates?
    Thoughts?

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple csv like this:
    point
    POINT (7.63 45.04)
    POINT (10.07 45.82)
    
  2. Import into kepler using add data modal
  3. Change the layer type from geojson to point, and make sure it uses column "point" in geojson mode
  4. Draw a rectangle around a point, right click it and select the layer
  5. See error in console: Uncaught TypeError: can't access property "every", pos is undefined on line 387 of filter-utils.ts

Expected behavior
It should correctly filter points without throwing errors.

Screenshots
If applicable, add screenshots to help explain your problem.

Image

Additional context
Reproduced in all demo websites and locally.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions