Dusan
Dusan

Reputation: 3478

Querying features in mapbox which are not visible

I have a mapbox map with lots of geometries (100 000+ features).

I'd like to draw a rectangle and select features, which belong to the bounds drawn out.
Mapbox provides such feature via queryRenderedFeatures()

Something like this example:
https://docs.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/

The selection is made by this code snippet:

const features = map.queryRenderedFeatures(bbox, {
     layers: ['myFirstLayer', 'mySecondLayer', 'myThirdLayer']
});

This one selects only features, that are currently rendered. In my scenario all my layers have a minzoom layout property set, to display only at certain zoom.

But after drawing the rectangle, I'd like to select all features which are on my map - either visible or invisible.

Does mabpox provide this functionality, or do I have to do that on my own?

Upvotes: 0

Views: 1045

Answers (1)

Steve Bennett
Steve Bennett

Reputation: 126355

Since you have the dataset loaded as a GeoJSON, I would simply query it directly.

Use flatbush to set up a spatial index of all your features, then call .search() to perform the bounding box query.

Upvotes: 1

Related Questions