querySourceFeatures(
sourceId:string,parameters?:QuerySourceFeatureOptions):GeoJSONFeature[]
Defined in: ui/map.ts:2658
Returns an array of MapGeoJSONFeature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
sourceId |
string |
The ID of the vector tile or GeoJSON source to query. |
parameters? |
QuerySourceFeatureOptions |
The options object. |
Returns
GeoJSONFeature[]
An array of MapGeoJSONFeature objects.
In contrast to Map.queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport.
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
Example
Find all features in one source layer in a vector source
let features = map.querySourceFeatures('your-source-id', {
sourceLayer: 'your-source-layer'
});