From 6f00becffeaf603942246a6ca4e06176626f68bf Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 4 Aug 2017 11:05:14 +0300 Subject: [test] One map per pixel ratio in render.test.js --recycle-map --- platform/node/test/suite_implementation.js | 52 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'platform') 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)); -- cgit v1.2.1