From 197e27121e5e1e0360e2a7f1443483b667921c2f Mon Sep 17 00:00:00 2001 From: Daniel Woznicki Date: Wed, 27 Jul 2022 15:20:46 -0700 Subject: [PATCH 1/2] Fixed a bug where the metadata for an object with id 'mapbox-content' was not being properly extracted --- lib/generate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generate.js b/lib/generate.js index a4e0119..e36c8f9 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -132,7 +132,7 @@ function generateLayoutInternal(options, callback) { if ( options.extractMetadata && options.format && - (img.svg.includes('mapbox-stretch') || img.svg.includes('mapbox-text-placeholder')) + (img.svg.includes('mapbox-stretch') || img.svg.includes('mapbox-text-placeholder') || img.svg.includes('mapbox-content')) ) { const metaOps = { svg: img.svg, pixelRatio: options.pixelRatio }; extractMetadata(metaOps, (err, metadataProps) => { From fb9880de45ecebad7578d2fe689cca1d8b7d7c8e Mon Sep 17 00:00:00 2001 From: Daniel Woznicki Date: Wed, 27 Jul 2022 15:22:01 -0700 Subject: [PATCH 2/2] Added a test to ensure that metadata for objects with 'mapbox-content' are properly extracted --- .../au-national-route-5-only-content.svg | 9 +++++++ test/generate.test.js | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/fixture/svg-metadata/au-national-route-5-only-content.svg diff --git a/test/fixture/svg-metadata/au-national-route-5-only-content.svg b/test/fixture/svg-metadata/au-national-route-5-only-content.svg new file mode 100644 index 0000000..c8062ea --- /dev/null +++ b/test/fixture/svg-metadata/au-national-route-5-only-content.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/generate.test.js b/test/generate.test.js index 67082b0..6461cdb 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -373,3 +373,29 @@ test('generateLayout with both placeholder and stretch zone', function (t) { t.end(); }); }); + +test('generateLayout with only content', function (t) { + var fixtures = [ + { + id: 'au-national-route-5-only-content', + svg: fs.readFileSync('./test/fixture/svg-metadata/au-national-route-5-only-content.svg') + } + ]; + spritezero.generateLayout({ imgs: fixtures, pixelRatio: 1, format: true }, function (err, formatted) { + t.ifError(err); + t.deepEqual( + formatted, + { + 'au-national-route-5-only-content': { + width: 38, + height: 20, + x: 0, + y: 0, + pixelRatio: 1, + content: [3, 7, 23, 18], + } + } + ); + t.end(); + }); +});