diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index b929a58e27..851f790b99 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -18,6 +18,15 @@ OpenLayers.Layer.prototype = { /** @type DOMElement */ div: null, + /** supported application event types + * + * @type Array */ + EVENT_TYPES: [ + "loadstart", "loadend", "loadcancel"], + + /** @type OpenLayers.Events */ + events: null, + /** This variable is set when the layer is added to the map, via the * accessor function setMap() * @@ -121,6 +130,8 @@ OpenLayers.Layer.prototype = { this.div.style.height = "100%"; this.div.id = this.id; } + + this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); }, /** @@ -135,6 +146,7 @@ OpenLayers.Layer.prototype = { this.name = null; this.div = null; this.options = null; + this.events = null; }, /** diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 92efa46ff7..f9d528b9d9 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -30,7 +30,10 @@ OpenLayers.Layer.WMS.Untiled.prototype = /** @type OpenLayers.Tile.Image */ tile: null, - + + /** did the image finish loading before a new draw was initiated? + * @type Boolean */ + doneLoading: false, /** * @constructor @@ -108,6 +111,10 @@ OpenLayers.Layer.WMS.Untiled.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + if (!this.doneLoading) { + this.events.triggerEvent("loadcancel"); + this.doneLoading = true; + } OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments); if (bounds == null) { @@ -155,10 +162,18 @@ OpenLayers.Layer.WMS.Untiled.prototype = this.tile = null; } + this.events.triggerEvent("loadstart"); + this.doneLoading = false; if (!this.tile) { this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds, url, tileSize); this.tile.draw(); + var onload = function() { + this.doneLoading = true; + this.events.triggerEvent("loadend"); + } + OpenLayers.Event.observe(this.tile.imgDiv, 'load', + onload.bindAsEventListener(this)); } else { this.tile.moveTo(tileBounds, pos); }