Merge pull request #7242 from ahocevar/source-error-not-empty
Use EMPTY and LOADED state properly on ol.VectorImageTile
This commit is contained in:
@@ -263,17 +263,23 @@ ol.VectorImageTile.prototype.load = function() {
|
||||
*/
|
||||
ol.VectorImageTile.prototype.finishLoading_ = function() {
|
||||
var loaded = this.tileKeys.length;
|
||||
var empty = 0;
|
||||
for (var i = loaded - 1; i >= 0; --i) {
|
||||
var state = this.getTile(this.tileKeys[i]).getState();
|
||||
if (state != ol.TileState.LOADED) {
|
||||
--loaded;
|
||||
}
|
||||
if (state == ol.TileState.EMPTY) {
|
||||
++empty;
|
||||
}
|
||||
}
|
||||
if (loaded == this.tileKeys.length) {
|
||||
this.loadListenerKeys_.forEach(ol.events.unlistenByKey);
|
||||
this.loadListenerKeys_.length = 0;
|
||||
this.setState(ol.TileState.LOADED);
|
||||
} else {
|
||||
this.setState(empty == this.tileKeys.length ? ol.TileState.EMPTY : ol.TileState.ERROR);
|
||||
}
|
||||
this.setState(loaded > 0 ? ol.TileState.LOADED : ol.TileState.EMPTY);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ describe('ol.rendering.layer.VectorTile', function() {
|
||||
source = new ol.source.VectorTile({
|
||||
format: new ol.format.MVT(),
|
||||
tileGrid: ol.tilegrid.createXYZ(),
|
||||
tilePixelRatio: 16,
|
||||
url: 'rendering/ol/data/tiles/mvt/{z}-{x}-{y}.vector.pbf'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,23 +32,6 @@ describe('ol.VectorImageTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('sets LOADED state when source tiles fail to load', function(done) {
|
||||
var format = new ol.format.GeoJSON();
|
||||
var url = 'spec/ol/data/unavailable.json';
|
||||
var tile = new ol.VectorImageTile([0, 0, -1], 0, url, format,
|
||||
ol.VectorImageTile.defaultLoadFunction, [0, 0, -1], function() {
|
||||
return url;
|
||||
}, ol.tilegrid.createXYZ(), ol.tilegrid.createXYZ(), {},
|
||||
1, ol.proj.get('EPSG:3857'), ol.VectorTile, function() {});
|
||||
|
||||
tile.load();
|
||||
|
||||
ol.events.listen(tile, 'change', function(e) {
|
||||
expect(tile.getState()).to.be(ol.TileState.EMPTY);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sets LOADED state when previously failed source tiles are loaded', function(done) {
|
||||
var format = new ol.format.GeoJSON();
|
||||
var url = 'spec/ol/data/unavailable.json';
|
||||
@@ -66,7 +49,7 @@ describe('ol.VectorImageTile', function() {
|
||||
var calls = 0;
|
||||
ol.events.listen(tile, 'change', function(e) {
|
||||
++calls;
|
||||
expect(tile.getState()).to.be(calls == 2 ? ol.TileState.LOADED : ol.TileState.EMPTY);
|
||||
expect(tile.getState()).to.be(calls == 2 ? ol.TileState.LOADED : ol.TileState.ERROR);
|
||||
if (calls == 2) {
|
||||
done();
|
||||
} else {
|
||||
@@ -77,7 +60,7 @@ describe('ol.VectorImageTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('sets EMPTY state when all source tiles fail to load', function(done) {
|
||||
it('sets ERROR state when source tiles fail to load', function(done) {
|
||||
var format = new ol.format.GeoJSON();
|
||||
var url = 'spec/ol/data/unavailable.json';
|
||||
var tile = new ol.VectorImageTile([0, 0, -1], 0, url, format,
|
||||
@@ -89,7 +72,7 @@ describe('ol.VectorImageTile', function() {
|
||||
tile.load();
|
||||
|
||||
ol.events.listen(tile, 'change', function(e) {
|
||||
expect(tile.getState()).to.be(ol.TileState.EMPTY);
|
||||
expect(tile.getState()).to.be(ol.TileState.ERROR);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user