Merge pull request #409 from elemoine/tilequeue
Tile renderers needn't listen for tile change
This commit is contained in:
+11
-8
@@ -271,7 +271,8 @@ ol.Map = function(mapOptions) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.TileQueue}
|
* @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),
|
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.VIEW),
|
||||||
this.handleViewChanged_, false, this);
|
this.handleViewChanged_, false, this);
|
||||||
@@ -543,13 +544,7 @@ 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
|
||||||
var moreLoadingTiles = this.tileQueue_.loadMoreTiles();
|
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;
|
||||||
@@ -585,6 +580,14 @@ ol.Map.prototype.handleSizeChanged_ = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.handleTileChange_ = function() {
|
||||||
|
this.requestRenderFrame();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -167,8 +167,6 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
|||||||
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 ||
|
||||||
tileState == ol.TileState.EMPTY) {
|
tileState == ol.TileState.EMPTY) {
|
||||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
|||||||
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;
|
||||||
|
|||||||
@@ -41,12 +41,6 @@ ol.renderer.Layer = function(mapRenderer, layer) {
|
|||||||
*/
|
*/
|
||||||
this.layer_ = layer;
|
this.layer_ = layer;
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {Object.<string, boolean>}
|
|
||||||
*/
|
|
||||||
this.observedTileKeys = {};
|
|
||||||
|
|
||||||
goog.events.listen(this.layer_,
|
goog.events.listen(this.layer_,
|
||||||
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS),
|
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS),
|
||||||
this.handleLayerBrightnessChange, false, this);
|
this.handleLayerBrightnessChange, false, this);
|
||||||
@@ -181,22 +175,6 @@ ol.renderer.Layer.prototype.handleTileChange_ = function(event) {
|
|||||||
if (tile.getState() === ol.TileState.LOADED) {
|
if (tile.getState() === ol.TileState.LOADED) {
|
||||||
this.getMap().requestRenderFrame();
|
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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -398,8 +398,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
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;
|
||||||
|
|||||||
+11
-3
@@ -30,8 +30,10 @@ ol.TilePriorityFunction;
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {ol.TilePriorityFunction} tilePriorityFunction
|
* @param {ol.TilePriorityFunction} tilePriorityFunction
|
||||||
* Tile priority function.
|
* Tile priority function.
|
||||||
|
* @param {Function} tileChangeCallback
|
||||||
|
* Function called on each tile change event.
|
||||||
*/
|
*/
|
||||||
ol.TileQueue = function(tilePriorityFunction) {
|
ol.TileQueue = function(tilePriorityFunction, tileChangeCallback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -39,6 +41,12 @@ ol.TileQueue = function(tilePriorityFunction) {
|
|||||||
*/
|
*/
|
||||||
this.tilePriorityFunction_ = tilePriorityFunction;
|
this.tilePriorityFunction_ = tilePriorityFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Function}
|
||||||
|
*/
|
||||||
|
this.tileChangeCallback_ = tileChangeCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -120,6 +128,7 @@ ol.TileQueue.prototype.enqueue = function(tile, tileSourceKey, tileCenter) {
|
|||||||
*/
|
*/
|
||||||
ol.TileQueue.prototype.handleTileChange = function() {
|
ol.TileQueue.prototype.handleTileChange = function() {
|
||||||
--this.tilesLoading_;
|
--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() {
|
ol.TileQueue.prototype.loadMoreTiles = function() {
|
||||||
var tile;
|
var tile;
|
||||||
@@ -179,7 +188,6 @@ ol.TileQueue.prototype.loadMoreTiles = function() {
|
|||||||
tile.load();
|
tile.load();
|
||||||
++this.tilesLoading_;
|
++this.tilesLoading_;
|
||||||
}
|
}
|
||||||
return goog.isDef(tile);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user