Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]: queryRenderedFeaturesInRect returns empty FeatureCollection #3786

Open
peterbodo opened this issue Feb 21, 2025 · 2 comments
Open

[Bug]: queryRenderedFeaturesInRect returns empty FeatureCollection #3786

peterbodo opened this issue Feb 21, 2025 · 2 comments
Labels
bug 🪲 Something isn't working

Comments

@peterbodo
Copy link

peterbodo commented Feb 21, 2025

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
Copy link
Author

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
Copy link
Author

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant