[Bug]: queryRenderedFeaturesInRect returns empty FeatureCollection
Mapbox Implementation
Mapbox
Mapbox Version
default
React Native Version
0.76.7
Platform
Android
@rnmapbox/maps version
10.1.35
Standalone component to reproduce
import { StyleSheet, View } from "react-native";
import React, { useRef } from "react";
import Mapbox from "@rnmapbox/maps";
Mapbox.setAccessToken(
"pk.ey..."
);
export default function HomeScreen() {
const mapViewRef = useRef<Mapbox.MapView>(null);
const handleOnPress = async () => {
const features = await mapViewRef.current?.queryRenderedFeaturesInRect(
[],
null,
[
"poi-scalerank1",
"poi-parks-scalerank1",
"poi-scalerank2",
"poi-parks-scalerank2",
"poi-scalerank3",
"poi-parks-scalerank3",
"poi-scalerank4-l1",
"poi-scalerank4-l15",
"poi-parks_scalerank4",
]
);
console.log(features);
};
return (
<View style={styles.page}>
<View style={styles.container}>
<Mapbox.MapView
ref={mapViewRef}
style={styles.map}
styleURL="mapbox://styles/mapbox/streets-v9"
testID={"show-map"}
onPress={handleOnPress}
>
<Mapbox.Camera
zoomLevel={17}
centerCoordinate={[19.06, 47.5]}
/>
</Mapbox.MapView>
</View>
</View>
);
}
const styles = StyleSheet.create({
page: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
container: {
height: "100%",
width: "100%",
backgroundColor: "tomato",
},
map: {
flex: 1,
},
});
Observed behavior and steps to reproduce
While poi symbol layers are clearly visible in the map view, tapping the map returns empty featurecollection:
{"features": [], "type": "FeatureCollection"}
Expected behavior
The features array should be populated by the pois visible in the actual screen.
Notes / preliminary analysis
No response
Additional links and references
No response
Update:
even with not filtering to any layer ids:
const features = await mapViewRef.current?.queryRenderedFeaturesInRect(
[]
);
anf the map clearly full of features:
The query gives back only onw feature (which is a building, btw):
{"type":"Feature","id":"4","geometry":{"type":"Polygon","coordinates":[[[19.0593079,47.5048712],[19.0594715,47.5047625],[19.0593092,47.5046502],[19.0591469,47.504758],[19.0593079,47.5048712]]]},"properties":{"extrude":"true","type":"apartments","min_height":0,"height":15,"underground":"false"}}
Update: for bbox [] clearly does not work. [0,0,1000,1000] for example gives back good results. Also just realised that bbox is in pixels not coordinates, which is not explicitely documented.
Thank you! Saved me lots of time.
Update: for bbox [] clearly does not work. [0,0,1000,1000] for example gives back good results. Also just realised that bbox is in pixels not coordinates, which is not explicitely documented.
Agree, I think it's documented in a confusing way https://rnmapbox.github.io/docs/components/MapView#queryrenderedfeaturesinrectbbox-filter-layerids