Short answer
• It’s fine to call map.queryRenderedFeatures() or map.querySourceFeatures(); it will not “block” the map or slow the normal tile-loading pipeline.
• But MapLibre GL is a renderer, not a database. Those query methods only look at the vector tiles (or GeoJSON) that are already in the client’s memory. If the feature you need lives in a tile that hasn’t been requested (because it’s outside the current viewport or zoom level), the query will return nothing.
• So: great for “what’s on the screen right now?” interactions; poor for global searches, analytics, or anything that must be complete.
─────────────────────────────────────────────
Why it works that way
─────────────────────────────────────────────
-
Lazy loading
• Vector-tile sources are fetched on demand: only the tiles covering the current viewport and zoom are downloaded.
• When you pan/zoom, tiles outside view are evicted from memory.
-
What the query functions see
• map.queryRenderedFeatures([geometry?], {layers, filter})
– Operates on features that are both loaded AND currently painted (respects style filters, zoom-dependent visibility, symbol collision, etc.).
• map.querySourceFeatures('sourceId', {sourceLayer, filter})
– Looks at the raw features of the loaded tiles for that source, independent of styling.
• Neither function triggers extra network requests. They just loop over what’s already in RAM.
─────────────────────────────────────────────
Typical use-cases that ARE a good fit
─────────────────────────────────────────────
✔ Hover/click tooltips
✔ Highlighting a feature the user just clicked
✔ Showing the count/sum of features visible on the map
✔ Brushing/selection workflows restricted to the current viewport
─────────────────────────────────────────────
Use-cases that AREN’T a good fit
─────────────────────────────────────────────
✘ “Find the parcel whose ID = 123456 anywhere in the world”
✘ Global aggregations (“How many schools are there in the US?”)
✘ Treating MapLibre as an offline spatial index for thousands of users—memory will explode.
─────────────────────────────────────────────
What to do instead for heavy queries
─────────────────────────────────────────────
• Server-side spatial database (PostGIS, Elasticsearch geo, etc.) with an API.
• Client-side spatial index libraries (RBush, Flatbush) if your data set is small enough to load entirely as GeoJSON.
• Pre-built search services (Algolia Places, Nominatim, Pelias, etc.).
• If you’re already using vector tiles, expose a small REST endpoint that lets you fetch a single feature by ID directly from your tile cache or DB.
─────────────────────────────────────────────
Performance tips if you still want to query in MapLibre
─────────────────────────────────────────────
- Wait for the
idle event before querying to be sure the visible tiles are loaded:
map.on('idle', () => {
const feats = map.querySourceFeatures('mySource', { sourceLayer: 'buildings' });
console.log(feats.length);
});
- Limit calls—don’t run a big query on every
mousemove; throttle/debounce.
- Narrow your
filter and layers arrays to avoid scanning unnecessary tiles.
- For static GeoJSON loaded as a
geojson source, disable clustering if you need individual points.
- Turn on WebWorker transfer (
promoteId) if you need fast look-ups by a unique ID.
─────────────────────────────────────────────
Bottom line
─────────────────────────────────────────────
You can safely query MapLibre for what is already on the map, but you should not rely on it for complete, database-like queries across the whole data set. Do that work elsewhere and use MapLibre purely for rendering and lightweight, view-based interactions.