Skip to content

Commit

Permalink
Ensure _rerender is called if _styleDirty is true (#2990)
Browse files Browse the repository at this point in the history
* Add failing test for issue #2936

* Ensure _rerender is called if _styleDirty is true

Closes #2936
  • Loading branch information
anandthakker authored and mourner committed Aug 17, 2016
1 parent 036bf53 commit dc81c54
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
this._styleDirty = true;
}

if (this._sourcesDirty || this._repaint || !this.animationLoop.stopped()) {
if (this._sourcesDirty || this._repaint || this._styleDirty) {
this._rerender();
}

Expand Down
62 changes: 62 additions & 0 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,68 @@ test('Map', function(t) {
t.end();
});

test('render stabilizes', function (t) {
var style = createStyle();
style.sources.mapbox = {
type: 'vector',
minzoom: 1,
maxzoom: 10,
tiles: ['http://example.com/{z}/{x}/{y}.png']
};
style.layers.push({
id: 'layerId',
type: 'circle',
source: 'mapbox',
'source-layer': 'sourceLayer'
});

var timer;
var map = createMap({ style: style });
map.on('render', function () {
if (timer) clearTimeout(timer);
timer = setTimeout(function () {
map.off('render');
map.on('render', t.fail);
t.notOk(map._frameId, 'no rerender scheduled');
t.end();
}, 100);
});
});

test('#removeLayer restores Map#loaded() to true', function (t) {
var style = createStyle();
style.sources.mapbox = {
type: 'vector',
minzoom: 1,
maxzoom: 10,
tiles: ['http://example.com/{z}/{x}/{y}.png']
};
style.layers.push({
id: 'layerId',
type: 'circle',
source: 'mapbox',
'source-layer': 'sourceLayer'
});

var timer;
var map = createMap({ style: style });
map.on('render', function () {
if (timer) clearTimeout(timer);
timer = setTimeout(function () {
map.off('render');
map.on('render', check);
map.removeLayer('layerId');
}, 100);
});

function check () {
if (map.loaded()) {
map.remove();
t.end();
}
}
});

t.end();
});

Expand Down

0 comments on commit dc81c54

Please sign in to comment.