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 3, 2017
1 parent 8c2db88 commit bfb4797
Showing 1 changed file with 26 additions and 15 deletions.
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 bfb4797

Please sign in to comment.