MapCSS/0.2/Proposal lists

From OpenStreetMap Wiki
< MapCSS‎ | 0.2
Jump to navigation Jump to search

Proposal

Some keys in OpenStreetMap allow (resp. it is common) the use of lists as values, e.g. cuisine=* and ref=*.

Also, lists can be useful for eval statements, e.g. to collect the Names or refs of route relations on the ways.

List selector

The value is treated as a semicolon-separated string, e.g. "regional;asian". If the value does not contain a semicolon, it is treated as list with only one value, e.g. "regional".

node[cuisine~=regional]    /* Matches against all nodes where the cuisine tags contains "regional" as list element */

Support:

Feature JOSM pgm
List selector *[cuisine~=regional] + +

List eval functions

Data type list: A list of values, may be empty (equals none).

The following functions may be used with lists:

General functions

Function Description Example JOSM pgm
list(a, b, ...) => list create list of values list("foo", "bar") + +
get(lst:list, i:int) => value return the ith element of the list lst (counting starts at 0); returns none if i is out of range. get(list("foo", "bar"), 1) => "bar" + +
set(lst:list, i:int, v:value) => list set the ith element of the list lst to value v set(list("foo", "bar"), 1, "baz") => list("foo", "baz") + +
append(lst:list, v:value) => list append the value v to list lst append(list("foo", "bar"), "baz") => list("foo", "bar", "baz") - +
split(sep:string, str:string) => list splits string str at occurrences of the separator string sep, returns a list split(";", "foo;bar") => list("foo", "bar") + +
join(sep:string, lst:list) => string joins a list with sep as separator join(";", list("foo", "bar")) => "foo;bar" - +
count(lst:list) => int count of elements in the list lst count(list("foo", "bar")) => 2 + +
contains(lst:list, v:value) => boolean returns true if list lst contains value v contains(list("foo", "bar"), "bar") => true - +
search(lst:list, v:value) => int returns first index of value v in list lst or none if not found. search(list("foo", "bar"), "bar") => 1 - +
unique(lst:list) => list removes duplicate values from list lst unique(list("foo", "bar", "foo")) => list("foo", "bar") - +
sort(lst:list) => list order list alphabetically ascending sort(list("foo", "bar", "12", "1", "2")) => list("1", "12", "2", "bar", "foo") - +
natsort(lst:list) => list order list 'natural' sort order sort(list("foo", "bar", "12", "1", "2")) => list("1", "2", "12", "bar", "foo") - +
min(lst:list) => number returns lowest of the input values min(list(12, 1, 2)) => 1 - +
max(lst:list) => number returns highest of the input values max(list(12, 1, 2)) => 12 - +
sum(lst:list) => number returns the sum of all input values sum(list(12, 1, 2)) => 15 - -
reverse(lst:list) => list returns the list in reverse order reverse(list("foo", "bar", "baz")) => list("baz", "bar", "foo") - -
range(start:number, end:number[, step:number]) => list returns a list of numbers, starting with start and ending with end increased by step (default: 1) range(-5, -10, -2.5) => list(-5, -7.5, -10) - -


Examples

Label all restaurants with asian cuisine

*[amenity=restaurant][cuisine~=asian] {
  text: name;
}

Show route refs on ways

Collect all route refs on their respective ways and print them joined after sorting naturally.

relation[type=route][ref] way {
  refs: append(prop(refs), parent_tag(ref));
  set .has_refs;
}

way.has_refs {
  color: #ff0000;
  width: 2;
  text: join(", ", natsort(prop(refs)));
  text-position: line;
}

Mapcss-lists.png

References

List selector

List eval functions

Comments