From a1cf8d9bd44d8e787afd3231fad3c2ac15f60e2c Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Fri, 2 Jun 2017 11:04:49 -0700 Subject: Add addImage test --- platform/node/test/fixtures/cat.png | Bin 0 -> 9921 bytes platform/node/test/fixtures/image-test.png | Bin 0 -> 36377 bytes platform/node/test/js/map.test.js | 49 +++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 platform/node/test/fixtures/cat.png create mode 100644 platform/node/test/fixtures/image-test.png diff --git a/platform/node/test/fixtures/cat.png b/platform/node/test/fixtures/cat.png new file mode 100644 index 0000000000..f46bc71167 Binary files /dev/null and b/platform/node/test/fixtures/cat.png differ diff --git a/platform/node/test/fixtures/image-test.png b/platform/node/test/fixtures/image-test.png new file mode 100644 index 0000000000..83fbd49f35 Binary files /dev/null and b/platform/node/test/fixtures/image-test.png differ diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js index 04d02d0558..6056fc2288 100644 --- a/platform/node/test/js/map.test.js +++ b/platform/node/test/js/map.test.js @@ -5,6 +5,7 @@ var mbgl = require('../../index'); var fs = require('fs'); var path = require('path'); var style = require('../fixtures/style.json'); +var PNG = require('pngjs').PNG; test('Map', function(t) { // This test is skipped because of the req.respond shim in index.js @@ -564,7 +565,6 @@ test('Map', function(t) { map.render({width: 400, height: 400, zoom: 5, center: [18.05489, 59.32744]}, function(err, actual) { t.error(err); - var PNG = require('pngjs').PNG; var pixelmatch = require('pixelmatch'); var expected = PNG.sync.read( fs.readFileSync(path.join(__dirname, '../fixtures/zoom-center/expected.png'))).data; @@ -572,7 +572,52 @@ test('Map', function(t) { t.equal(numPixels, 0); t.end(); }); - }) + }); + + t.test('addImage test', function(t) { + var map = new mbgl.Map(options); + var newStyle = JSON.parse(JSON.stringify(style)); + style.layers.push({ + source: 'catImage', + id: 'catImage', + type: 'symbol', + layout: { + 'icon-image': 'catImage', + 'icon-size': 1, + 'icon-allow-overlap': true + } + }); + style.sources.catImage = {}; + style.sources.catImage = { + type: 'geojson', + data: { + type: 'Feature', + properties: {}, + geometry: { + type: "Point", + coordinates: [ + 0, + 0 + ] + } + } + }; + map.load(style); + map.addImage('catImage', PNG.sync.read(fs.readFileSync(path.join(__dirname, '../fixtures/cat.png'))).data, { + height: 128, + width: 128, + pixelRatio: 1 + }); + map.render({zoom: 0}, function(err, actual) { + t.error(err); + var pixelmatch = require('pixelmatch'); + var expected = PNG.sync.read( + fs.readFileSync(path.join(__dirname, '../fixtures/image-test.png'))).data; + var numPixels = pixelmatch(actual, expected, undefined, 512, 512, { threshold: 0.13 }); + t.equal(numPixels, 0); + t.end(); + }); + }); }); t.test('request callback', function (t) { -- cgit v1.2.1