Is it possible to query features that are not being displayed?
Asked Answered
C

1

16

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

Cernuous answered 16/1, 2017 at 23:32 Comment(1)
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: stackoverflow.com/help/how-to-askArleenarlen
L
9

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.

Lists answered 17/1, 2017 at 3:23 Comment(4)
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.Spiro
See this example...Very early in development ovrdc.org/apps/mapbox-parcel-viewer.htmlSpiro
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 =/Cernuous
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.Spiro

© 2022 - 2024 — McMap. All rights reserved.