[OpenLayers-Commits] r4252 - in trunk/openlayers: lib/OpenLayers/Layer lib/OpenLayers/Tile tests tests/Layer
commits at openlayers.org
commits at openlayers.org
Wed Sep 12 21:23:07 EDT 2007
Author: euzuro
Date: 2007-09-12 21:23:06 -0400 (Wed, 12 Sep 2007)
New Revision: 4252
Added:
trunk/openlayers/tests/owls.xml
Modified:
trunk/openlayers/lib/OpenLayers/Layer/GML.js
trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
trunk/openlayers/lib/OpenLayers/Layer/Text.js
trunk/openlayers/lib/OpenLayers/Layer/WFS.js
trunk/openlayers/lib/OpenLayers/Tile/WFS.js
trunk/openlayers/tests/Layer/test_GML.html
trunk/openlayers/tests/Layer/test_GeoRSS.html
trunk/openlayers/tests/Layer/test_Text.html
Log:
Add 'loadstart' and 'loadend' events to some of our exciting layers like WFS, GML, GeoRSS, and Text. tests to back it up. (Closes #808)
Modified: trunk/openlayers/lib/OpenLayers/Layer/GML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/GML.js 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/lib/OpenLayers/Layer/GML.js 2007-09-13 01:23:06 UTC (rev 4252)
@@ -81,6 +81,7 @@
// 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 @@
var gml = this.format ? new this.format() : new OpenLayers.Format.GML();
this.addFeatures(gml.read(doc));
+ this.events.triggerEvent("loadend");
},
/**
@@ -125,6 +127,7 @@
*/
requestFailure: function(request) {
alert("Error in loading GML file "+this.url);
+ this.events.triggerEvent("loadend");
},
CLASS_NAME: "OpenLayers.Layer.GML"
Modified: trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js 2007-09-13 01:23:06 UTC (rev 4252)
@@ -67,6 +67,7 @@
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 @@
marker.events.register('click', feature, this.markerClick);
this.addMarker(marker);
}
+ this.events.triggerEvent("loadend");
},
/**
Modified: trunk/openlayers/lib/OpenLayers/Layer/Text.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Text.js 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/lib/OpenLayers/Layer/Text.js 2007-09-13 01:23:06 UTC (rev 4252)
@@ -47,7 +47,14 @@
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 @@
}
}
}
+ this.events.triggerEvent("loadend");
},
/**
Modified: trunk/openlayers/lib/OpenLayers/Layer/WFS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/WFS.js 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/lib/OpenLayers/Layer/WFS.js 2007-09-13 01:23:06 UTC (rev 4252)
@@ -23,6 +23,12 @@
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
* buffer)
@@ -234,6 +240,7 @@
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 @@
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 @@
}
},
+ /**
+ * 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.
Modified: trunk/openlayers/lib/OpenLayers/Tile/WFS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Tile/WFS.js 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/lib/OpenLayers/Tile/WFS.js 2007-09-13 01:23:06 UTC (rev 4252)
@@ -75,6 +75,13 @@
*/
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 @@
this.addResults(resultFeatures);
}
}
+ if (this.events) {
+ this.events.triggerEvent("loadend");
+ }
},
/**
Modified: trunk/openlayers/tests/Layer/test_GML.html
===================================================================
--- trunk/openlayers/tests/Layer/test_GML.html 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/tests/Layer/test_GML.html 2007-09-13 01:23:06 UTC (rev 4252)
@@ -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");
+ });
+
+ }
</script>
</head>
<body>
Modified: trunk/openlayers/tests/Layer/test_GeoRSS.html
===================================================================
--- trunk/openlayers/tests/Layer/test_GeoRSS.html 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/tests/Layer/test_GeoRSS.html 2007-09-13 01:23:06 UTC (rev 4252)
@@ -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': '<xml xmlns="http://example.com"><title> </title></xml>'
+ });
+ 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);
Modified: trunk/openlayers/tests/Layer/test_Text.html
===================================================================
--- trunk/openlayers/tests/Layer/test_Text.html 2007-09-12 20:48:28 UTC (rev 4251)
+++ trunk/openlayers/tests/Layer/test_Text.html 2007-09-13 01:23:06 UTC (rev 4252)
@@ -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 );
Added: trunk/openlayers/tests/owls.xml
===================================================================
--- trunk/openlayers/tests/owls.xml (rev 0)
+++ trunk/openlayers/tests/owls.xml 2007-09-13 01:23:06 UTC (rev 4252)
@@ -0,0 +1,156 @@
+<?xml version='1.0' encoding="ISO-8859-1" ?>
+<wfs:FeatureCollection
+ xmlns:bsc="http://www.bsc-eoc.org/bsc"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd
+ http://www.bsc-eoc.org/bsc http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=OWLS&OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-89.817223,45.005555 -74.755001,51.701388</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <gml:featureMember><bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-79.771668,45.891110 -79.771668,45.891110</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-79.771668,45.891110</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-83.755834,46.365277 -83.755834,46.365277</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:owlname>owl</bsc:owlname>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-83.755834,46.365277</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-83.808612,46.175277 -83.808612,46.175277</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-83.808612,46.175277</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-84.111112,46.309166 -84.111112,46.309166</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-84.111112,46.309166</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-83.678612,46.821110 -83.678612,46.821110</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-83.678612,46.821110</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-83.664445,46.518888 -83.664445,46.518888</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-83.664445,46.518888</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-80.613334,46.730277 -80.613334,46.730277</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-80.613334,46.730277</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-79.676946,45.428054 -79.676946,45.428054</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-79.676946,45.428054</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-83.853056,46.236944 -83.853056,46.236944</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-83.853056,46.236944</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+ <gml:featureMember>
+ <bsc:OWLS>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:4326">
+ <gml:coordinates>-82.289167,45.896388 -82.289167,45.896388</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <bsc:msGeometry>
+ <gml:Point srsName="EPSG:4326">
+ <gml:coordinates>-82.289167,45.896388</gml:coordinates>
+ </gml:Point>
+ </bsc:msGeometry>
+ </bsc:OWLS>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
More information about the Commits
mailing list