Skip to content

Commit

Permalink
Fix filter operator checking for nested condition
Browse files Browse the repository at this point in the history
  • Loading branch information
zmiao committed Apr 22, 2020
1 parent 12fe07b commit 92bf6c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/style-spec/feature_filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ function createFilter(filter: any): FeatureFilter {
return {filter: () => true, needGeometry: false};
}

filter = convertFilter(filter);
if (!isExpressionFilter(filter)) {
filter = convertFilter(filter);
}

const compiled = createExpression(filter, filterSpec);
if (compiled.result === 'error') {
Expand All @@ -96,17 +98,14 @@ function compare(a, b) {

function geometryNeeded(filter) {
if (!Array.isArray(filter)) return false;
let needed = false;
for (let index = 0; index < filter.length; index++) {
const val = filter[index];
const op = Array.isArray(val) ? val[0] : val;
needed = needed || (op === 'within');
if (filter[0] === 'within') return true;
for (let index = 1; index < filter.length; index++) {
if (geometryNeeded(filter[index])) return true;
}
return needed;
return false;
}

function convertFilter(filter: ?Array<any>): mixed {
if (isExpressionFilter(filter)) return filter;
if (!filter) return true;
const op = filter[0];
if (filter.length <= 1) return (op !== 'any');
Expand All @@ -124,6 +123,7 @@ function convertFilter(filter: ?Array<any>): mixed {
op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
op === 'has' ? convertHasOp(filter[1]) :
op === '!has' ? convertNegation(convertHasOp(filter[1])) :
op === 'within' ? filter :
true;
return converted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"type": "Feature",
"properties": {
"name": "ABC"
"number": [5]
},
"geometry": {
"type": "Point",
Expand All @@ -30,7 +30,7 @@
{
"type": "Feature",
"properties": {
"name": "ABC"
"number": [5]
},
"geometry": {
"type": "Point",
Expand Down Expand Up @@ -80,7 +80,7 @@
"id": "circle",
"type": "circle",
"source": "points",
"filter": ["all", ["in", "ABC", ["get", "name"]], ["within", {
"filter": ["all", ["in", 5, ["get", "number"]], ["==", ["within", {
"type": "Polygon",
"coordinates": [
[
Expand All @@ -91,7 +91,7 @@
[0, 0]
]
]
}]
}], true]
],
"paint": {
"circle-radius": 5,
Expand Down

0 comments on commit 92bf6c3

Please sign in to comment.