Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
allow expressions in filters, fixes #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>

3 comments on commit 31023fb

@StyXman
Copy link

@StyXman StyXman commented on 31023fb Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this with osm-carto? I tried with v3.3.1 and I got this:

$ time ./bin/carto -a 2.1.1 ~/src/projects/osm/osm-carto/project.mml 
Error: water-features.mss:60:21 Invalid value for marker-width, the type expression is expected. 10 (of type float) was given.
Error: water-features.mss:59:6 Invalid value for marker-width, the type expression is expected. 8 (of type float) was given.
[...]

and gazillion more. Maybe I should use another API version?

@nebulon42
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I guess I should. Could you open a issue about that? It makes it easier to track and prevents that I'm forgetting. Thanks.

@StyXman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, #486.

Please sign in to comment.