Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querySourceFeature returns empty array

Tags:

mapbox-gl-js

I am using mapbox to try and query all features of the mapbox tileset and return them as geojson. From what I understand, to query features that are no visible on the screen, you must use querysourcefeatures. My tileset only shows up at zoom 14 so I am having trouble querying all the features in the dataset at once and then applying a filter. Is this possible? It stills like querySourceFeatures returns an empty array.

function addLayers() {
    map.addSource('plutonew-c03oxi', {
        'type': 'vector',
        'url': 'mapbox://samtpr.4ehwzn0r'
    });

    map.addLayer({
        "id": "parcels_fill",
        "type": "fill",
        "source": "plutonew-c03oxi",
        "source-layer": "plutonew-c03oxi",
       'layout': {
            'visibility': 'visible'
        },
        paint: {
            'fill-color': 'blue',            
            'fill-outline-color': 'gray',
            "fill-opacity": ["case",
            ["boolean", ["feature-state", "hover"], false],
            0.5,
            0
            ]
        }
    });

var features = map.querySourceFeatures('plutonew-c03oxi',  {filter: ["==", ['get','ZIPCODE'], zipcode_val]});
like image 369
blg2 Avatar asked Oct 24 '25 23:10

blg2


1 Answers

From what I understand, to query features that are no visible on the screen, you must use querysourcefeatures

You may have misunderstood. querySourceFeatures allows you to query features that are present within the vector tiles currently loaded and displayable within the current viewport and zoom level. Unlike queryRenderedFeatures they don't have to actually be rendered through a visible layer, however.

In this case it sounds like you're hoping to gain access to features that are not available at the current zoom level, which is not possible.

like image 159
Steve Bennett Avatar answered Oct 27 '25 00:10

Steve Bennett