mapbox / mapbox/mapbox-gl-js

setFilter method for GeoJSONSource

Open
#10,722 9 comments 8 reactions 1 assignee View on GitHub

@mourner is already working on this.

Since May 27, 2021.

api :memo: feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

You can cluster a `GeoJSONSource`, but it's difficult to filter out source data because the layer `filter` expression applies to the clustered features. The `GeoJSONSource` has a `filter` property, but it can only be specified on source initialization.

To paint an illustrative example, let's say we have 50K features with a date property and as a user interacts with our app, we allow them to filter the clustered map to just show features in a certain date range. If the 50K features weren't clustered, we could just apply a `filter` to each layer we wanted to filter. But with the 50K features clustered, we either need to filter the source data ourselves and use `setData` or we need to remove the source and add it back with a `filter` applied to it. The former requires source data regeneration on our end, and the latter results in a flash as the map removes all features from the old source and adds all features from the new source.

Thanks for your consideration, and also open to alternative ideas! ❤️

## Design Alternatives

Would it be possible to add a `setFilter` method to a `GeoJSONSource` to allow for this workflow?

## Design

Currently, it looks like the `setData` workflow in a `geojson_source` will kick off a `loadData`, which checks to see if there is a filter, and if so, does a `data.features.filter`. Since this `setData` workflow looks at the `filter`, it seems like `setFilter` could potentially be a subset of this workflow.

### Mock-Up

### Concepts

### Implementation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.