Skip to content

Commit

Permalink
Fix ["has", "$id"] filter and "!has" filters in general
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 8, 2017
1 parent cf031a6 commit 14ec9f5
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/style-spec/feature_filter/index.js
Expand Up @@ -34,7 +34,7 @@ function compile(filter) {
op === 'in' ? compileInOp(filter[1], filter.slice(2)) :
op === '!in' ? compileNegation(compileInOp(filter[1], filter.slice(2))) :
op === 'has' ? compileHasOp(filter[1]) :
op === '!has' ? compileNegation(compileHasOp([filter[1]])) :
op === '!has' ? compileNegation(compileHasOp(filter[1])) :
'true';
return `(${str})`;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ function compileInOp(property, values) {
}

function compileHasOp(property) {
return `${JSON.stringify(property)} in p`;
return property === '$id' ? '"id" in f' : `${JSON.stringify(property)} in p`;
}

function compileNegation(expression) {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,70 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"id": "a",
"geometry": {
"type": "Point",
"coordinates": [
-10,
0
]
}
},
{
"type": "Feature",
"properties": {
"$id": "b"
},
"geometry": {
"type": "Point",
"coordinates": [
10,
0
]
}
}
]
}
}
},
"layers": [
{
"id": "a",
"type": "circle",
"source": "geojson",
"filter": [
"has",
"$id"
],
"paint": {
"circle-color": "red"
}
},
{
"id": "b",
"type": "circle",
"source": "geojson",
"filter": [
"!has",
"$id"
],
"paint": {
"circle-color": "blue"
}
}
]
}

0 comments on commit 14ec9f5

Please sign in to comment.