Add 'loadstart' and 'loadend' events to some of our exciting layers like WFS, GML, GeoRSS, and Text. tests to back it up. (Closes #808)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4252 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-09-13 01:23:06 +00:00
parent aa70587033
commit ff82936fba
9 changed files with 292 additions and 3 deletions

View File

@@ -22,6 +22,12 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
*/
isBaseLayer: false,
/**
* Property: tile
* {<OpenLayers.Tile.WFS>}
*/
tile: null,
/**
* APIProperty: ratio
* {Float} the ratio of image/tile size to map size (this is the untiled
@@ -234,6 +240,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
if (!this.tile) {
this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,
url, tileSize);
this.addTileMonitoringHooks(this.tile);
this.tile.draw();
} else {
if (this.vectorMode) {
@@ -243,6 +250,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
this.clearMarkers();
}
this.tile.destroy();
this.removeTileMonitoringHooks(this.tile);
this.tile = null;
this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,
@@ -252,6 +260,50 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
}
},
/**
* 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 tile
* (making sure to check that the tile is always the layer's current
* tile before taking any action).
*
* Parameters:
* tile - {<OpenLayers.Tile>}
*/
addTileMonitoringHooks: function(tile) {
tile.onLoadStart = function() {
//if this is the the layer's current tile, then trigger
// a 'loadstart'
if (this == this.layer.tile) {
this.layer.events.triggerEvent("loadstart");
}
};
tile.events.register("loadstart", tile, tile.onLoadStart);
tile.onLoadEnd = function() {
//if this is the the layer's current tile, then trigger
// a 'tileloaded' and 'loadend'
if (this == this.layer.tile) {
this.layer.events.triggerEvent("tileloaded");
this.layer.events.triggerEvent("loadend");
}
};
tile.events.register("loadend", tile, 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.events.unregister("loadstart", tile, tile.onLoadStart);
tile.events.unregister("loadend", tile, tile.onLoadEnd);
},
/**
* Method: onMapResize
* Call the onMapResize method of the appropriate parent class.