Skip to content

Commit

Permalink
Enable map recycling in GL JS render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Aug 4, 2017
1 parent df6c404 commit fbb67c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@
"lint-css": "stylelint 'dist/mapbox-gl.css'",
"open-changed-examples": "git diff --name-only mb-pages HEAD -- docs/_posts/examples/*.html | awk '{print \"http://127.0.0.1:4000/mapbox-gl-js/example/\" substr($0,33,length($0)-37)}' | xargs open",
"test": "run-s lint lint-css test-unit test-flow",
"test-suite": "run-s test-render test-query",
"test-suite": "run-s test-render test-render-recycle-map test-query",
"test-suite-clean": "find test/integration/*-tests -mindepth 2 -type d -not \\( -exec test -e \"{}/style.json\" \\; \\) -print | xargs -t rm -r",
"test-unit": "tap --reporter dot --no-coverage test/unit",
"test-render": "node --max-old-space-size=2048 test/render.test.js",
"test-render-recycle-map": "node --max-old-space-size=2048 test/render.test.js --recycle-map",
"test-query": "node test/query.test.js",
"test-flow": "flow .",
"test-flow-cov": "flow-coverage-report -i 'src/**/*.js' -t html",
Expand Down
41 changes: 26 additions & 15 deletions test/suite_implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const path = require('path');
rtlTextPlugin['applyArabicShaping'] = rtlText.applyArabicShaping;
rtlTextPlugin['processBidirectionalText'] = rtlText.processBidirectionalText;

let map;

module.exports = function(style, options, _callback) {

let wasCallbackCalled = false;
function callback() {
if (!wasCallbackCalled) {
Expand All @@ -30,20 +33,26 @@ module.exports = function(style, options, _callback) {
Object.defineProperty(container, 'offsetWidth', {value: options.width});
Object.defineProperty(container, 'offsetHeight', {value: options.height});

const map = new Map({
container: container,
style: style,
classes: options.classes,
interactive: false,
attributionControl: false,
preserveDrawingBuffer: true
});
if (typeof map === 'undefined' || !options.recycleMap) {
map = new Map({
container: container,
style: style,
classes: options.classes,
interactive: false,
attributionControl: false,
preserveDrawingBuffer: true
});

// Configure the map to never stop the render loop
map.repaint = true;
// Configure the map to never stop the render loop
map.repaint = true;
} else if (options.recycleMap) {
map.resize();
map.setStyle(style, {diff: false});
map.setClasses(options.classes || {});
}

if (options.debug) map.showTileBoundaries = true;
if (options.showOverdrawInspector) map.showOverdrawInspector = true;
map.showTileBoundaries = options.debug;
map.showOverdrawInspector = options.showOverdrawInspector;

const gl = map.painter.gl;

Expand Down Expand Up @@ -77,9 +86,11 @@ module.exports = function(style, options, _callback) {
map.queryRenderedFeatures(options.queryGeometry, options.queryOptions || {}) :
[];

map.remove();
gl.getExtension('STACKGL_destroy_context').destroy();
delete map.painter.gl;
if (!options.recycleMap) {
map.remove();
gl.getExtension('STACKGL_destroy_context').destroy();
delete map.painter.gl;
}

callback(null, data, results.map((feature) => {
feature = feature.toJSON();
Expand Down

0 comments on commit fbb67c3

Please sign in to comment.