Making loaded tile available to tileloaded listeners.

This commit is contained in:
ahocevar
2012-02-16 16:29:06 +01:00
parent ed502f6f19
commit 93e4d0b94c
2 changed files with 12 additions and 9 deletions
+4 -2
View File
@@ -199,7 +199,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* tileloaded - Triggered when each new tile is * tileloaded - Triggered when each new tile is
* loaded, as a means of progress update to listeners. * loaded, as a means of progress update to listeners.
* listeners can access 'numLoadingTiles' if they wish to keep * listeners can access 'numLoadingTiles' if they wish to keep
* track of the loading progress. * track of the loading progress. Listeners are called with an object
* with a tile property as first argument, making the loded tile
* available to the listener.
*/ */
/** /**
@@ -971,7 +973,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
tile.onLoadEnd = function() { tile.onLoadEnd = function() {
this.numLoadingTiles--; this.numLoadingTiles--;
this.events.triggerEvent("tileloaded"); this.events.triggerEvent("tileloaded", {tile: tile});
//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.tileQueue.length === 0 && this.numLoadingTiles === 0) { if (this.tileQueue.length === 0 && this.numLoadingTiles === 0) {
this.events.triggerEvent("loadend"); this.events.triggerEvent("loadend");
+8 -7
View File
@@ -505,12 +505,12 @@
} }
function test_Layer_Grid_addTileMonitoringHooks(t) { function test_Layer_Grid_addTileMonitoringHooks(t) {
t.plan(14); t.plan(15);
layer = new OpenLayers.Layer.Grid(); layer = new OpenLayers.Layer.Grid();
layer.events = { layer.events = {
'triggerEvent': function(str) { 'triggerEvent': function(str, evt) {
g_events.push(str); g_events.push([str, evt]);
} }
} }
@@ -536,7 +536,7 @@
g_events = []; g_events = [];
tile.onLoadStart.apply(layer); tile.onLoadStart.apply(layer);
t.eq(g_events[0], "loadstart", "loadstart event triggered when numLoadingTiles is 0"); t.eq(g_events[0][0], "loadstart", "loadstart event triggered when numLoadingTiles is 0");
t.eq(layer.numLoadingTiles, 1, "numLoadingTiles incremented"); t.eq(layer.numLoadingTiles, 1, "numLoadingTiles incremented");
g_events = []; g_events = [];
@@ -553,7 +553,8 @@
layer.numLoadingTiles = 2; layer.numLoadingTiles = 2;
g_events = []; g_events = [];
tile.onLoadEnd.apply(layer); tile.onLoadEnd.apply(layer);
t.eq(g_events[0], "tileloaded", "tileloaded triggered when numLoadingTiles is > 0"); t.eq(g_events[0][0], "tileloaded", "tileloaded triggered when numLoadingTiles is > 0");
t.ok(g_events[0][1].tile === tile, "tile passed as tile property to event object");
t.eq(g_events.length, 1, "loadend event not triggered when numLoadingTiles is > 0"); t.eq(g_events.length, 1, "loadend event not triggered when numLoadingTiles is > 0");
t.eq(layer.numLoadingTiles, 1, "numLoadingTiles decremented"); t.eq(layer.numLoadingTiles, 1, "numLoadingTiles decremented");
@@ -561,8 +562,8 @@
g_events = []; g_events = [];
layer.grid = [[{}]]; // to prevent error in updateBackBuffer layer.grid = [[{}]]; // to prevent error in updateBackBuffer
tile.onLoadEnd.apply(layer); tile.onLoadEnd.apply(layer);
t.eq(g_events[0], "tileloaded", "tileloaded triggered when numLoadingTiles is 0"); t.eq(g_events[0][0], "tileloaded", "tileloaded triggered when numLoadingTiles is 0");
t.eq(g_events[1], "loadend", "loadend event triggered when numLoadingTiles is 0"); t.eq(g_events[1][0], "loadend", "loadend event triggered when numLoadingTiles is 0");
t.eq(layer.numLoadingTiles, 0, "numLoadingTiles decremented"); t.eq(layer.numLoadingTiles, 0, "numLoadingTiles decremented");
} }