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

querySourceFeatures returns features outside the viewbox #13254

Open
dee-cf opened this issue Aug 15, 2024 · 2 comments
Open

querySourceFeatures returns features outside the viewbox #13254

dee-cf opened this issue Aug 15, 2024 · 2 comments

Comments

@dee-cf
Copy link

dee-cf commented Aug 15, 2024

mapbox-gl-js version: 3.1.2

Question

We use querySourceFeatures to query features in our vector tiles (mvt).
Based on the documentation, we would expect only features within the map viewport to be returned by the method. Relevant part of the docs:

The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport.

What happens though is that the method sometimes returns features that are not within the viewport boundaries.
The only way I could explain that behavior is that it could happen if the we are in a state between 2 zoom levels meaning that the tile doesn't end precisely on the edge of the viewport so that a part of the tile is within the viewport and part is out. And in that case the method returns features within the tile but outside of the viewport.

Questions are:

  1. Can someone confirm if that is the case? If so, should we do additional filtering of features based on the viewport bounding box?
  2. If so, could that be explained a bit more clear in the docs?

PS.
Another source of confusion is that the description says the method behaves the same as queryRenderedFeatures with the difference that it looks for features that might be invisible. But I have never seen queryRenderedFeatures returning features outside of the viewport.

Links to related documentation

https://docs.mapbox.com/mapbox-gl-js/api/map/#map#querysourcefeatures

@dee-cf dee-cf changed the title querySourceFeatures return features outside the viewbox querySourceFeatures returns features outside the viewbox Aug 15, 2024
@mourner
Copy link
Member

mourner commented Aug 16, 2024

this function does not check tiles outside the currently visible viewport

Perhaps we could improve the clarity of documentation about this. querySourceFeatures indeed returns all features inside tiles loaded for the current viewport, and these tiles are often visible only partially — they are rarely aligned to viewport.

To see how this works, set map.showTileBoundaries = true in your code. If you want the features filtered by viewport strictly, you should do the additional filtering on the app side.

@dee-cf
Copy link
Author

dee-cf commented Aug 16, 2024

Thanks for the clarification!

Yeah, putting a sentence about it in docs would help.

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants