Missing features in results from circle layers when using queryRenderedFeatures without specifying a layers option
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**mapbox-gl-js version**: 2.15.0
**browser**:
Brave Version 1.52.130 (Chromium 114.0.5735.198)
Safari Version 15.3 (17612.4.9.1.8)
### Issue Description
In this scenario, the user selects a point on the map which falls in an underlying polygon. The goal is to determine what other features are located within this selected polygon using the `map.queryRenderedFeatures` method.
The underlying polygon geometry is extracted and a bounding box is derived and projected to pixel coordinates. This bounding box is used as the `geometry` param for the `queryRenderedFeatures` method.
When I attempt to query all features (by not specifying a `layers` option), I am getting missing results for any features that are included in `circle` layers. However when including the affected layer ID name within the `layers` array option, I am able to get the results as expected.
As seen below, the exact same geometry value is used, so I am unsure why this behaviour is occuring.
### Steps to Trigger Behavior
1. Click a point on the map which selects and highlights a polygon.
2. Query map features without specifying any layer IDs in the `layers` array option.
```
const allFeatures = map.queryRenderedFeatures(bboxScreen);
console.log('results 1', allFeatures.map(r => r.layer.id).filter(l => l === 'nsw-da-data-circle'));
```
3. Query map features by specifying the circle layer in the `layers` array option.
```
const daFeatures = map.queryRenderedFeatures(bboxScreen, {layers: ['nsw-da-data-circle']});
console.log('results 2', daFeatures.map(r => r.layer.id));
```
4. View the results in the console log
```
> results 1 []
> results 2 ['nsw-da-data-circle', 'nsw-da-data-circle']
```
As you can see features for the `nsw-da-data-circle` layer do not appear in the first set of results. I do not seem to have this issue for any layers which are not `"type": "circle"`.
I have had circumstances where this issue does not occur and both results match. E.g.
In other cases where there are multiple features in the bounding box, I have situations where only some of the features are returned when using `map.queryRenderedFeatures` without the `layers` option. E.g.
Additionally, the issue seems to occur inconsistently when the page is refreshed and/or at different zoom levels.
Is there a limit to the number of results that can be returned by `map.queryRenderedFeatures` when no `layers` option is provided (attempting to get all features)? I have a large number of layers on my map (that are in some cases transparent based on the users configuration). Or is there any other explanation for why this may be occuring?
### Expected Behavior
All features found within the supplied geometry for any `circle` layers should be returned when calling `map.queryRenderedFeatures`.
### Actual Behavior
Features are inconsistently returned when the layer ID is not explicitly included in the `layers` array option for any `circle` layers.
### Current workaround
Currently I am able to overcome this issue by separately querying the affected circle layers and combining the results. However this is not ideal as it means I have to filter out any duplicates that occur when features are included in both sets of results.
I'm not entirely sure if this is a bug, but based on my testing and examples above it appears to be.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported map.queryRenderedFeatures calls with the same geometry, once without layers and once with the circle layer ID, across the stated browsers and zoom levels. Trace the queryRenderedFeatures entry point and circle-layer handling; done means all circle-layer features within the supplied geometry are returned consistently without the workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100