From b113bfea99607772d04c6c6e6258e0e256f6d8c5 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 16 Apr 2013 10:24:48 -0400 Subject: [PATCH] Prevent image filter duplication. Fixes #270 --- lib/carto/tree/style.js | 6 +++-- test/rendering/imagefilter-duplication.mml | 15 +++++++++++ test/rendering/imagefilter-duplication.mss | 5 ++++ test/rendering/imagefilter-duplication.result | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/rendering/imagefilter-duplication.mml create mode 100644 test/rendering/imagefilter-duplication.mss create mode 100644 test/rendering/imagefilter-duplication.result diff --git a/lib/carto/tree/style.js b/lib/carto/tree/style.js index bd3a883..059c93e 100644 --- a/lib/carto/tree/style.js +++ b/lib/carto/tree/style.js @@ -28,9 +28,11 @@ tree.StyleXML = function(name, attachment, definitions, env) { var attrs_xml = ''; if (image_filters.length) { - attrs_xml += ' image-filters="' + image_filters.map(function(f) { + attrs_xml += ' image-filters="' + _.chain(image_filters) + // prevent identical filters from being duplicated in the style + .uniq(function(i) { return i.id; }).map(function(f) { return f.ev(env).toXML(env, true, ',', 'image-filter'); - }).join(',') + '"'; + }).value().join(',') + '"'; } if (comp_op.length) { diff --git a/test/rendering/imagefilter-duplication.mml b/test/rendering/imagefilter-duplication.mml new file mode 100644 index 0000000..6798418 --- /dev/null +++ b/test/rendering/imagefilter-duplication.mml @@ -0,0 +1,15 @@ +{ + "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": [ + "imagefilter-duplication.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/imagefilter-duplication.mss b/test/rendering/imagefilter-duplication.mss new file mode 100644 index 0000000..0c65c5f --- /dev/null +++ b/test/rendering/imagefilter-duplication.mss @@ -0,0 +1,5 @@ +#world { + image-filters:agg-stack-blur(3,3); + [zoom=2] { line-width: 3; } + [zoom=3] { line-width: 5; } +} diff --git a/test/rendering/imagefilter-duplication.result b/test/rendering/imagefilter-duplication.result new file mode 100644 index 0000000..76b5970 --- /dev/null +++ b/test/rendering/imagefilter-duplication.result @@ -0,0 +1,27 @@ + + + + + + + + world + + + + + + +