diff options
author | Bobby Sudekum <bobby@mapbox.com> | 2017-06-02 11:04:49 -0700 |
---|---|---|
committer | Bobby Sudekum <bobby@mapbox.com> | 2017-06-02 11:04:49 -0700 |
commit | a1cf8d9bd44d8e787afd3231fad3c2ac15f60e2c (patch) | |
tree | e35a8ba6dd4fb306a8fb564cf4d5dcc327999002 | |
parent | e82649139b69a4794b944b4a61822dd82a4d6abc (diff) | |
download | qtlocation-mapboxgl-upstream/image-test.tar.gz |
Add addImage testupstream/image-test
-rw-r--r-- | platform/node/test/fixtures/cat.png | bin | 0 -> 9921 bytes | |||
-rw-r--r-- | platform/node/test/fixtures/image-test.png | bin | 0 -> 36377 bytes | |||
-rw-r--r-- | platform/node/test/js/map.test.js | 49 |
3 files changed, 47 insertions, 2 deletions
diff --git a/platform/node/test/fixtures/cat.png b/platform/node/test/fixtures/cat.png Binary files differnew file mode 100644 index 0000000000..f46bc71167 --- /dev/null +++ b/platform/node/test/fixtures/cat.png diff --git a/platform/node/test/fixtures/image-test.png b/platform/node/test/fixtures/image-test.png Binary files differnew file mode 100644 index 0000000000..83fbd49f35 --- /dev/null +++ b/platform/node/test/fixtures/image-test.png 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) { |