Changeset 4252
- Timestamp:
- 09/12/07 21:23:06 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer/GML.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/Text.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/WFS.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Tile/WFS.js (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_GML.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_GeoRSS.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_Text.html (modified) (1 diff)
- trunk/openlayers/tests/owls.xml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer/GML.js
r4223 r4252 82 82 // See http://trac.openlayers.org/ticket/404 83 83 if(this.visibility && !this.loaded){ 84 this.events.triggerEvent("loadstart"); 84 85 this.loadGML(); 85 86 } … … 114 115 var gml = this.format ? new this.format() : new OpenLayers.Format.GML(); 115 116 this.addFeatures(gml.read(doc)); 117 this.events.triggerEvent("loadend"); 116 118 }, 117 119 … … 126 128 requestFailure: function(request) { 127 129 alert("Error in loading GML file "+this.url); 130 this.events.triggerEvent("loadend"); 128 131 }, 129 132 trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
r4226 r4252 68 68 this.location = location; 69 69 this.features = []; 70 this.events.triggerEvent("loadstart"); 70 71 OpenLayers.loadURL(location, null, this, this.parseData); 71 72 }, … … 210 211 this.addMarker(marker); 211 212 } 213 this.events.triggerEvent("loadend"); 212 214 }, 213 215 trunk/openlayers/lib/OpenLayers/Layer/Text.js
r4225 r4252 48 48 this.features = new Array(); 49 49 if (this.location != null) { 50 OpenLayers.loadURL(this.location, null, this, this.parseData); 50 51 var onFail = function(e) { 52 this.events.triggerEvent("loadend"); 53 }; 54 55 this.events.triggerEvent("loadstart"); 56 OpenLayers.loadURL(this.location, null, 57 this, this.parseData, onFail); 51 58 } 52 59 }, … … 156 163 } 157 164 } 165 this.events.triggerEvent("loadend"); 158 166 }, 159 167 trunk/openlayers/lib/OpenLayers/Layer/WFS.js
r4189 r4252 22 22 */ 23 23 isBaseLayer: false, 24 25 /** 26 * Property: tile 27 * {<OpenLayers.Tile.WFS>} 28 */ 29 tile: null, 24 30 25 31 /** … … 235 241 this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds, 236 242 url, tileSize); 243 this.addTileMonitoringHooks(this.tile); 237 244 this.tile.draw(); 238 245 } else { … … 244 251 } 245 252 this.tile.destroy(); 253 this.removeTileMonitoringHooks(this.tile); 246 254 247 255 this.tile = null; … … 251 259 } 252 260 } 261 }, 262 263 /** 264 * Method: addTileMonitoringHooks 265 * This function takes a tile as input and adds the appropriate hooks to 266 * the tile so that the layer can keep track of the loading tile 267 * (making sure to check that the tile is always the layer's current 268 * tile before taking any action). 269 * 270 * Parameters: 271 * tile - {<OpenLayers.Tile>} 272 */ 273 addTileMonitoringHooks: function(tile) { 274 tile.onLoadStart = function() { 275 //if this is the the layer's current tile, then trigger 276 // a 'loadstart' 277 if (this == this.layer.tile) { 278 this.layer.events.triggerEvent("loadstart"); 279 } 280 }; 281 tile.events.register("loadstart", tile, tile.onLoadStart); 282 283 tile.onLoadEnd = function() { 284 //if this is the the layer's current tile, then trigger 285 // a 'tileloaded' and 'loadend' 286 if (this == this.layer.tile) { 287 this.layer.events.triggerEvent("tileloaded"); 288 this.layer.events.triggerEvent("loadend"); 289 } 290 }; 291 tile.events.register("loadend", tile, tile.onLoadEnd); 292 }, 293 294 /** 295 * Method: removeTileMonitoringHooks 296 * This function takes a tile as input and removes the tile hooks 297 * that were added in addTileMonitoringHooks() 298 * 299 * Parameters: 300 * tile - {<OpenLayers.Tile>} 301 */ 302 removeTileMonitoringHooks: function(tile) { 303 tile.events.unregister("loadstart", tile, tile.onLoadStart); 304 tile.events.unregister("loadend", tile, tile.onLoadEnd); 253 305 }, 254 306 trunk/openlayers/lib/OpenLayers/Tile/WFS.js
r4227 r4252 76 76 draw:function() { 77 77 if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 78 if (this.isLoading) { 79 //if already loading, send 'reload' instead of 'loadstart'. 80 this.events.triggerEvent("reload"); 81 } else { 82 this.isLoading = true; 83 this.events.triggerEvent("loadstart"); 84 } 78 85 this.loadFeaturesForRegion(this.requestSuccess); 79 86 } … … 122 129 } 123 130 } 131 if (this.events) { 132 this.events.triggerEvent("loadend"); 133 } 124 134 }, 125 135 trunk/openlayers/tests/Layer/test_GML.html
r4059 r4252 5 5 6 6 var name = "GML Layer"; 7 8 var gml = "./owls.xml"; 9 10 // if this test is running online, different rules apply 11 var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1); 12 if (isMSIE) { 13 gml = "." + gml; 14 } 7 15 8 16 function test_01_Layer_GML_constructor(t) { … … 15 23 16 24 } 25 function test_Layer_GML_events(t) { 26 t.plan(3); 27 28 var layer = new OpenLayers.Layer.GML(name, gml, {isBaseLayer: true}); 29 layer.events.register("loadstart", layer, function() { 30 t.ok(true, "loadstart called.") 31 }); 32 layer.events.register("loadend", layer, function() { 33 t.ok(true, "loadend called.") 34 }); 35 var map = new OpenLayers.Map("map"); 36 map.addLayer(layer); 37 map.zoomToMaxExtent(); 38 t.delay_call(1, function() { 39 t.ok(true, "waited for 1s"); 40 }); 41 42 } 17 43 </script> 18 44 </head> trunk/openlayers/tests/Layer/test_GeoRSS.html
r4226 r4252 81 81 map.setCenter(new OpenLayers.LonLat(0,0),0); 82 82 var event = {}; 83 t.delay_call( 1, function() {83 t.delay_call( 2, function() { 84 84 t.ok(layer.markers[0].events, "First marker has an events object"); 85 85 t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); … … 160 160 }); 161 161 } 162 162 function test_Layer_GeoRSS_loadend_Event(t) { 163 var browserCode = OpenLayers.Util.getBrowserName(); 164 if (browserCode == "msie") { 165 t.plan(1); 166 t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it."); 167 } else { 168 t.plan(2); 169 layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); 170 t.delay_call(2, function() { 171 layer.events.register('loadend', layer, function() { 172 t.ok(true, "Loadend event fired"); 173 }); 174 layer.parseData({ 175 'responseText': '<xml xmlns="http://example.com"><title> </title></xml>' 176 }); 177 t.ok(true, "Parsing data didn't fail"); 178 }); 179 } 180 } 181 163 182 function test_99_Layer_GeoRSS_destroy (t) { 164 183 t.plan( 1 ); trunk/openlayers/tests/Layer/test_Text.html
r4225 r4252 119 119 }); 120 120 } 121 function test_Layer_Text_loadend_Event(t) { 122 t.plan(2); 123 layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile}); 124 t.delay_call(2, function() { 125 layer.events.register('loadend', layer, function() { 126 t.ok(true, "Loadend event fired"); 127 }); 128 layer.parseData({ 129 'responseText':'' 130 }); 131 t.ok(true, "Parsing data didn't fail"); 132 }); 133 } 121 134 122 135 function test_99_Layer_Text_destroy (t) {
