From e8a48a6d6333a5b092e742ce3543870c2235de88 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 13 Dec 2016 14:00:59 -0800 Subject: [node] Fix order of operations when setting zoom and center Zoom must be set first, to avoid center potentially getting constrained. Fixes #7351 --- package.json | 2 + platform/node/src/node_map.cpp | 8 ++-- .../node/test/fixtures/zoom-center/expected.png | Bin 0 -> 882 bytes platform/node/test/js/map.test.js | 42 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 platform/node/test/fixtures/zoom-center/expected.png diff --git a/package.json b/package.json index 5dde33f8a6..32d6038922 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#66397c8ee0426537d25e8d4cfcac134ca21a021b", "mkdirp": "^0.5.1", "node-cmake": "^1.2.1", + "pixelmatch": "^4.0.2", + "pngjs": "^3.0.0", "request": "^2.72.0", "tape": "^4.5.1" }, diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 48a954504c..acf83eef66 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -371,15 +371,15 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { map->setClasses(options.classes); } + if (map->getZoom() != options.zoom) { + map->setZoom(options.zoom); + } + mbgl::LatLng latLng(options.latitude, options.longitude); if (map->getLatLng() != latLng) { map->setLatLng(latLng); } - if (map->getZoom() != options.zoom) { - map->setZoom(options.zoom); - } - if (map->getBearing() != options.bearing) { map->setBearing(options.bearing); } diff --git a/platform/node/test/fixtures/zoom-center/expected.png b/platform/node/test/fixtures/zoom-center/expected.png new file mode 100644 index 0000000000..93365c04d2 Binary files /dev/null and b/platform/node/test/fixtures/zoom-center/expected.png differ diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js index e2ff8d85d0..e3b287f68f 100644 --- a/platform/node/test/js/map.test.js +++ b/platform/node/test/js/map.test.js @@ -371,6 +371,48 @@ test('Map', function(t) { map.release(); t.end(); }); + + // This can't be tested with a test-suite render test because zoom and center + // are set via a different code path when included as style properties. + t.test('sets zoom before center', function(t) { + var map = new mbgl.Map(options); + map.load({ + "version": 8, + "sources": { + "geojson": { + "type": "geojson", + "data": { + "type": "Point", + "coordinates": [ + 18.05489, + 59.32744 + ] + } + } + }, + "layers": [ + { + "id": "circle", + "type": "circle", + "source": "geojson", + "paint": { + "circle-color": "red" + } + } + ] + }); + 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; + var numPixels = pixelmatch(actual, expected, undefined, 400, 400, { threshold: 0.13 }); + t.equal(numPixels, 0); + t.end(); + }); + }) }); t.test('request callback', function (t) { -- cgit v1.2.1