Add advanced field test, fixes for combining fields with colors that otherwise go back to mapnik

field
Tom MacWright 12 years ago
parent 651a650f2e
commit d57006dd97

@ -25,7 +25,7 @@ tree.Dimension.prototype = {
return new tree.Color([this.value, this.value, this.value]);
},
toString: function() {
return this.value;
return this.value.toString();
},
// In an operation between two Dimensions,

@ -1,3 +1,6 @@
// A literal is a literal string for Mapnik - the
// result of the combination of a `tree.Field` with any
// other type.
(function(tree) {
tree.Literal = function Field(content) {

@ -46,9 +46,23 @@ tree.Operation.prototype.eval = function(env) {
};
}
// Fields, literals, dimensions, and quoted strings can be combined.
if (a instanceof tree.Field || b instanceof tree.Field ||
a instanceof tree.Literal || b instanceof tree.Literal) {
return new tree.Literal(a.eval(env).toString(true) + this.op + b.eval(env).toString(true));
if (a.is === 'color' || b.is === 'color') {
env.error({
message: "Can't subtract, divide, or multiply colors in expressions.",
index: this.index,
type: 'runtime',
filename: this.filename
});
return {
is: 'undefined',
value: 'undefined'
};
} else {
return new tree.Literal(a.eval(env).toString(true) + this.op + b.eval(env).toString(true));
}
}
return a.operate(this.op, b);

@ -0,0 +1,23 @@
{
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Stylesheet": [
"field_advanced.mss"
],
"Layer": [{
"name": "world",
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Datasource": {
"file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip",
"type": "shape"
}
},
{
"class": "new",
"name": "countries",
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Datasource": {
"file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip",
"type": "shape"
}
}]
}

@ -0,0 +1,6 @@
#world {
text-name: "hello " + [NAME] + " hello" + 2;
text-size: 11;
text-face-name: "Georgia Regular", "Arial Italic";
}

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
<FontSet name="fontset-0">
<Font face-name="Georgia Regular"/>
<Font face-name="Arial Italic"/>
</FontSet>
<Style name="world" filter-mode="first" >
<Rule>
<TextSymbolizer size="11" fontset-name="fontset-0" ><![CDATA['hello '+[NAME]+' hello'+2]]></TextSymbolizer>
</Rule>
</Style>
<Layer name="world"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>world</StyleName>
<Datasource>
<Parameter name="file"><![CDATA[[absolute path]]]></Parameter>
<Parameter name="type"><![CDATA[shape]]></Parameter>
</Datasource>
</Layer>
</Map>
Loading…
Cancel
Save