Merge pull request #920 from ahocevar/backbuffer-conditional

Backbuffer and transitionend only when there are tiles. r=@bartvde
This commit is contained in:
ahocevar
2013-03-27 07:14:51 -07:00
2 changed files with 22 additions and 12 deletions
+11 -3
View File
@@ -1112,10 +1112,17 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//if that was the last tile, then trigger a 'loadend' on the layer //if that was the last tile, then trigger a 'loadend' on the layer
if (this.numLoadingTiles === 0) { if (this.numLoadingTiles === 0) {
if (this.backBuffer) { if (this.backBuffer) {
this._transitionElement = tile.imgDiv; if (this.backBuffer.childNodes.length === 0) {
for (var i=this.transitionendEvents.length-1; i>=0; --i) { // no tiles transitioning, remove immediately
this.removeBackBuffer();
} else {
// wait until transition has ended or delay has passed
this._transitionElement = aborted ?
this.div.lastChild : tile.imgDiv;
var transitionendEvents = this.transitionendEvents;
for (var i=transitionendEvents.length-1; i>=0; --i) {
OpenLayers.Event.observe(this._transitionElement, OpenLayers.Event.observe(this._transitionElement,
this.transitionendEvents[i], transitionendEvents[i],
this._removeBackBuffer); this._removeBackBuffer);
} }
// the removal of the back buffer is delayed to prevent // the removal of the back buffer is delayed to prevent
@@ -1124,6 +1131,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
this._removeBackBuffer, this.removeBackBufferDelay this._removeBackBuffer, this.removeBackBufferDelay
); );
} }
}
this.loading = false; this.loading = false;
this.events.triggerEvent("loadend"); this.events.triggerEvent("loadend");
} }
+3 -1
View File
@@ -1334,7 +1334,9 @@
t.ok(layer.backBuffer === map.layerContainerDiv.firstChild, t.ok(layer.backBuffer === map.layerContainerDiv.firstChild,
'[a] back buffer is first child of layer container div'); '[a] back buffer is first child of layer container div');
// Mark one tile loaded, to see if back buffer removal gets scheduled. // Mark one tile loaded and add an element to the backbuffer, to see if
// backbuffer removal gets scheduled.
layer.backBuffer.appendChild(document.createElement('img'));
layer.grid[1][1].onImageLoad(); layer.grid[1][1].onImageLoad();
t.ok(layer.backBufferTimerId !== null, t.ok(layer.backBufferTimerId !== null,