Merge pull request #303 from elemoine/tile
Tile loading stops after a while when there are multiple maps
This commit is contained in:
@@ -530,7 +530,14 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
|
||||
*/
|
||||
ol.Map.prototype.handlePostRender = function() {
|
||||
this.tileQueue_.reprioritize(); // FIXME only call if needed
|
||||
this.tileQueue_.loadMoreTiles();
|
||||
var moreLoadingTiles = this.tileQueue_.loadMoreTiles();
|
||||
if (moreLoadingTiles) {
|
||||
// The tile layer renderers need to know when tiles change
|
||||
// to the LOADING state (to register the change listener
|
||||
// on the tile).
|
||||
this.requestRenderFrame();
|
||||
}
|
||||
|
||||
var postRenderFunctions = this.postRenderFunctions_;
|
||||
var i;
|
||||
for (i = 0; i < postRenderFunctions.length; ++i) {
|
||||
|
||||
@@ -158,10 +158,11 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.listenToTileChange(tile);
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADING) {
|
||||
this.listenToTileChange(tile);
|
||||
} else if (tileState == ol.TileState.LOADED) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
continue;
|
||||
|
||||
@@ -116,10 +116,11 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.listenToTileChange(tile);
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADING) {
|
||||
this.listenToTileChange(tile);
|
||||
} else if (tileState == ol.TileState.LOADED) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
continue;
|
||||
|
||||
@@ -391,10 +391,11 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.listenToTileChange(tile);
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADING) {
|
||||
this.listenToTileChange(tile);
|
||||
} else if (tileState == ol.TileState.LOADED) {
|
||||
if (mapRenderer.isTileTextureLoaded(tile)) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
|
||||
@@ -30,13 +30,6 @@ ol.Tile = function(tileCoord) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* A count incremented each time the tile is inQueue in a tile queue,
|
||||
* and decremented each time the tile is dequeued from a tile queue.
|
||||
* @type {number}
|
||||
*/
|
||||
this.inQueue = 0;
|
||||
|
||||
/**
|
||||
* @type {ol.TileCoord}
|
||||
*/
|
||||
|
||||
@@ -89,8 +89,6 @@ ol.TileQueue.prototype.dequeue_ = function() {
|
||||
}
|
||||
var tileKey = tile.getKey();
|
||||
delete this.queuedTileKeys_[tileKey];
|
||||
tile.inQueue--;
|
||||
goog.asserts.assert(tile.inQueue >= 0);
|
||||
return tile;
|
||||
};
|
||||
|
||||
@@ -112,8 +110,6 @@ ol.TileQueue.prototype.enqueue = function(tile, tileSourceKey, tileCenter) {
|
||||
this.heap_.push([priority, tile, tileSourceKey, tileCenter]);
|
||||
this.queuedTileKeys_[tileKey] = true;
|
||||
this.siftDown_(0, this.heap_.length - 1);
|
||||
tile.inQueue++;
|
||||
goog.asserts.assert(tile.inQueue > 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -172,7 +168,7 @@ ol.TileQueue.prototype.heapify_ = function() {
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
* @return {boolean} New loading tiles?
|
||||
*/
|
||||
ol.TileQueue.prototype.loadMoreTiles = function() {
|
||||
var tile;
|
||||
@@ -183,6 +179,7 @@ ol.TileQueue.prototype.loadMoreTiles = function() {
|
||||
tile.load();
|
||||
++this.tilesLoading_;
|
||||
}
|
||||
return goog.isDef(tile);
|
||||
};
|
||||
|
||||
|
||||
@@ -250,11 +247,6 @@ ol.TileQueue.prototype.reprioritize = function() {
|
||||
if (priority == ol.TileQueue.DROP) {
|
||||
tileKey = tile.getKey();
|
||||
delete this.queuedTileKeys_[tileKey];
|
||||
tile.inQueue--;
|
||||
goog.asserts.assert(tile.inQueue >= 0);
|
||||
if (tile.inQueue === 0) {
|
||||
goog.events.removeAll(tile);
|
||||
}
|
||||
} else {
|
||||
node[0] = priority;
|
||||
heap[n++] = node;
|
||||
|
||||
@@ -21,20 +21,13 @@ describe('ol.TileQueue', function() {
|
||||
}
|
||||
|
||||
function addRandomPriorityTiles(tq, num) {
|
||||
var tiles = [];
|
||||
var i, tile, priority;
|
||||
for (i = 0; i < num; i++) {
|
||||
tile = new ol.Tile();
|
||||
tile.toDrop = (i % 2 === 0) ? true : false;
|
||||
goog.events.listen(tile, goog.events.EventType.CHANGE,
|
||||
goog.nullFunction);
|
||||
priority = Math.floor(Math.random() * 100);
|
||||
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
|
||||
tq.queuedTileKeys_[tile.getKey()] = true;
|
||||
tile.inQueue++;
|
||||
tiles.push(tile);
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
|
||||
describe('heapify', function() {
|
||||
@@ -52,15 +45,16 @@ describe('ol.TileQueue', function() {
|
||||
it('does reprioritize the array', function() {
|
||||
|
||||
var tq = new ol.TileQueue(function() {});
|
||||
var tiles = addRandomPriorityTiles(tq, 100);
|
||||
addRandomPriorityTiles(tq, 100);
|
||||
|
||||
tq.heapify_();
|
||||
|
||||
// now reprioritize, changing the priority of 50 tiles and removing the
|
||||
// rest
|
||||
|
||||
tq.tilePriorityFunction_ = function(tile) {
|
||||
if (tile.toDrop) {
|
||||
var i = 0;
|
||||
tq.tilePriorityFunction_ = function() {
|
||||
if ((i++) % 2 === 0) {
|
||||
return ol.TileQueue.DROP;
|
||||
}
|
||||
return Math.floor(Math.random() * 100);
|
||||
@@ -70,23 +64,10 @@ describe('ol.TileQueue', function() {
|
||||
expect(tq.heap_.length).toEqual(50);
|
||||
expect(isHeap(tq)).toBeTruthy();
|
||||
|
||||
var i, tile;
|
||||
for (i = 0; i < tiles.length; ++i) {
|
||||
tile = tiles[i];
|
||||
var hasListener = goog.events.hasListener(tile);
|
||||
if (tile.toDrop) {
|
||||
expect(hasListener).toBeFalsy();
|
||||
} else {
|
||||
expect(hasListener).toBeTruthy();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.TileQueue');
|
||||
|
||||
Reference in New Issue
Block a user