Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryRenderedFeatures within feature collection not working #3540

Closed
bertday opened this issue Jan 5, 2024 · 4 comments · Fixed by maplibre/maplibre-style-spec#477
Closed
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed

Comments

@bertday
Copy link
Contributor

bertday commented Jan 5, 2024

maplibre-gl-js version: 3.6.2

browser: Brave 1.61.109 (Chromium 120.0.6099.144)

Steps to Trigger Behavior

  1. Add a point layer
  2. Call queryRenderedFeatures on the point layer, providing a filter with a within expression and a GeoJSON feature collection of polygons that contain the points
  3. Only points within the first feature are returned; should be all

Link to Demonstration

I've created a minimal example of this which

  • queries rendered points within a feature collection of polygons
  • sets the feature state of points returned by the query so they turn red on the map

https://codepen.io/rbrtmrtn/pen/abMvYvK

Expected Behavior

Both points should turn red because both of the are within the feature collection.

Actual Behavior

Only one is red. The issue seems to be that queryRenderedFeatures is only returning a single point — the one that falls within the first polygon encountered in the feature collection. Looking at the docs for within expressions, however, it looks like a feature collection should be a valid argument.

image

@HarelM
Copy link
Collaborator

HarelM commented Jan 5, 2024

Yes, this looks like a bug.
As a workaround, I found out that using a Feature of type MultiPolygon instead of a list of polygons works as expected (don't use FeatureCollection).

I also tried to add a test to the expressions test with this use case and it seems to fail, so it looks like an actual bug that should be easy to test, reproduce, and hopefully solve.
https://github.com/maplibre/maplibre-gl-js/tree/main/test/integration/expression

Let me know if you would like to try and tackle this.

@HarelM HarelM added bug Something isn't working PR is more than welcomed Extra attention is needed labels Jan 5, 2024
@bertday
Copy link
Contributor Author

bertday commented Jan 5, 2024

Thanks so much for the prompt dive into this @HarelM ! Really appreciate that.

I would like to help with a fix. I'm a bit low on cycles right now so I may have to use the MultiPolygon workaround, but will keep this on my radar and report back when I can dive in further.

Thanks again!

@HarelM
Copy link
Collaborator

HarelM commented Jan 6, 2024

Found the issue, it does only take the first one apparently.
I'll move the tests and code to the relevant repo. I'll link it here shortly.

@bertday
Copy link
Contributor Author

bertday commented Jan 8, 2024

Thank you @HarelM, glad to hear you tracked the problem down 🤩 (And thank you @sbachinin for putting in a fix!) I'll keep an eye on maplibre/maplibre-style-spec#477 and start using that code once it's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants