New events: loaderror for Tile, tileerror for Layer.Grid.

This commit is contained in:
ahocevar
2012-03-05 14:20:01 +01:00
parent d7533096e9
commit fe63d0aa63
6 changed files with 56 additions and 6 deletions

View File

@@ -202,6 +202,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* 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.
* tileerror - Triggered before the tileloaded event (i.e. when the tile is
* still hidden) if a tile failed to load. Listeners receive an object
* as first argument, which has a tile property that references the
* tile that could not be loaded.
*/
/**
@@ -969,7 +973,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
}
this.numLoadingTiles++;
};
tile.events.register("loadstart", this, tile.onLoadStart);
tile.onLoadEnd = function() {
this.numLoadingTiles--;
@@ -987,8 +990,18 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
}
}
};
tile.events.register("loadend", this, tile.onLoadEnd);
tile.events.register("unload", this, tile.onLoadEnd);
tile.onLoadError = function() {
this.events.triggerEvent("tileerror", {tile: tile});
};
tile.events.on({
"loadstart": tile.onLoadStart,
"loadend": tile.onLoadEnd,
"unload": tile.onLoadEnd,
"loaderror": tile.onLoadError,
scope: this
});
},
/**
@@ -1005,6 +1018,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
"loadstart": tile.onLoadStart,
"loadend": tile.onLoadEnd,
"unload": tile.onLoadEnd,
"loaderror": tile.onLoadError,
scope: this
});
},

View File

@@ -40,6 +40,8 @@ OpenLayers.Tile = OpenLayers.Class({
* to call <draw>(true) to actually draw the tile.
* loadstart - Triggered when tile loading starts.
* loadend - Triggered when tile loading ends.
* loaderror - Triggered before the loadend event (i.e. when the tile is
* still hidden) if the tile could not be loaded.
* reload - Triggered when an already loading tile is reloaded.
* unload - Triggered before a tile is unloaded.
*/

View File

@@ -425,6 +425,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
this.setImgSrc(this.layer.getURL(this.bounds));
} else {
OpenLayers.Element.addClass(img, "olImageLoadError");
this.events.triggerEvent("loaderror");
this.onImageLoad();
}
}