-
Notifications
You must be signed in to change notification settings - Fork 8
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
Replace no-op style filter expressions #62
Conversation
test/styleToFilter.test.js
Outdated
[ | ||
"case", | ||
[">=", ["distance-from-center"], 1], | ||
true, | ||
[">=", ["pitch"], 45] | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change the expression a little to be:
[
"case",
[">=", ["distance-from-center"], 1],
false,
[">=", ["pitch"], 45]
],
The case expression will return false, excluding the feature. Therefore, we probably need to aggressively set the entire case expression to ['literal', true]
.
lib/styleToFilters.js
Outdated
@@ -33,15 +33,15 @@ function styleToFilters(style) { | |||
if (styleMin < layers[layerName].minzoom) layers[layerName].minzoom = styleMin; | |||
if (styleMax > layers[layerName].maxzoom) layers[layerName].maxzoom = styleMax; | |||
// Modify filter | |||
if (layers[layerName].filters === true || !style.layers[i].filter) { | |||
if (layers[layerName].filters === true || !style.layers[i].filter || isNoOpFilter(style.layers[i].filter)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be too aggressive, so for such case:
"filter": [
"all",
[
"case",
["<=", ["pitch"], 45],
true,
["<=", ["distance-from-center"], 1]
],
["match", ["get", "type"], ["Toll booth"], true, false]
],
we would want to replace it with:
"filter": [
"all",
[
"literal",
true
],
["match", ["get", "type"], ["Toll booth"], true, false]
],
instead of just ['literal', true]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR adds a "pre-filter" that removes no-op style filter expressions as
['pitch']
,['distance-from-center']
by replacing them with an expression that always evaluates to true.