diff --git a/src/ol/image.js b/src/ol/image.js index 303bd05f73..236b887afd 100644 --- a/src/ol/image.js +++ b/src/ol/image.js @@ -122,10 +122,13 @@ ol.Image.prototype.handleImageLoad_ = function() { /** - * Load not yet loaded URI. + * Load the image or retry if loading previously failed. + * Loading is taken care of by the tile queue, and calling this method is + * only needed for preloading or for reloading in case of an error. + * @api */ ol.Image.prototype.load = function() { - if (this.state == ol.ImageState.IDLE) { + if (this.state == ol.ImageState.IDLE || this.state == ol.ImageState.ERROR) { this.state = ol.ImageState.LOADING; this.changed(); goog.asserts.assert(!this.imageListenerKeys_, diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index 5d423ee5af..700cb083eb 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -137,10 +137,13 @@ ol.ImageTile.prototype.handleImageLoad_ = function() { /** - * Load not yet loaded URI. + * Load the image or retry if loading previously failed. + * Loading is taken care of by the tile queue, and calling this method is + * only needed for preloading or for reloading in case of an error. + * @api */ ol.ImageTile.prototype.load = function() { - if (this.state == ol.TileState.IDLE) { + if (this.state == ol.TileState.IDLE || this.state == ol.TileState.ERROR) { this.state = ol.TileState.LOADING; this.changed(); goog.asserts.assert(!this.imageListenerKeys_, diff --git a/src/ol/tile.js b/src/ol/tile.js index cffb053a24..b531c38a65 100644 --- a/src/ol/tile.js +++ b/src/ol/tile.js @@ -107,6 +107,9 @@ ol.Tile.prototype.getState = function() { /** - * FIXME empty description for jsdoc + * Load the image or retry if loading previously failed. + * Loading is taken care of by the tile queue, and calling this method is + * only needed for preloading or for reloading in case of an error. + * @api */ ol.Tile.prototype.load = goog.abstractMethod; diff --git a/test/spec/ol/data/osm-0-0-0.png b/test/spec/ol/data/osm-0-0-0.png new file mode 100644 index 0000000000..885def1f00 Binary files /dev/null and b/test/spec/ol/data/osm-0-0-0.png differ diff --git a/test/spec/ol/imagetile.test.js b/test/spec/ol/imagetile.test.js new file mode 100644 index 0000000000..cb01bdb1a7 --- /dev/null +++ b/test/spec/ol/imagetile.test.js @@ -0,0 +1,65 @@ +goog.provide('ol.test.ImageTile'); + +describe('ol.ImageTile', function() { + + describe('#load()', function() { + + it('can load idle tile', function(done) { + var tileCoord = [0, 0, 0]; + var state = ol.TileState.IDLE; + var src = 'spec/ol/data/osm-0-0-0.png'; + var tileLoadFunction = ol.source.Image.defaultImageLoadFunction; + var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction); + + var previousState = tile.getState() + + ol.events.listen(tile, ol.events.EventType.CHANGE, function(event) { + var state = tile.getState(); + if (previousState == ol.TileState.IDLE) { + expect(state).to.be(ol.TileState.LOADING); + } else if (previousState == ol.TileState.LOADING) { + expect(state).to.be(ol.TileState.LOADED); + done(); + } else { + expect().fail(); + } + previousState = state; + }); + + tile.load(); + }); + + it('can load error tile', function(done) { + var tileCoord = [0, 0, 0]; + var state = ol.TileState.ERROR; + var src = 'spec/ol/data/osm-0-0-0.png'; + var tileLoadFunction = ol.source.Image.defaultImageLoadFunction; + var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction); + + var previousState = tile.getState() + + ol.events.listen(tile, ol.events.EventType.CHANGE, function(event) { + var state = tile.getState(); + if (previousState == ol.TileState.ERROR) { + expect(state).to.be(ol.TileState.LOADING); + } else if (previousState == ol.TileState.LOADING) { + expect(state).to.be(ol.TileState.LOADED); + done(); + } else { + expect().fail(); + } + previousState = state; + }); + + tile.load(); + }); + + }); + +}); + +goog.require('ol.events'); +goog.require('ol.events.EventType'); +goog.require('ol.source.Image'); +goog.require('ol.ImageTile'); +goog.require('ol.TileState');