Merge pull request #409 from elemoine/tilequeue

Tile renderers needn't listen for tile change
This commit is contained in:
Éric Lemoine
2013-03-22 09:17:46 -07:00
6 changed files with 22 additions and 39 deletions

View File

@@ -271,7 +271,8 @@ ol.Map = function(mapOptions) {
* @private
* @type {ol.TileQueue}
*/
this.tileQueue_ = new ol.TileQueue(goog.bind(this.getTilePriority, this));
this.tileQueue_ = new ol.TileQueue(goog.bind(this.getTilePriority, this),
goog.bind(this.handleTileChange_, this));
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.VIEW),
this.handleViewChanged_, false, this);
@@ -543,13 +544,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
*/
ol.Map.prototype.handlePostRender = function() {
this.tileQueue_.reprioritize(); // FIXME only call if needed
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();
}
this.tileQueue_.loadMoreTiles();
var postRenderFunctions = this.postRenderFunctions_;
var i;
@@ -585,6 +580,14 @@ ol.Map.prototype.handleSizeChanged_ = function() {
};
/**
* @private
*/
ol.Map.prototype.handleTileChange_ = function() {
this.requestRenderFrame();
};
/**
* @private
*/

View File

@@ -167,8 +167,6 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
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 ||
tileState == ol.TileState.EMPTY) {
tilesToDrawByZ[z][tileCoord.toString()] = tile;

View File

@@ -124,8 +124,6 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
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;

View File

@@ -41,12 +41,6 @@ ol.renderer.Layer = function(mapRenderer, layer) {
*/
this.layer_ = layer;
/**
* @protected
* @type {Object.<string, boolean>}
*/
this.observedTileKeys = {};
goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS),
this.handleLayerBrightnessChange, false, this);
@@ -181,22 +175,6 @@ ol.renderer.Layer.prototype.handleTileChange_ = function(event) {
if (tile.getState() === ol.TileState.LOADED) {
this.getMap().requestRenderFrame();
}
delete this.observedTileKeys[tile.getKey()];
};
/**
* Listen once to tileKey, le change event.
* @param {ol.Tile} tile Tile.
* @protected
*/
ol.renderer.Layer.prototype.listenToTileChange = function(tile) {
var tileKey = tile.getKey();
if (!(tileKey in this.observedTileKeys)) {
this.observedTileKeys[tileKey] = true;
goog.events.listenOnce(tile, goog.events.EventType.CHANGE,
this.handleTileChange_, false, this);
}
};

View File

@@ -398,8 +398,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
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;

View File

@@ -30,8 +30,10 @@ ol.TilePriorityFunction;
* @constructor
* @param {ol.TilePriorityFunction} tilePriorityFunction
* Tile priority function.
* @param {Function} tileChangeCallback
* Function called on each tile change event.
*/
ol.TileQueue = function(tilePriorityFunction) {
ol.TileQueue = function(tilePriorityFunction, tileChangeCallback) {
/**
* @private
@@ -39,6 +41,12 @@ ol.TileQueue = function(tilePriorityFunction) {
*/
this.tilePriorityFunction_ = tilePriorityFunction;
/**
* @private
* @type {Function}
*/
this.tileChangeCallback_ = tileChangeCallback;
/**
* @private
* @type {number}
@@ -120,6 +128,7 @@ ol.TileQueue.prototype.enqueue = function(tile, tileSourceKey, tileCenter) {
*/
ol.TileQueue.prototype.handleTileChange = function() {
--this.tilesLoading_;
this.tileChangeCallback_();
};
@@ -168,7 +177,7 @@ ol.TileQueue.prototype.heapify_ = function() {
/**
* @return {boolean} New loading tiles?
* FIXME empty description for jsdoc
*/
ol.TileQueue.prototype.loadMoreTiles = function() {
var tile;
@@ -179,7 +188,6 @@ ol.TileQueue.prototype.loadMoreTiles = function() {
tile.load();
++this.tilesLoading_;
}
return goog.isDef(tile);
};