maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: querySourceFeatures not working with VectorSource in rnmapbox

Open Pakile-vhg opened this issue 9 months ago • 2 comments

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

  1. Create a VectorSource and FillLayer as shown below.
  2. Ensure that the data is loading and rendering correctly on the map.
  3. Try calling querySourceFeatures to get the features within the layer.
  4. The function returns features empty array .

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

No response

Pakile-vhg avatar Mar 10 '25 10:03 Pakile-vhg

Seeing the same thing following this example. Any updates on this?

alexjhill-medly avatar May 16 '25 11:05 alexjhill-medly

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

xoxkoo avatar Jun 04 '25 22:06 xoxkoo

@Pakile-vhg I can't run your example as https://tiles.domain.com/dwr_wd is not an existing vector source.

mfazekas avatar Oct 16 '25 12:10 mfazekas

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

mfazekas avatar Oct 16 '25 12:10 mfazekas