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

@@ -81,6 +81,7 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
// loaded after the GML is paited.
// See http://trac.openlayers.org/ticket/404
if(this.visibility && !this.loaded){
this.events.triggerEvent("loadstart");
this.loadGML();
}
},
@@ -113,6 +114,7 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
var gml = this.format ? new this.format() : new OpenLayers.Format.GML();
this.addFeatures(gml.read(doc));
this.events.triggerEvent("loadend");
},
/**
@@ -125,6 +127,7 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
*/
requestFailure: function(request) {
alert("Error in loading GML file "+this.url);
this.events.triggerEvent("loadend");
},
CLASS_NAME: "OpenLayers.Layer.GML"

View File

@@ -67,6 +67,7 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, {
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name, options]);
this.location = location;
this.features = [];
this.events.triggerEvent("loadstart");
OpenLayers.loadURL(location, null, this, this.parseData);
},
@@ -209,6 +210,7 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, {
marker.events.register('click', feature, this.markerClick);
this.addMarker(marker);
}
this.events.triggerEvent("loadend");
},
/**

View File

@@ -47,7 +47,14 @@ OpenLayers.Layer.Text = OpenLayers.Class(OpenLayers.Layer.Markers, {
OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments);
this.features = new Array();
if (this.location != null) {
OpenLayers.loadURL(this.location, null, this, this.parseData);
var onFail = function(e) {
this.events.triggerEvent("loadend");
};
this.events.triggerEvent("loadstart");
OpenLayers.loadURL(this.location, null,
this, this.parseData, onFail);
}
},
@@ -155,6 +162,7 @@ OpenLayers.Layer.Text = OpenLayers.Class(OpenLayers.Layer.Markers, {
}
}
}
this.events.triggerEvent("loadend");
},
/**

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.