[OpenLayers-Commits] r3600 - in sandbox/euzuro/untiled3/lib/OpenLayers: . Tile
commits at openlayers.org
commits at openlayers.org
Thu Jul 5 16:14:31 EDT 2007
Author: euzuro
Date: 2007-07-05 16:14:28 -0400 (Thu, 05 Jul 2007)
New Revision: 3600
Modified:
sandbox/euzuro/untiled3/lib/OpenLayers/Tile.js
sandbox/euzuro/untiled3/lib/OpenLayers/Tile/Image.js
Log:
Add events to Tile for load start, cancel, and end. Add hooks in the image tile to trigger them.
Modified: sandbox/euzuro/untiled3/lib/OpenLayers/Tile/Image.js
===================================================================
--- sandbox/euzuro/untiled3/lib/OpenLayers/Tile/Image.js 2007-07-05 20:02:29 UTC (rev 3599)
+++ sandbox/euzuro/untiled3/lib/OpenLayers/Tile/Image.js 2007-07-05 20:14:28 UTC (rev 3600)
@@ -90,12 +90,25 @@
* {Boolean} Always returns true.
*/
draw:function() {
+
+ //if we're already loading, we need to send a 'loadcancel' event,
+ // since the 'loadend' will not get fired (since the image will
+ // not load. This keeps start/finish pairings even.
+ //
+ if (this.loading) {
+ this.events.triggerEvent("loadcancel");
+ }
+
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
this.bounds = this.getBoundsFromBaseLayer(this.position);
}
if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
return false;
}
+
+ this.loading = true;
+ this.events.triggerEvent("loadstart");
+
if (this.imgDiv == null) {
this.initImgDiv();
}
@@ -202,6 +215,15 @@
// we need this reference to check back the viewRequestID
this.imgDiv.map = this.layer.map;
+ //bind a listener to the onload of the image div so that we
+ // can register when a tile has finished loading.
+ var onload = function() {
+ this.loading = false;
+ this.events.triggerEvent("loadend");
+ }
+ OpenLayers.Event.observe(this.imgDiv, 'load',
+ onload.bindAsEventListener(this));
+
},
/**
Modified: sandbox/euzuro/untiled3/lib/OpenLayers/Tile.js
===================================================================
--- sandbox/euzuro/untiled3/lib/OpenLayers/Tile.js 2007-07-05 20:02:29 UTC (rev 3599)
+++ sandbox/euzuro/untiled3/lib/OpenLayers/Tile.js 2007-07-05 20:14:28 UTC (rev 3600)
@@ -21,6 +21,12 @@
OpenLayers.Tile.prototype = {
/**
+ * Constant: EVENT_TYPES
+ * {Array(String)} Supported application event types
+ */
+ EVENT_TYPES: [ "loadstart", "loadend", "loadcancel"],
+
+ /**
* Property: id
* {String} null
*/
@@ -66,6 +72,12 @@
*/
drawn: false,
+ /**
+ * Property: isLoading
+ * {Boolean} Is the tile loading?
+ */
+ isLoading: false,
+
/** TBD 3.0 -- remove 'url' from the list of parameters to the constructor.
* there is no need for the base tile class to have a url.
*
@@ -88,6 +100,8 @@
//give the tile a unique id based on its BBOX.
this.id = OpenLayers.Util.createUniqueID("Tile_");
+
+ this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
},
/**
More information about the Commits
mailing list