[Bug]: querySourceFeatures not working with VectorSource in rnmapbox
Mapbox Implementation
Mapbox GL
Mapbox Version
default
React Native Version
0.75.3
Platform
iOS
@rnmapbox/maps version
10.1.35
Standalone component to reproduce
import React, { useRef } from 'react';
import MapboxGL from '@rnmapbox/maps';
import { View } from 'react-native';
const MapComponent = () => {
const mapRef = useRef<MapboxGL.MapView>(null);
const handlePress = async () => {
try {
const features = await mapRef.current?.querySourceFeatures(
'dwr_wd',
[],
['dwr_wd_layer']
);
console.log('Features:', features);
} catch (error) {
console.error('Error fetching features:', error);
}
};
return (
<View style={{ flex: 1 }}>
<MapboxGL.MapView
ref={mapRef}
style={{ flex: 1 }}
onPress={handlePress}
>
<MapboxGL.Camera
zoomLevel={10}
centerCoordinate={[-121.8853, 37.3382]}
/>
<MapboxGL.VectorSource
id="dwr_wd"
url="https://tiles.domain.com/dwr_wd"
>
<MapboxGL.FillLayer
id="dwr_wd_layer"
sourceLayerID="dwr_wd"
style={{
fillColor: '#088',
fillOpacity: 0.5,
}}
/>
</MapboxGL.VectorSource>
</MapboxGL.MapView>
</View>
);
};
export default MapComponent;
Observed behavior and steps to reproduce
- Create a VectorSource and FillLayer as shown below.
- Ensure that the data is loading and rendering correctly on the map.
- Try calling querySourceFeatures to get the features within the layer.
- The function returns features empty array .
Expected behavior
No response
Notes / preliminary analysis
No response
Additional links and references
No response
Seeing the same thing following this example. Any updates on this?
For me something like this worked
await mapRef.current?.querySourceFeatures('source', [], ['layer']);
The trick was in using empty array (also undefined will work) for filter parameter
@Pakile-vhg I can't run your example as https://tiles.domain.com/dwr_wd is not an existing vector source.
Our example does work fine. https://rnmapbox.github.io/docs/examples/FillRasterLayer/QuerySourceFeatures
Since your example is not complete, missing working url for the vector source, I'm closing this as can't repo