Skip to content

Commit 92ae3d9

Browse files
Ruschiostepankuzmin
authored andcommitted
Set Filter method for GeoJSON Source
Adding setFilter method for GeoJSON source, to allow filtering data without passing new ones with setData function
1 parent 823534d commit 92ae3d9

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

src/source/geojson_source.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,48 @@ class GeoJSONSource extends Evented<SourceEvents> implements ISource {
253253
return this;
254254
}
255255

256+
/**
257+
* Sets filter for the GeoJSON data source and re-renders the map.
258+
*
259+
* @param {Array | string} filter An array for the filter expression.
260+
* @returns {GeoJSONSource} Returns itself to allow for method chaining.
261+
* @example
262+
* map.addSource('source_id', {
263+
* type: 'geojson',
264+
* data: {
265+
* "type": "FeatureCollection",
266+
* "features": [{
267+
* "type": "Feature",
268+
* "properties": {"name": "Null Island"},
269+
* "geometry": {
270+
* "type": "Point",
271+
* "coordinates": [ 0, 0 ]
272+
* }
273+
* },
274+
* {
275+
* "type": "Feature",
276+
* "properties": {"name": "Another Island"},
277+
* "geometry": {
278+
* "type": "Point",
279+
* "coordinates": [ 1, 1 ]
280+
* }
281+
* }]
282+
* }
283+
* });
284+
* const geojsonSource = map.getSource('source_id');
285+
* // Update the filter after the GeoJSON source was created
286+
* geojsonSource.setFilter([
287+
* "==",
288+
* ["get", "name"],
289+
* "Another Island"
290+
* ]);
291+
*/
292+
setFilter(filter: Array | string): this {
293+
this.workerOptions = extend$1({ filter: filter }, this.workerOptions);
294+
this._updateWorkerData();
295+
return this;
296+
}
297+
256298
/**
257299
* For clustered sources, fetches the zoom at which the given cluster expands.
258300
*

0 commit comments

Comments
 (0)