Register change listeners for loading tiles only
With this commit we register a change listener at a time when we are guaranteed that the listener will be called. In this was we don't need to remove listeners when the tile is dropped from the tile queue. And to avoid busy-polling between IDLE and LOADING we rely on the map to call requestRenderFrame when new tiles change to LOADING from IDLE.
This commit is contained in:
@@ -530,7 +530,14 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
|
|||||||
*/
|
*/
|
||||||
ol.Map.prototype.handlePostRender = function() {
|
ol.Map.prototype.handlePostRender = function() {
|
||||||
this.tileQueue_.reprioritize(); // FIXME only call if needed
|
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 postRenderFunctions = this.postRenderFunctions_;
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < postRenderFunctions.length; ++i) {
|
for (i = 0; i < postRenderFunctions.length; ++i) {
|
||||||
|
|||||||
@@ -158,10 +158,11 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
this.listenToTileChange(tile);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
} else if (tileState == ol.TileState.LOADING) {
|
||||||
|
this.listenToTileChange(tile);
|
||||||
} else if (tileState == ol.TileState.LOADED) {
|
} else if (tileState == ol.TileState.LOADED) {
|
||||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -116,10 +116,11 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
this.listenToTileChange(tile);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
} else if (tileState == ol.TileState.LOADING) {
|
||||||
|
this.listenToTileChange(tile);
|
||||||
} else if (tileState == ol.TileState.LOADED) {
|
} else if (tileState == ol.TileState.LOADED) {
|
||||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -391,10 +391,11 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
|
|
||||||
tileState = tile.getState();
|
tileState = tile.getState();
|
||||||
if (tileState == ol.TileState.IDLE) {
|
if (tileState == ol.TileState.IDLE) {
|
||||||
this.listenToTileChange(tile);
|
|
||||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||||
|
} else if (tileState == ol.TileState.LOADING) {
|
||||||
|
this.listenToTileChange(tile);
|
||||||
} else if (tileState == ol.TileState.LOADED) {
|
} else if (tileState == ol.TileState.LOADED) {
|
||||||
if (mapRenderer.isTileTextureLoaded(tile)) {
|
if (mapRenderer.isTileTextureLoaded(tile)) {
|
||||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ ol.TileQueue.prototype.heapify_ = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME empty description for jsdoc
|
* @return {boolean} New loading tiles?
|
||||||
*/
|
*/
|
||||||
ol.TileQueue.prototype.loadMoreTiles = function() {
|
ol.TileQueue.prototype.loadMoreTiles = function() {
|
||||||
var tile;
|
var tile;
|
||||||
@@ -179,6 +179,7 @@ ol.TileQueue.prototype.loadMoreTiles = function() {
|
|||||||
tile.load();
|
tile.load();
|
||||||
++this.tilesLoading_;
|
++this.tilesLoading_;
|
||||||
}
|
}
|
||||||
|
return goog.isDef(tile);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user