Improve operating with mapnik field types
This commit is contained in:
parent
bdfcd7aa6d
commit
d7e6cdf082
@ -94,6 +94,13 @@ tree.functions = {
|
||||
|
||||
return hsla(hsl);
|
||||
},
|
||||
replace: function (entity, a, b) {
|
||||
if (entity.is === 'field') {
|
||||
return entity.toString + '.replace(' + a.toString() + ', ' + b.toString() + ')';
|
||||
} else {
|
||||
return entity.replace(a, b);
|
||||
}
|
||||
},
|
||||
//
|
||||
// Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
|
||||
// http://sass-lang.com
|
||||
|
@ -35,8 +35,12 @@ tree.Dimension.prototype = {
|
||||
// conversions such that `100cm + 10mm` would yield
|
||||
// `101cm`.
|
||||
operate: function(op, other) {
|
||||
return new tree.Dimension(tree.operate(op, this.value, other.value),
|
||||
this.unit || other.unit);
|
||||
if (other.is === 'field') {
|
||||
return new tree.Quoted('', this.value + op + other.toString());
|
||||
} else {
|
||||
return new tree.Dimension(tree.operate(op, this.value, other.value),
|
||||
this.unit || other.unit);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -11,6 +11,9 @@ tree.Field.prototype = {
|
||||
},
|
||||
'eval': function() {
|
||||
return this;
|
||||
},
|
||||
operate: function(op, other) {
|
||||
return new tree.Quoted('', this.toString() + op + other.toString());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -16,8 +16,13 @@ tree.Quoted.prototype = {
|
||||
},
|
||||
|
||||
operate: function(op, other) {
|
||||
return new tree.Quoted(this.quote,
|
||||
tree.operate(op, this.toString(), other.toString()));
|
||||
if (other.is !== 'string') {
|
||||
return new tree.Quoted(this.quote,
|
||||
this.toString() + op + other.toString());
|
||||
} else {
|
||||
return new tree.Quoted(this.quote,
|
||||
tree.operate(op, this.toString(), other.toString()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
23
test/rendering/building_height.mml
Normal file
23
test/rendering/building_height.mml
Normal file
@ -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": [
|
||||
"building_height.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"
|
||||
}
|
||||
}]
|
||||
}
|
4
test/rendering/building_height.mss
Normal file
4
test/rendering/building_height.mss
Normal file
@ -0,0 +1,4 @@
|
||||
@n: 4;
|
||||
#world {
|
||||
building-height: 2 * 3 * [HEIGHT] + 2 + [NOTHEIGHT] + (@n * 2);
|
||||
}
|
Loading…
Reference in New Issue
Block a user