maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: queryRenderedFeaturesInRect returns empty FeatureCollection

Open peterbodo opened this issue 10 months ago • 3 comments

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

peterbodo avatar Feb 21 '25 07:02 peterbodo

Update:

even with not filtering to any layer ids:

 const features = await mapViewRef.current?.queryRenderedFeaturesInRect(
            []
        );

anf the map clearly full of features:

Image

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"}}

peterbodo avatar Feb 24 '25 09:02 peterbodo

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.

peterbodo avatar Feb 24 '25 16:02 peterbodo

Thank you! Saved me lots of time.

kevindice avatar Mar 18 '25 15:03 kevindice

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

mfazekas avatar Oct 18 '25 07:10 mfazekas