Do not abort and dispose of tiles
This commit is contained in:
@@ -144,13 +144,6 @@ class Tile extends EventTarget {
|
||||
this.dispatchEvent(EventType.CHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
disposeInternal() {
|
||||
this.setState(TileState.ABORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} Key.
|
||||
*/
|
||||
|
||||
@@ -6,15 +6,6 @@ import {fromKey, getKey} from './tilecoord.js';
|
||||
|
||||
class TileCache extends LRUCache {
|
||||
|
||||
/**
|
||||
* @param {number=} opt_highWaterMark High water mark.
|
||||
*/
|
||||
constructor(opt_highWaterMark) {
|
||||
|
||||
super(opt_highWaterMark);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object<string, import("./TileRange.js").default>} usedTiles Used tiles.
|
||||
*/
|
||||
@@ -24,7 +15,7 @@ class TileCache extends LRUCache {
|
||||
if (tile.getKey() in usedTiles) {
|
||||
break;
|
||||
} else {
|
||||
this.pop().dispose();
|
||||
this.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +33,6 @@ class TileCache extends LRUCache {
|
||||
this.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.dispose();
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ class TileQueue extends PriorityQueue {
|
||||
handleTileChange(event) {
|
||||
const tile = /** @type {import("./Tile.js").default} */ (event.target);
|
||||
const state = tile.getState();
|
||||
if (tile.hifi && state === TileState.LOADED || state === TileState.ERROR ||
|
||||
state === TileState.EMPTY || state === TileState.ABORT) {
|
||||
if (tile.hifi && state === TileState.LOADED || state === TileState.ERROR || state === TileState.EMPTY) {
|
||||
tile.removeEventListener(EventType.CHANGE, this.boundHandleTileChange_);
|
||||
const tileKey = tile.getKey();
|
||||
if (tileKey in this.tilesLoadingKeys_) {
|
||||
@@ -102,27 +101,19 @@ class TileQueue extends PriorityQueue {
|
||||
*/
|
||||
loadMoreTiles(maxTotalLoading, maxNewLoads) {
|
||||
let newLoads = 0;
|
||||
let abortedTiles = false;
|
||||
let state, tile, tileKey;
|
||||
while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
|
||||
this.getCount() > 0) {
|
||||
tile = /** @type {import("./Tile.js").default} */ (this.dequeue()[0]);
|
||||
tileKey = tile.getKey();
|
||||
state = tile.getState();
|
||||
if (state === TileState.ABORT) {
|
||||
abortedTiles = true;
|
||||
} else if (state === TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) {
|
||||
if (state === TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) {
|
||||
this.tilesLoadingKeys_[tileKey] = true;
|
||||
++this.tilesLoading_;
|
||||
++newLoads;
|
||||
tile.load();
|
||||
}
|
||||
}
|
||||
if (newLoads === 0 && abortedTiles) {
|
||||
// Do not stop the render loop when all wanted tiles were aborted due to
|
||||
// a small, saturated tile cache.
|
||||
this.tileChangeCallback_();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,5 @@ export default {
|
||||
* @type {number}
|
||||
*/
|
||||
ERROR: 3,
|
||||
EMPTY: 4,
|
||||
ABORT: 5
|
||||
EMPTY: 4
|
||||
};
|
||||
|
||||
@@ -117,8 +117,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
let render;
|
||||
const tileUid = getUid(tile);
|
||||
const state = tile.getState();
|
||||
if (((state === TileState.LOADED && tile.hifi) ||
|
||||
state === TileState.ERROR || state === TileState.ABORT) &&
|
||||
if (((state === TileState.LOADED && tile.hifi) || state === TileState.ERROR) &&
|
||||
tileUid in this.tileListenerKeys_) {
|
||||
unlistenByKey(this.tileListenerKeys_[tileUid]);
|
||||
delete this.tileListenerKeys_[tileUid];
|
||||
@@ -468,9 +467,6 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
const clipZs = [];
|
||||
for (let i = tiles.length - 1; i >= 0; --i) {
|
||||
const tile = /** @type {import("../../VectorRenderTile.js").default} */ (tiles[i]);
|
||||
if (tile.getState() == TileState.ABORT) {
|
||||
continue;
|
||||
}
|
||||
const tileCoord = tile.tileCoord;
|
||||
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
||||
const worldOffset = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent)[0] - tileExtent[0];
|
||||
|
||||
@@ -139,7 +139,7 @@ class UrlTile extends TileSource {
|
||||
} else if (uid in this.tileLoadingKeys_) {
|
||||
delete this.tileLoadingKeys_[uid];
|
||||
type = tileState == TileState.ERROR ? TileEventType.TILELOADERROR :
|
||||
(tileState == TileState.LOADED || tileState == TileState.ABORT) ?
|
||||
tileState == TileState.LOADED ?
|
||||
TileEventType.TILELOADEND : undefined;
|
||||
}
|
||||
if (type != undefined) {
|
||||
|
||||
@@ -83,21 +83,4 @@ describe('ol.ImageTile', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('dispose', function() {
|
||||
|
||||
it('sets image src to a blank image data uri', function() {
|
||||
const tileCoord = [0, 0, 0];
|
||||
const state = TileState.IDLE;
|
||||
const src = 'spec/ol/data/osm-0-0-0.png';
|
||||
const tileLoadFunction = defaultImageLoadFunction;
|
||||
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
|
||||
tile.load();
|
||||
expect(tile.getState()).to.be(TileState.LOADING);
|
||||
tile.dispose();
|
||||
expect(tile.getState()).to.be(TileState.ABORT);
|
||||
expect(tile.getImage().src).to.be(ImageTile.blankImageUrl);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -218,19 +218,6 @@ describe('ol.source.TileImage', function() {
|
||||
const tile = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
tile.load();
|
||||
});
|
||||
|
||||
it('dispatches tileloadend events for aborted tiles', function() {
|
||||
source.setTileLoadFunction(function() {});
|
||||
const startSpy = sinon.spy();
|
||||
source.on('tileloadstart', startSpy);
|
||||
const endSpy = sinon.spy();
|
||||
source.on('tileloadend', endSpy);
|
||||
const tile = source.getTile(0, 0, 0, 1, getProjection('EPSG:3857'));
|
||||
tile.load();
|
||||
tile.dispose();
|
||||
expect(startSpy.callCount).to.be(1);
|
||||
expect(endSpy.callCount).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -32,8 +32,6 @@ describe('ol.TileCache', function() {
|
||||
'2/1/0',
|
||||
'2/0/0'
|
||||
]);
|
||||
|
||||
expect(tiles[0].dispose.calledOnce).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,20 +89,6 @@ describe('ol.TileQueue', function() {
|
||||
|
||||
});
|
||||
|
||||
it('calls #tileChangeCallback_ when all wanted tiles are aborted', function() {
|
||||
const tileChangeCallback = sinon.spy();
|
||||
const queue = new TileQueue(noop, tileChangeCallback);
|
||||
const numTiles = 20;
|
||||
for (let i = 0; i < numTiles; ++i) {
|
||||
const tile = createImageTile();
|
||||
tile.state = TileState.ABORT;
|
||||
queue.enqueue([tile]);
|
||||
}
|
||||
const maxLoading = numTiles / 2;
|
||||
queue.loadMoreTiles(maxLoading, maxLoading);
|
||||
expect(tileChangeCallback.callCount).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('heapify', function() {
|
||||
@@ -144,7 +130,7 @@ describe('ol.TileQueue', function() {
|
||||
describe('tile change event', function() {
|
||||
const noop = function() {};
|
||||
|
||||
it('abort queued tiles', function() {
|
||||
it('loaded tiles', function() {
|
||||
const tq = new TileQueue(noop, noop);
|
||||
const tile = createImageTile();
|
||||
expect(tile.hasListener('change')).to.be(false);
|
||||
@@ -152,12 +138,11 @@ describe('ol.TileQueue', function() {
|
||||
tq.enqueue([tile]);
|
||||
expect(tile.hasListener('change')).to.be(true);
|
||||
|
||||
tile.dispose();
|
||||
tile.setState(TileState.LOADED);
|
||||
expect(tile.hasListener('change')).to.be(false);
|
||||
expect(tile.getState()).to.eql(5); // ABORT
|
||||
});
|
||||
|
||||
it('abort loading tiles', function() {
|
||||
it('error tiles', function() {
|
||||
const tq = new TileQueue(noop, noop);
|
||||
const tile = createImageTile(noop);
|
||||
|
||||
@@ -166,10 +151,9 @@ describe('ol.TileQueue', function() {
|
||||
expect(tq.getTilesLoading()).to.eql(1);
|
||||
expect(tile.getState()).to.eql(1); // LOADING
|
||||
|
||||
tile.dispose();
|
||||
tile.setState(TileState.ERROR);
|
||||
expect(tq.getTilesLoading()).to.eql(0);
|
||||
expect(tile.hasListener('change')).to.be(false);
|
||||
expect(tile.getState()).to.eql(5); // ABORT
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import TileState from '../../../src/ol/TileState.js';
|
||||
import {defaultLoadFunction} from '../../../src/ol/source/VectorTile.js';
|
||||
import VectorTileSource from '../../../src/ol/source/VectorTile.js';
|
||||
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
|
||||
import {listen, unlistenByKey} from '../../../src/ol/events.js';
|
||||
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
||||
import {createXYZ} from '../../../src/ol/tilegrid.js';
|
||||
import TileGrid from '../../../src/ol/tilegrid/TileGrid.js';
|
||||
import EventType from '../../../src/ol/events/EventType.js';
|
||||
|
||||
@@ -95,52 +94,4 @@ describe('ol.VectorRenderTile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('#dispose() while loading', function() {
|
||||
const source = new VectorTileSource({
|
||||
format: new GeoJSON(),
|
||||
url: 'spec/ol/data/point.json',
|
||||
tileGrid: createXYZ()
|
||||
});
|
||||
source.getTileGridForProjection = function() {
|
||||
return createXYZ({tileSize: 512});
|
||||
};
|
||||
const tile = source.getTile(0, 0, 0, 1, source.getProjection());
|
||||
|
||||
tile.load();
|
||||
expect(tile.getState()).to.be(TileState.LOADING);
|
||||
tile.dispose();
|
||||
expect(source.sourceTilesByTileKey_[tile.getKey()]).to.be(undefined);
|
||||
expect(tile.getState()).to.be(TileState.ABORT);
|
||||
});
|
||||
|
||||
it('#dispose() when source tiles are loaded', function(done) {
|
||||
const source = new VectorTileSource({
|
||||
format: new GeoJSON(),
|
||||
url: 'spec/ol/data/point.json?{z}/{x}/{y}',
|
||||
tileGrid: createXYZ()
|
||||
});
|
||||
source.getTileGridForProjection = function() {
|
||||
return createXYZ({tileSize: 512});
|
||||
};
|
||||
const tile = source.getTile(0, 0, 0, 1, source.getProjection());
|
||||
|
||||
tile.load();
|
||||
listenOnce(tile, 'change', function() {
|
||||
expect(tile.getState()).to.be(TileState.LOADED);
|
||||
expect(tile.loadingSourceTiles).to.be(0);
|
||||
const sourceTiles = source.getSourceTiles(1, source.getProjection(), tile);
|
||||
expect(sourceTiles.length).to.be(4);
|
||||
for (let i = 0, ii = sourceTiles.length; i < ii; ++i) {
|
||||
expect(sourceTiles[i].consumers).to.be(1);
|
||||
}
|
||||
tile.dispose();
|
||||
expect(tile.getState()).to.be(TileState.ABORT);
|
||||
for (let i = 0, ii = sourceTiles.length; i < ii; ++i) {
|
||||
expect(sourceTiles[i].consumers).to.be(0);
|
||||
expect(sourceTiles[i].getState()).to.be(TileState.ABORT);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user