querySourceFeatures returns empty for "invisible" features
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**: 0.42.0
### Steps to Trigger Behavior
1. add a few point features as a geojson source
2. add a layer from the source, with `visibility: 'none'`:
```
this.map.addLayer({
id: 'foobar',
type: 'circle',
source: 'foobar-points',
layout: {
visibility: 'none',
},
paint: {
'circle-color': '#222',
'circle-radius': 6,
},
});
```
3. use querySourceFeatures on the source and examine the returned array
```
const sourceFeatures = map.querySourceFeatures('foobar-points');
```
### Expected Behavior
As per the docs: returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible).
### Actual Behavior
`querySourceFeatures` returns an empty array.
However if you leave the layer visible but hide everything with a filter, querySourceFeatures does return the expected output (all of the features in the viewport)
```
this.map.addLayer({
id: 'foobar',
type: 'circle',
source: 'foobar-points',
filter: ['has', 'nothingHasThis'],
paint: {
'circle-color': '#222',
'circle-radius': 6,
},
});
```
The other thing I didn't expect from the API documentation is the fact that you need to add a layer at all. I thought you could simply add a source and then query it without having to put it in a layer.
This is so I can get the source features within a radius so I can try to predict what is inside a supercluster.
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 issue with the reported mapbox-gl-js 0.42.0 setup: a GeoJSON source, a layer with visibility set to none, and map.querySourceFeatures('foobar-points'). Compare that result with the visible-layer and filter examples; done means the API returns the expected source features regardless of layer visibility, matching its documented behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100