Skip to content

Commit

Permalink
allow expressions in filters, fixes mapbox#377
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulon42 committed Jul 2, 2017
1 parent f37bd50 commit 31023fb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ There is a new command line / API switch (`-q / --quiet` / `quiet`) to suppress
(`-o / --output` / `outputFormat`) to choose the output format. Possible values are `mapnik` (default)
for Mapnik XML and `json` for the JSON variant (part of [#413](https://github.com/mapbox/carto/issues/413)).
For Mapnik XML all character data as tag content is now prefixed with CDATA.
* Expressions are allowed in filters e.g. `[height] % 50 = 0` or `[height] + 10 = 0`, fields have to be properly written within brackets
([#377](https://github.com/mapbox/carto/issues/377))

### Breaking changes

Expand Down
5 changes: 5 additions & 0 deletions docs/styling_concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,8 @@ String comparisons::

/* a regular expression over name */
#world[name =~ "A.*"]

More complex expressions::

#world[[population] % 50 = 0]
#world[[population] * 2 < 1000]
1 change: 1 addition & 0 deletions lib/carto/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ carto.Parser = function Parser(env) {
/*eslint-disable no-cond-assign */
if (key = $(/^[a-zA-Z0-9\-_]+/) ||
$(this.entities.quoted) ||
$(this.expression) ||
$(this.entities.variable) ||
$(this.entities.keyword) ||
$(this.entities.field)) {
Expand Down
3 changes: 3 additions & 0 deletions test/rendering-mss/issue_377.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[height] % 50 = 0] {
marker-fill: red;
}
6 changes: 6 additions & 0 deletions test/rendering-mss/issue_377.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Style filter-mode="first" name="style">
<Rule>
<Filter><![CDATA[([height]%50 = 0)]]></Filter>
<MarkersSymbolizer fill="#ff0000" />
</Rule>
</Style>

0 comments on commit 31023fb

Please sign in to comment.