Triggering loadstart and loadend events for the Image layer. Thanks for the excellent patch sky. r=me (closes #1700)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8923 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-01 16:07:50 +00:00
parent 654291ecff
commit c7afe8e134
3 changed files with 87 additions and 5 deletions

View File

@@ -84,6 +84,7 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
*/
destroy: function() {
if (this.tile) {
this.removeTileMonitoringHooks(this.tile);
this.tile.destroy();
this.tile = null;
}
@@ -166,6 +167,7 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
//create the new tile
this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent,
null, this.tileSize);
this.addTileMonitoringHooks(this.tile);
} else {
//just resize the tile and set it's new position
this.tile.size = this.tileSize.clone();
@@ -184,6 +186,45 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
this.tileSize = new OpenLayers.Size(tileWidth, tileHeight);
},
/**
* Method: addTileMonitoringHooks
* This function takes a tile as input and adds the appropriate hooks to
* the tile so that the layer can keep track of the loading tiles.
*
* Parameters:
* tile - {<OpenLayers.Tile>}
*/
addTileMonitoringHooks: function(tile) {
tile.onLoadStart = function() {
this.events.triggerEvent("loadstart");
};
tile.events.register("loadstart", this, tile.onLoadStart);
tile.onLoadEnd = function() {
this.events.triggerEvent("loadend");
};
tile.events.register("loadend", this, tile.onLoadEnd);
tile.events.register("unload", this, tile.onLoadEnd);
},
/**
* Method: removeTileMonitoringHooks
* This function takes a tile as input and removes the tile hooks
* that were added in <addTileMonitoringHooks>.
*
* Parameters:
* tile - {<OpenLayers.Tile>}
*/
removeTileMonitoringHooks: function(tile) {
tile.unload();
tile.events.un({
"loadstart": tile.onLoadStart,
"loadend": tile.onLoadEnd,
"unload": tile.onLoadEnd,
scope: this
});
},
/**
* APIMethod: setUrl
*