summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Sudekum <bobby@mapbox.com>2017-06-02 11:04:49 -0700
committerBobby Sudekum <bobby@mapbox.com>2017-06-02 11:04:49 -0700
commita1cf8d9bd44d8e787afd3231fad3c2ac15f60e2c (patch)
treee35a8ba6dd4fb306a8fb564cf4d5dcc327999002
parente82649139b69a4794b944b4a61822dd82a4d6abc (diff)
downloadqtlocation-mapboxgl-upstream/image-test.tar.gz
Add addImage testupstream/image-test
-rw-r--r--platform/node/test/fixtures/cat.pngbin0 -> 9921 bytes
-rw-r--r--platform/node/test/fixtures/image-test.pngbin0 -> 36377 bytes
-rw-r--r--platform/node/test/js/map.test.js49
3 files changed, 47 insertions, 2 deletions
diff --git a/platform/node/test/fixtures/cat.png b/platform/node/test/fixtures/cat.png
new file mode 100644
index 0000000000..f46bc71167
--- /dev/null
+++ b/platform/node/test/fixtures/cat.png
Binary files 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
--- /dev/null
+++ b/platform/node/test/fixtures/image-test.png
Binary files 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) {