Fetch all features, not just within the visible extent, using MapBox Studio hosted data

mapbox-gl-jsmapbox-studioquery

I uploaded a GeoJSON Dataset to MapBox Studio, then converted it into a Tileset. I'm displaying this in a MapBox GL-JS map:

map.addSource('regionsSource', {
  type: 'vector',
  url: 'mapbox://username.layerId'
});
map.addLayer({
  'id': 'regions',
  'source': 'regionsSource',
  'source-layer': layerName,
  ...
})

I need a way to fetch features from the regions layer via an attribute query, whether or not they're in the current view extent.

Unfortunately it seems that querySourceFeatures "does not check tiles outside the currently visible viewport." queryRenderedFeatures has a similar limitation.

How can I query features from a Tileset stored in MapBox studio, regardless of the current view extent?

Best Answer

There is a custom solution to build.

  1. Select the extent desired extent/bbox.
  2. Use slippy tiles algorithm to query pbf tiles from Mapbox studio link to that extent/bbox. https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
  3. Convert pbf to geojson. github.com/mapbox/vt2geojson
Related Question