mapbox/carto — Issue #126: discuss: how to gracefully support more expressions?
Author: springmeyer
Created: 2011-12-12 19:18:48+00:00
State: open

Many Mapnik symbolizer properties could, should, and will be expressions, like `text-name`.

I see two futures in mapnik core: either we could incrementally switch more symbolizers to use expressions, or we could try to make one massive sweep/refactor.

Since the former is more likely, we need to discuss how to gracefully avoid breakages in carto stylesheets along the way.

For example, building heights should be expressions and now we have a imminent merge to make this so: https://github.com/mapnik/mapnik/pull/991.

Exposing this to work in TileMill/Carto then is as easy as this change to reference.json:

```diff
diff --git a/reference.json b/reference.json
index 449b705..0953c05 100644
--- a/reference.json
+++ b/reference.json
@@ -277,7 +277,7 @@
},
"height": {
"css": "marker-height",
- "type": "float"
+ "type": "string"
},
"fill": {
"css": "marker-fill",
```

But this immediately breaks all existing stylesheets:

```
Error: style.mss:16:4 Invalid value for building-height, a valid float is expected. 200 was given.
at Object.error (/Users/dane/projects/tilemill/node_modules/carto/lib/carto/parser.js:300:55)
at Rule.toXML (/Users/dane/projects/tilemill/node_modules/carto/lib/carto/tree/rule.js:50:20)
at Definition.symbolizersToXML (/Users/dane/projects/tilemill/node_modules/carto/lib/carto/tree/definition.js:115:50)
```

Proposal:

Add an new "expression" type to reference.json which will trigger carto to completely avoid syntax validation so that both of these would be valid:

```css
building-height:200;
building-height:"[field1/field2]";
```