15

I would like to know if there is a way to query features that are not being displayed on a map.

Both queryRenderedFeatures and querySourceFeatures only work when the features are being displayed on the map.

I tried also to hide the features using setLayoutProperty with visibility and using setFilter. Both don't return features when queried.

example

thiagoxvo
  • 347
  • 2
  • 10
  • Welcome to Stackoverflow! To get the most out of the site it is important to ask good questions. A guide to asking questions is at: http://stackoverflow.com/help/how-to-ask – Stephen Rauch Jan 17 '17 at 00:00

1 Answers1

8

MapboxGL only requests tiles for the current viewport and zoom level. If it's not available via map#queryRenderedFeatures or map#querySourceFeatures then your MapboxGL map doesn't have the data you are looking for.

Danny Delott
  • 6,756
  • 3
  • 33
  • 57
  • 3
    I got around this by creating a JSON file from the original data with the values I need for search, a unique key and a latlng. Then I just use a simple JSON search, zoom to the latlng, then query mapfeatures with the unique key. You may have to wait for all features to be rendered after zoom...via settimeout unfortunately. – malcolm Jan 20 '17 at 18:03
  • See this example...Very early in development https://www.ovrdc.org/apps/mapbox-parcel-viewer.html – malcolm Jan 20 '17 at 18:06
  • I was afraid that I will have to use something like this @malcolm. In the end, I can't have all my data only on Mapbox and I have to rely on other data sources to make the map navigate to the right place =/ – thiagoxvo Jan 20 '17 at 18:23
  • 1
    All that said, if mapbox is using mbtiles on the backend, this is just an SQLite DB...just not sure if it be queried, and if so that would have to happen server-side. This is definitely a key missing link in the mbtiles/vector tiles/mapbox mapping platform. – malcolm Jan 21 '17 at 04:25