Merge pull request #6832 from oterral/fix_5269

Force state of error tiles when usInterimTilesOnError is false
This commit is contained in:
Frédéric Junod
2017-05-24 15:27:12 +02:00
committed by GitHub
6 changed files with 39 additions and 18 deletions

View File

@@ -94,6 +94,7 @@ ol.ImageTile.prototype.getKey = function() {
*/
ol.ImageTile.prototype.handleImageError_ = function() {
this.state = ol.TileState.ERROR;
this.image_ = ol.ImageTile.blankImage;
this.unlistenImage_();
this.changed();
};
@@ -143,3 +144,11 @@ ol.ImageTile.prototype.unlistenImage_ = function() {
this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
this.imageListenerKeys_ = null;
};
/**
* A blank image.
* @type {Image}
*/
ol.ImageTile.blankImage = new Image();
ol.ImageTile.blankImage.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';

View File

@@ -144,6 +144,10 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(frameState, layer
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
// When useInterimTilesOnError is false, we consider the error tile as loaded.
if (tile.getState() == ol.TileState.ERROR && !this.getLayer().getUseInterimTilesOnError()) {
tile.setState(ol.TileState.LOADED);
}
if (!this.isDrawableTile_(tile)) {
tile = tile.getInterimTile();
}

View File

@@ -145,6 +145,13 @@ ol.Tile.prototype.getState = function() {
return this.state;
};
/**
* @param {ol.TileState} state State.
*/
ol.Tile.prototype.setState = function(state) {
this.state = state;
this.changed();
};
/**
* Load the image or retry if loading previously failed.

View File

@@ -253,15 +253,6 @@ ol.VectorImageTile.prototype.load = function() {
};
/**
* @param {ol.TileState} tileState Tile state.
*/
ol.VectorImageTile.prototype.setState = function(tileState) {
this.state = tileState;
this.changed();
};
/**
* Sets the loader for a tile.
* @param {ol.VectorTile} tile Vector tile.

View File

@@ -178,15 +178,6 @@ ol.VectorTile.prototype.setReplayGroup = function(key, replayGroup) {
};
/**
* @param {ol.TileState} tileState Tile state.
*/
ol.VectorTile.prototype.setState = function(tileState) {
this.state = tileState;
this.changed();
};
/**
* Set the feature loader for reading this tile's features.
* @param {ol.FeatureLoader} loader Feature loader.

View File

@@ -61,6 +61,25 @@ describe('ol.ImageTile', function() {
tile.load();
});
it('loads an empty image on error ', function(done) {
var tileCoord = [0, 0, 0];
var state = ol.TileState.IDLE;
var src = 'spec/ol/data/osm-0-0-99.png';
var tileLoadFunction = ol.source.Image.defaultImageLoadFunction;
var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction);
ol.events.listen(tile, ol.events.EventType.CHANGE, function(event) {
var state = tile.getState();
if (state == ol.TileState.ERROR) {
expect(state).to.be(ol.TileState.ERROR);
expect(tile.image_).to.be(ol.ImageTile.blankImage);
done();
}
});
tile.load();
});
});
});