Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load erroneous image in ol.Image#load and ol.ImageTile#load #5270

Merged
merged 2 commits into from Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/ol/image.js
Expand Up @@ -122,10 +122,13 @@ ol.Image.prototype.handleImageLoad_ = function() {


/**
* Load not yet loaded URI.
* Load the image or retry if loading previously failed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a note that 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note added

* 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_,
Expand Down
7 changes: 5 additions & 2 deletions src/ol/imagetile.js
Expand Up @@ -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_,
Expand Down
5 changes: 4 additions & 1 deletion src/ol/tile.js
Expand Up @@ -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;
Binary file added test/spec/ol/data/osm-0-0-0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions 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');