Created
May 2, 2016 21:41
-
-
Save tmcw/810cf787bb47b33e5606c1b49f64ce98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var filter = [ | |
"all", | |
[ "in", "$type", "Polygon", "LineString", "Point"], | |
[ "all", | |
["in", "type", "town", "city"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
] | |
] | |
var filter2 = [ | |
"all", | |
[ "in", "$type", "Polygon", "Point", "LineString"], | |
[ "all", | |
["in", "type", "city", "town"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
] | |
] | |
var filter3 = [ | |
"all", | |
[ "all", | |
["in", "type", "city", "town"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
var filter4 = [ | |
"all", | |
[ "all", | |
["==", "class", "street_limited"], | |
["in", "type", "city", "town"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
var filter5 = [ | |
"all", | |
[ "all", | |
["==", "class", "street_limited"], | |
["in", "type", "city", "town"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
function sortLevel(list) { | |
if (!Array.isArray(list)) { | |
return list; | |
} else if (list[0] == 'any' || list[0] == 'all' || list[0] == 'none') { | |
return list.slice(0, 1).concat(list.slice(1).map(sortLevel).sort()); | |
} else { | |
return list.slice(0, 2).concat(list.slice(2).map(sortLevel).sort()); | |
} | |
} | |
console.log(sortLevel(filter)); | |
console.log(sortLevel(filter2)); | |
console.log(sortLevel(filter3)); | |
console.log(sortLevel(filter4)); |
The filter operator list is just a list, doesn't divide into set vs property https://github.com/mapbox/mapbox-gl-style-spec/blob/mb-pages/reference/v8.json#L790
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a reliable source of metadata for which filter expressions are comparing against a property vs a set? It would be nice to not hard code 'any', 'all' and 'none'. (I don't think this metadata exists currently, we should create it)
Properties values inside set operations are required to be operations themselves (arrays). While non-set operations are individual values (non-arrays). The
.map(sortLevel)
on line 57 is unnessesary.It would be nice to have this method inside the style spec so it can grow and evolve with the spec.