diff --git a/CHANGELOG.md b/CHANGELOG.md index 72a8164..3854c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.7.0 + +* Support an `opacity` property on any style that is a style-level property + ### 0.6.0 * Bump `mapnik-reference` dependency to 1.0.0 to allow for using `buffer-size` in the diff --git a/lib/carto/tree/style.js b/lib/carto/tree/style.js index 4c99e5e..8211dda 100644 --- a/lib/carto/tree/style.js +++ b/lib/carto/tree/style.js @@ -9,7 +9,7 @@ tree.Style = function Style(name, attachment, definitions) { tree.Style.prototype.toXML = function(env) { var existing = {}; - // TODO :add filters and comp op + var image_filters = _.flatten(this.definitions.map(function(definition) { return definition.rules.filter(function(rule) { return (rule.name === 'image-filters'); @@ -22,24 +22,33 @@ tree.Style.prototype.toXML = function(env) { }); })); + var opacity = _.flatten(this.definitions.map(function(definition) { + return definition.rules.filter(function(rule) { + return (rule.name === 'opacity'); + }); + })); + var rules = this.definitions.map(function(definition) { return definition.toXML(env, existing); }); - var image_filters_xml = '', - comp_op_xml = ''; + var attrs_xml = ''; if (image_filters.length) { - image_filters_xml = 'image-filters="' + image_filters.map(function(f) { + attrs_xml += ' image-filters="' + image_filters.map(function(f) { return f.toXML(env, true); - }).join(',') + '"'; + }).join(',') + '" '; } if (comp_op.length) { - comp_op_xml = 'comp-op="' + comp_op[0].value.eval(env).toString() + '"'; + attrs_xml += ' comp-op="' + comp_op[0].value.eval(env).toString() + '" '; } - return ''; + if (opacity.length) { + attrs_xml += ' opacity="' + opacity[0].value.eval(env).toString() + '" '; + } + + return ''; }; })(require('../tree')); diff --git a/package.json b/package.json index 067f52b..f07837e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "carto", - "version": "0.6.0", + "version": "0.7.0", "description": "Mapnik Stylesheet Compiler", "url": "https://github.com/mapbox/carto", "repositories": [{ @@ -36,7 +36,7 @@ }, "dependencies": { "underscore": "~1.3.3", - "mapnik-reference": "~2.0.0", + "mapnik-reference": "~2.1.0", "xml2js": "~0.1.13" }, "devDependencies": { diff --git a/test/rendering/style_level_opacity.mml b/test/rendering/style_level_opacity.mml new file mode 100644 index 0000000..160ebc8 --- /dev/null +++ b/test/rendering/style_level_opacity.mml @@ -0,0 +1,14 @@ +{ + "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": [ + "style_level_opacity.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" + } + }] +} diff --git a/test/rendering/style_level_opacity.mss b/test/rendering/style_level_opacity.mss new file mode 100644 index 0000000..ea06e8f --- /dev/null +++ b/test/rendering/style_level_opacity.mss @@ -0,0 +1,6 @@ +#world { + opacity:0.2; + text-name: "[NAME]"; + text-size: 11; + text-face-name: "Georgia Regular", "Arial Italic"; +} diff --git a/test/rendering/style_level_opacity.result b/test/rendering/style_level_opacity.result new file mode 100644 index 0000000..f6132f9 --- /dev/null +++ b/test/rendering/style_level_opacity.result @@ -0,0 +1,23 @@ + + + + + + + + + + + world + + + + + + +