Hi, When a tile fails to load the OpenLayers.Util.onImageLoadError takes care of handling the error and the “loadend” event is called without any indication on if one or more tiles are missing.
Attached patch add support for layer events when a tile has failed loading. When a single tile is missing it trigger the event “loadwarning” to indicate that something is wrong with this layer. When all the tiles in a layer are missing it trigger the event “loadfail”. The patch includes an update to the event.html example. /Karsten
Index: examples/events.html =================================================================== --- examples/events.html (revision 11895) +++ examples/events.html (working copy) @@ -54,6 +54,9 @@ function mapEvent(event) { log(event.type); } + function layerEvent(event) { + log(event.object.name + ' - ' +event.type); + } function mapBaseLayerChanged(event) { log(event.type + " " + event.layer.name); } @@ -122,6 +125,13 @@ {layers:"nexrad-n0r-wmst", transparent: "TRUE", format: 'image/png'}, {isBaseLayer: false} ); + nexrad.events.on({ + 'loadstart': layerEvent, + 'loadend': layerEvent, + 'loadcancel': layerEvent, + 'loadwarning': layerEvent, + 'loadfail': layerEvent + }); map.addLayers([vmap, landsat, nexrad]); Index: lib/OpenLayers/Layer.js =================================================================== --- lib/OpenLayers/Layer.js (revision 11895) +++ lib/OpenLayers/Layer.js (working copy) @@ -89,7 +89,7 @@ * a *layer* property referencing the layer. */ EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged", - "move", "moveend", "added", "removed"], + "move", "moveend", "added", "removed", "loadwarning", "loadfail"], /** * Constant: RESOLUTION_PROPERTIES Index: lib/OpenLayers/Tile.js =================================================================== --- lib/OpenLayers/Tile.js (revision 11895) +++ lib/OpenLayers/Tile.js (working copy) @@ -29,7 +29,7 @@ * Constant: EVENT_TYPES * {Array(String)} Supported application event types */ - EVENT_TYPES: [ "loadstart", "loadend", "reload", "unload"], + EVENT_TYPES: [ "loadstart", "loadend", "reload", "unload", "loadfail"], /** * APIProperty: events Index: lib/OpenLayers/Layer/Grid.js =================================================================== --- lib/OpenLayers/Layer/Grid.js (revision 11895) +++ lib/OpenLayers/Layer/Grid.js (working copy) @@ -672,6 +672,18 @@ }; tile.events.register("loadend", this, tile.onLoadEnd); tile.events.register("unload", this, tile.onLoadEnd); + + tile.onLoadFail = function() { + this.numLoadingTiles--; + this.events.triggerEvent("tileloaded"); + //if that was the last tile, then trigger a 'loadfail' on the layer + if (this.numLoadingTiles == 0) { + this.events.triggerEvent("loadfail"); + } else { + this.events.triggerEvent("loadwarning"); + } + }; + tile.events.register("loadfail", this, tile.onLoadFail); }, /** @@ -687,6 +699,7 @@ tile.events.un({ "loadstart": tile.onLoadStart, "loadend": tile.onLoadEnd, + "loadfail": tile.onLoadFail, "unload": tile.onLoadEnd, scope: this }); Index: lib/OpenLayers/Tile/Image.js =================================================================== --- lib/OpenLayers/Tile/Image.js (revision 11895) +++ lib/OpenLayers/Tile/Image.js (working copy) @@ -403,7 +403,7 @@ //bind a listener to the onload of the image div so that we // can register when a tile has finished loading. - var onload = function() { + var onload = function(error) { //normally isLoading should always be true here but there are some // right funky conditions where loading and then reloading a tile @@ -412,7 +412,11 @@ // if (this.isLoading) { this.isLoading = false; - this.events.triggerEvent("loadend"); + if (error===true) { + this.events.triggerEvent("loadfail"); + } else { + this.events.triggerEvent("loadend"); + } } }; @@ -435,7 +439,7 @@ // the error, we can continue as if the image was loaded // successfully. if (this.imgDiv._attempts > OpenLayers.IMAGE_RELOAD_ATTEMPTS) { - onload.call(this); + onload.call(this,true); } }; OpenLayers.Event.observe(this.imgDiv, "error",
_______________________________________________ Dev mailing list d...@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/openlayers-dev