Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support contains, begins with, and ends with filter option for strings #4820

Closed
afischer opened this issue Jun 10, 2017 · 6 comments
Closed

Comments

@afischer
Copy link

Motivation

Often, layers will be filtered on a specific attribute. This attribute could be a string, for example, a restaurant name. The current filter API allows for extensive filtering of numerical values, but the ability to filter strings is limited to searching string equality and inequality.

Design

Maintaining the current filter API design, a few new selectors could be added. I would recommend following the CSS selector design, as it is widely known by web designers.

Mock-Up

To begin, the API could support the ^=, $=, and *= operators. This would give the ability to do the following:

// Filter showing only features with the property `cuisine` beginning with 'Asian'
map.setFilter('restaurants', ['^=', 'cuisine', 'Asian']);
// matches 'Asian', 'Asian-Fusion'

// Filter showing only features with the property `cuisine` ending with 'ian'
map.setFilter('restaurants', ['$=', 'cuisine', 'ian']);
// matches 'Italian, 'Asian', 'American'

// Filter showing only features with the property `cuisine` containing the substring 'pan'
map.setFilter('restaurants', ['*=', 'cuisine', 'pan']);
// matches 'Japanese', 'Spanish'

Concepts

The design is familiar to web designers already, and is in alignment with the current filter API design. Adding these features would not be breaking, and would be highly discoverable. The same terminology could be used to discuss these filters, and they would easily fit in with the filters already in place.

Implementation

Implementation would follow the precedent set for filters in the JS/C++ mapbox repos.

Further discussion would be needed regarding how/if these operators would support other types, such as numerics. Would numbers be treated as strings?

@anandthakker
Copy link
Contributor

Thanks for this proposal @afischer -- this type of functionality will be covered by the work that's currently underway (#4777) to add a general expression syntax.

Duplicate of #4077

@gabimoncha
Copy link

@anandthakker I read the Project Arbex but could not see this particular example. Can you please reference the syntax where this example is applied?

@gabimoncha
Copy link

@afischer did you manage to sort it out?

@anandthakker
Copy link
Contributor

See #6484, which tracks expression operators that aren't yet implemented.

@gabimoncha
Copy link

@anandthakker I don't understand. Is this feature implemented or not yet? I thought it is as Project Arbex is merged into master and you referenced it for this issue.

@anandthakker
Copy link
Contributor

It is not implemented yet. #6484 tracks expression features that are not yet implemented, but will be in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants