diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-08-04 11:05:14 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-08-31 10:17:21 +0300 |
commit | 6f00becffeaf603942246a6ca4e06176626f68bf (patch) | |
tree | 614b7d0081876925c40ebe7ffe1a2b1af8e24571 | |
parent | b43d88b7253d641fe24fcc030a58f207b2e33f10 (diff) | |
download | qtlocation-mapboxgl-6f00becffeaf603942246a6ca4e06176626f68bf.tar.gz |
[test] One map per pixel ratio in render.test.js --recycle-map
-rw-r--r-- | platform/node/test/suite_implementation.js | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js index 0ddf49679b..323f429bed 100644 --- a/platform/node/test/suite_implementation.js +++ b/platform/node/test/suite_implementation.js @@ -10,23 +10,27 @@ mbgl.on('message', function(msg) { console.log('%s (%s): %s', msg.severity, msg.class, msg.text); }); +// Map of map objects by pixel ratio +var maps = new Map(); + module.exports = function (style, options, callback) { - var map = new mbgl.Map({ - ratio: options.pixelRatio, - request: function(req, callback) { - request(req.url, {encoding: null}, function (err, response, body) { - if (err) { - callback(err); - } else if (response.statusCode == 404) { - callback(); - } else if (response.statusCode != 200) { - callback(new Error(response.statusMessage)); - } else { - callback(null, {data: body}); - } - }); + if (options.recycleMap) { + if (maps.has(options.pixelRatio)) { + var map = maps.get(options.pixelRatio); + map.request = mapRequest; + } else { + maps.set(options.pixelRatio, new mbgl.Map({ + ratio: options.pixelRatio, + request: mapRequest + })); + var map = maps.get(options.pixelRatio); } - }); + } else { + var map = new mbgl.Map({ + ratio: options.pixelRatio, + request: mapRequest + }); + } var timedOut = false; var watchdog = setTimeout(function () { @@ -48,12 +52,28 @@ module.exports = function (style, options, callback) { map.load(style, { defaultStyleCamera: true }); + function mapRequest(req, callback) { + request(req.url, {encoding: null}, function (err, response, body) { + if (err) { + callback(err); + } else if (response.statusCode == 404) { + callback(); + } else if (response.statusCode != 200) { + callback(new Error(response.statusMessage)); + } else { + callback(null, {data: body}); + } + }); + }; + applyOperations(options.operations, function() { map.render(options, function (err, pixels) { var results = options.queryGeometry ? map.queryRenderedFeatures(options.queryGeometry, options.queryOptions || {}) : []; - map.release(); + if (!options.recycleMap) { + map.release(); + } if (timedOut) return; clearTimeout(watchdog); callback(err, pixels, results.map(prepareFeatures)); |