I have been playing around with mapbox-gl. I am trying to get the map to flyTo() a specific polygon in one of my layers.

After looking extensively through the API I can only find methods to return features after clicking the map or selecting with a bounding box -- no method to parse the features of a layer and its attributes.

I want the latlon (or bounding box or whatever) of a polygon in the dataset, where "NBHD_NAME" equals the variable I am searching for. I am using a polygon PBF hosted on Mapbox. I cannot seem to access the features of the vector layer through map.getLayer() or map.getSource().

Am I missing something obvious, or is this functionality not really present in mapbox-gl?

1 Answer 1


To get features within a vector tile dataset you can use the method querySourceFeatures:

map.on('style.load', function() {
    var features = map.querySourceFeatures('SOURCE_NAME', {
        sourceLayer: 'SOURCE_LAYER_NAME',
        filter: ["==", "NBHD_NAME", "YOUR_VARIABLE"]

This will return an geoJson.

See the documentation here: https://www.mapbox.com/mapbox-gl-js/api/#Map#querySourceFeatures

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.