Skip to content

map.setFilter() bug with 'within' expression within 'all' expression #9605

@dpdiliberto

Description

@dpdiliberto

I created an example by going off this example to test setting a filter based on 1) features within a certain polygon using the within expression, as well as 2) features that met certain data conditions using the in expression.

My example works with the within expression or in expression individually, but not when they are both within an all expression. Here is my filter expression that does not work:

map.setFilter('population', ['all', ['in', 'Hispanic', ['get', 'ethnicity']], ['within', feature]]);

I was able to get this to work with the following workaround:

map.setPaintProperty('population', 'circle-opacity' , ['to-number', ['all', ['within', feature], ['==', ['get', 'ethnicity'], 'Hispanic']]]);

Is this a bug or expected behavior?

mapbox-gl-js version: 1.9.0

browser: Chrome Version 80.0.3987.163

Steps to Trigger Behavior

  1. map.setFilter('population', ['all', ['in', 'Hispanic', ['get', 'ethnicity']], ['within', feature]]); does not work
    2.map.setFilter('population', ['within', feature]); and map.setFilter('population', ['in', 'Hispanic', ['get', 'ethnicity']]); work individually
  2. I was able to work around this with @arindam1993 's help with map.setPaintProperty('population', 'circle-opacity' , ['to-number', ['all', ['within', feature], ['==', ['get', 'ethnicity'], 'Hispanic']]]);

Link to Demonstration

https://jsbin.com/yoqunojelu/edit?html,output

Expected Behavior

Being able to filter for both conditions: 1) being within a polygon and 2) certain data conditions

Actual Behavior

It is not possible to filter for both when using the within expression.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions