Remove error tiles after loading is finished

This commit is contained in:
Andreas Hocevar
2017-06-26 16:15:36 +02:00
parent c299bfcd0f
commit 533ca8b9fe
+23 -16
View File
@@ -205,7 +205,6 @@ ol.VectorImageTile.prototype.getTile = function(tileKey) {
*/ */
ol.VectorImageTile.prototype.load = function() { ol.VectorImageTile.prototype.load = function() {
var leftToLoad = 0; var leftToLoad = 0;
var errors = false;
if (this.state == ol.TileState.IDLE) { if (this.state == ol.TileState.IDLE) {
this.setState(ol.TileState.LOADING); this.setState(ol.TileState.LOADING);
} }
@@ -215,10 +214,6 @@ ol.VectorImageTile.prototype.load = function() {
if (sourceTile.state == ol.TileState.IDLE) { if (sourceTile.state == ol.TileState.IDLE) {
sourceTile.setLoader(this.loader_); sourceTile.setLoader(this.loader_);
sourceTile.load(); sourceTile.load();
} else if (sourceTile.state == ol.TileState.ERROR) {
errors = true;
} else if (sourceTile.state == ol.TileState.EMPTY) {
ol.array.remove(this.tileKeys, sourceTileKey);
} }
if (sourceTile.state == ol.TileState.LOADING) { if (sourceTile.state == ol.TileState.LOADING) {
var key = ol.events.listen(sourceTile, ol.events.EventType.CHANGE, function(e) { var key = ol.events.listen(sourceTile, ol.events.EventType.CHANGE, function(e) {
@@ -228,13 +223,8 @@ ol.VectorImageTile.prototype.load = function() {
--leftToLoad; --leftToLoad;
ol.events.unlistenByKey(key); ol.events.unlistenByKey(key);
ol.array.remove(this.loadListenerKeys_, key); ol.array.remove(this.loadListenerKeys_, key);
if (state == ol.TileState.ERROR) {
ol.array.remove(this.tileKeys, sourceTileKey);
errors = true;
}
if (leftToLoad == 0) { if (leftToLoad == 0) {
this.setState(this.tileKeys.length > 0 ? this.finishLoading_();
ol.TileState.LOADED : ol.TileState.ERROR);
} }
} }
}.bind(this)); }.bind(this));
@@ -244,15 +234,32 @@ ol.VectorImageTile.prototype.load = function() {
}.bind(this)); }.bind(this));
} }
if (leftToLoad == 0) { if (leftToLoad == 0) {
setTimeout(function() { setTimeout(this.finishLoading_.bind(this), 0);
this.setState(this.tileKeys.length > 0 ?
ol.TileState.LOADED :
(errors ? ol.TileState.ERROR : ol.TileState.EMPTY));
}.bind(this), 0);
} }
}; };
/**
* @private
*/
ol.VectorImageTile.prototype.finishLoading_ = function() {
var errors = false;
var tile;
for (var i = this.tileKeys.length - 1; i >= 0; --i) {
tile = this.getTile(this.tileKeys[i]);
if (tile.getState() == ol.TileState.ERROR) {
errors = true;
}
if (tile.getState() != ol.TileState.LOADED) {
this.tileKeys.splice(i, 1);
}
}
this.setState(this.tileKeys.length > 0 ?
ol.TileState.LOADED :
(errors ? ol.TileState.ERROR : ol.TileState.EMPTY));
};
/** /**
* Sets the loader for a tile. * Sets the loader for a tile.
* @param {ol.VectorTile} tile Vector tile. * @param {ol.VectorTile} tile Vector tile.