diff --git a/lib/OpenLayers/Layer/GML.js b/lib/OpenLayers/Layer/GML.js index 3c3c231a10..a86614ac86 100644 --- a/lib/OpenLayers/Layer/GML.js +++ b/lib/OpenLayers/Layer/GML.js @@ -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" diff --git a/lib/OpenLayers/Layer/GeoRSS.js b/lib/OpenLayers/Layer/GeoRSS.js index c87735b93d..c7e31c8548 100644 --- a/lib/OpenLayers/Layer/GeoRSS.js +++ b/lib/OpenLayers/Layer/GeoRSS.js @@ -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"); }, /** diff --git a/lib/OpenLayers/Layer/Text.js b/lib/OpenLayers/Layer/Text.js index f5dc0135f6..9c62590369 100644 --- a/lib/OpenLayers/Layer/Text.js +++ b/lib/OpenLayers/Layer/Text.js @@ -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"); }, /** diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index e93b48e7f4..bbaea5ff33 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -22,6 +22,12 @@ OpenLayers.Layer.WFS = OpenLayers.Class( */ isBaseLayer: false, + /** + * Property: tile + * {} + */ + 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 - {} + */ + 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 - {} + */ + 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. diff --git a/lib/OpenLayers/Tile/WFS.js b/lib/OpenLayers/Tile/WFS.js index 285dbe3bdd..2df96555f1 100644 --- a/lib/OpenLayers/Tile/WFS.js +++ b/lib/OpenLayers/Tile/WFS.js @@ -75,6 +75,13 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, { */ draw:function() { if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) { + if (this.isLoading) { + //if already loading, send 'reload' instead of 'loadstart'. + this.events.triggerEvent("reload"); + } else { + this.isLoading = true; + this.events.triggerEvent("loadstart"); + } this.loadFeaturesForRegion(this.requestSuccess); } }, @@ -121,6 +128,9 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, { this.addResults(resultFeatures); } } + if (this.events) { + this.events.triggerEvent("loadend"); + } }, /** diff --git a/tests/Layer/test_GML.html b/tests/Layer/test_GML.html index 104e03d1f3..4f8d04b179 100644 --- a/tests/Layer/test_GML.html +++ b/tests/Layer/test_GML.html @@ -5,6 +5,14 @@ var name = "GML Layer"; + var gml = "./owls.xml"; + + // if this test is running online, different rules apply + var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1); + if (isMSIE) { + gml = "." + gml; + } + function test_01_Layer_GML_constructor(t) { t.plan(3); @@ -14,6 +22,24 @@ t.ok(layer.renderer.CLASS_NAME, "layer has a renderer"); } + function test_Layer_GML_events(t) { + t.plan(3); + + var layer = new OpenLayers.Layer.GML(name, gml, {isBaseLayer: true}); + layer.events.register("loadstart", layer, function() { + t.ok(true, "loadstart called.") + }); + layer.events.register("loadend", layer, function() { + t.ok(true, "loadend called.") + }); + var map = new OpenLayers.Map("map"); + map.addLayer(layer); + map.zoomToMaxExtent(); + t.delay_call(1, function() { + t.ok(true, "waited for 1s"); + }); + + } diff --git a/tests/Layer/test_GeoRSS.html b/tests/Layer/test_GeoRSS.html index be2878e86b..ba96130965 100644 --- a/tests/Layer/test_GeoRSS.html +++ b/tests/Layer/test_GeoRSS.html @@ -80,7 +80,7 @@ map.addLayer(layer); map.setCenter(new OpenLayers.LonLat(0,0),0); var event = {}; - t.delay_call( 1, function() { + t.delay_call( 2, function() { t.ok(layer.markers[0].events, "First marker has an events object"); t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); layer.markers[0].events.triggerEvent('click', event); @@ -159,7 +159,26 @@ t.eq(otherLayer.markers[0].icon.url, the_icon.url,"The layer with an icon has that icon."); }); } - + function test_Layer_GeoRSS_loadend_Event(t) { + var browserCode = OpenLayers.Util.getBrowserName(); + if (browserCode == "msie") { + t.plan(1); + t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it."); + } else { + t.plan(2); + layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); + t.delay_call(2, function() { + layer.events.register('loadend', layer, function() { + t.ok(true, "Loadend event fired"); + }); + layer.parseData({ + 'responseText': ' ' + }); + t.ok(true, "Parsing data didn't fail"); + }); + } + } + function test_99_Layer_GeoRSS_destroy (t) { t.plan( 1 ); layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); diff --git a/tests/Layer/test_Text.html b/tests/Layer/test_Text.html index 1e54803e01..4538617333 100644 --- a/tests/Layer/test_Text.html +++ b/tests/Layer/test_Text.html @@ -118,6 +118,19 @@ t.eq(map.popups.length, 0, "no popup on second marker"); }); } + function test_Layer_Text_loadend_Event(t) { + t.plan(2); + layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile}); + t.delay_call(2, function() { + layer.events.register('loadend', layer, function() { + t.ok(true, "Loadend event fired"); + }); + layer.parseData({ + 'responseText':'' + }); + t.ok(true, "Parsing data didn't fail"); + }); + } function test_99_Layer_Text_destroy (t) { t.plan( 1 ); diff --git a/tests/owls.xml b/tests/owls.xml new file mode 100644 index 0000000000..4a001eca26 --- /dev/null +++ b/tests/owls.xml @@ -0,0 +1,156 @@ + + + + + -89.817223,45.005555 -74.755001,51.701388 + + + + + + -79.771668,45.891110 -79.771668,45.891110 + + + + + -79.771668,45.891110 + + + + + + + + + -83.755834,46.365277 -83.755834,46.365277 + + + owl + + + -83.755834,46.365277 + + + + + + + + + -83.808612,46.175277 -83.808612,46.175277 + + + + + -83.808612,46.175277 + + + + + + + + + -84.111112,46.309166 -84.111112,46.309166 + + + + + -84.111112,46.309166 + + + + + + + + + -83.678612,46.821110 -83.678612,46.821110 + + + + + -83.678612,46.821110 + + + + + + + + + -83.664445,46.518888 -83.664445,46.518888 + + + + + -83.664445,46.518888 + + + + + + + + + -80.613334,46.730277 -80.613334,46.730277 + + + + + -80.613334,46.730277 + + + + + + + + + -79.676946,45.428054 -79.676946,45.428054 + + + + + -79.676946,45.428054 + + + + + + + + + -83.853056,46.236944 -83.853056,46.236944 + + + + + -83.853056,46.236944 + + + + + + + + + -82.289167,45.896388 -82.289167,45.896388 + + + + + -82.289167,45.896388 + + + + + +