Test that data tiles can be loaded after error
This commit is contained in:
@@ -75,26 +75,24 @@ class DataTile extends Tile {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
load() {
|
load() {
|
||||||
if (this.state == TileState.ERROR) {
|
if (this.state !== TileState.IDLE && this.state !== TileState.ERROR) {
|
||||||
this.state = TileState.IDLE;
|
return;
|
||||||
}
|
}
|
||||||
if (this.state == TileState.IDLE) {
|
this.state = TileState.LOADING;
|
||||||
this.state = TileState.LOADING;
|
this.changed();
|
||||||
this.changed();
|
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
this.loader_()
|
this.loader_()
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
self.data_ = data;
|
self.data_ = data;
|
||||||
self.state = TileState.LOADED;
|
self.state = TileState.LOADED;
|
||||||
self.changed();
|
self.changed();
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
self.error_ = error;
|
self.error_ = error;
|
||||||
self.state = TileState.ERROR;
|
self.state = TileState.ERROR;
|
||||||
self.changed();
|
self.changed();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import DataTile from '../../../../src/ol/DataTile.js';
|
import DataTile from '../../../../src/ol/DataTile.js';
|
||||||
import TileState from '../../../../src/ol/TileState.js';
|
import TileState from '../../../../src/ol/TileState.js';
|
||||||
|
import {listenOnce} from '../../../../src/ol/events.js';
|
||||||
|
|
||||||
describe('ol.DataTile', function () {
|
describe('ol/DataTile', function () {
|
||||||
/** @type {Promise<import('../../../../src/ol/DataTile.js').Data} */
|
/** @type {Promise<import('../../../../src/ol/DataTile.js').Data} */
|
||||||
let loader;
|
let loader;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -42,10 +43,26 @@ describe('ol.DataTile', function () {
|
|||||||
expect(tile.getState()).to.be(TileState.IDLE);
|
expect(tile.getState()).to.be(TileState.IDLE);
|
||||||
tile.load();
|
tile.load();
|
||||||
expect(tile.getState()).to.be(TileState.LOADING);
|
expect(tile.getState()).to.be(TileState.LOADING);
|
||||||
setTimeout(() => {
|
listenOnce(tile, 'change', () => {
|
||||||
expect(tile.getState()).to.be(TileState.LOADED);
|
expect(tile.getState()).to.be(TileState.LOADED);
|
||||||
done();
|
done();
|
||||||
}, 16);
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reloads tiles in an error state', function (done) {
|
||||||
|
const tileCoord = [0, 0, 0];
|
||||||
|
const tile = new DataTile({
|
||||||
|
tileCoord: tileCoord,
|
||||||
|
loader: loader,
|
||||||
|
});
|
||||||
|
tile.state = TileState.ERROR;
|
||||||
|
|
||||||
|
tile.load();
|
||||||
|
expect(tile.getState()).to.be(TileState.LOADING);
|
||||||
|
listenOnce(tile, 'change', () => {
|
||||||
|
expect(tile.getState()).to.be(TileState.LOADED);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user