Merge pull request #702 from ahocevar/smart-queue
New tile image cache and tile queue improvements. r=@bartvde,@elemoine
This commit is contained in:
@@ -197,20 +197,12 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
res.zoomMax + 1 - res.zoomMin, this.numZoomLevels
|
||||
)
|
||||
}, true);
|
||||
if (!this.isBaseLayer) {
|
||||
this.redraw();
|
||||
}
|
||||
this.updateAttribution();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawTileFromQueue
|
||||
* Draws the first tile from the tileQueue, and unqueues that tile
|
||||
*/
|
||||
drawTileFromQueue: function() {
|
||||
// don't start working on the queue before we have a url from initLayer
|
||||
if (this.url) {
|
||||
OpenLayers.Layer.XYZ.prototype.drawTileFromQueue.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Method: getURL
|
||||
*
|
||||
@@ -218,6 +210,9 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
* bounds - {<OpenLayers.Bounds>}
|
||||
*/
|
||||
getURL: function(bounds) {
|
||||
if (!this.url) {
|
||||
return;
|
||||
}
|
||||
var xyz = this.getXYZ(bounds), x = xyz.x, y = xyz.y, z = xyz.z;
|
||||
var quadDigits = [];
|
||||
for (var i = z; i > 0; --i) {
|
||||
|
||||
+14
-122
@@ -113,14 +113,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
*/
|
||||
numLoadingTiles: 0,
|
||||
|
||||
/**
|
||||
* APIProperty: tileLoadingDelay
|
||||
* {Integer} Number of milliseconds before we shift and load
|
||||
* tiles when panning. Ignored if <OpenLayers.Animation.isNative> is
|
||||
* true. Default is 85.
|
||||
*/
|
||||
tileLoadingDelay: 85,
|
||||
|
||||
/**
|
||||
* Property: serverResolutions
|
||||
* {Array(Number}} This property is documented in subclasses as
|
||||
@@ -128,32 +120,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
*/
|
||||
serverResolutions: null,
|
||||
|
||||
/**
|
||||
* Property: moveTimerId
|
||||
* {Number} The id of the <deferMoveGriddedTiles> timer.
|
||||
*/
|
||||
moveTimerId: null,
|
||||
|
||||
/**
|
||||
* Property: deferMoveGriddedTiles
|
||||
* {Function} A function that defers execution of <moveGriddedTiles> by
|
||||
* <tileLoadingDelay>. If <OpenLayers.Animation.isNative> is true, this
|
||||
* is null and unused.
|
||||
*/
|
||||
deferMoveGriddedTiles: null,
|
||||
|
||||
/**
|
||||
* Property: tileQueueId
|
||||
* {Number} The id of the <drawTileFromQueue> animation.
|
||||
*/
|
||||
tileQueueId: null,
|
||||
|
||||
/**
|
||||
* Property: tileQueue
|
||||
* {Array(<OpenLayers.Tile>)} Tiles queued for drawing.
|
||||
*/
|
||||
tileQueue: null,
|
||||
|
||||
/**
|
||||
* Property: loading
|
||||
* {Boolean} Indicates if tiles are being loaded.
|
||||
@@ -240,7 +206,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* should not be zero.
|
||||
*/
|
||||
className: null,
|
||||
|
||||
|
||||
/**
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
@@ -255,6 +221,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* element - {DOMElement} A reference to layer.events.element.
|
||||
*
|
||||
* Supported event types:
|
||||
* addtile - Triggered when a tile is added to this layer. Listeners receive
|
||||
* an object as first argument, which has a tile property that
|
||||
* references the tile that has been added.
|
||||
* tileloadstart - Triggered when a tile starts loading. Listeners receive
|
||||
* an object as first argument, which has a tile property that
|
||||
* references the tile that starts loading.
|
||||
@@ -269,6 +238,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* still hidden) if a tile failed to load. Listeners receive an object
|
||||
* as first argument, which has a tile property that references the
|
||||
* tile that could not be loaded.
|
||||
* retile - Triggered when the layer recreates its tile grid.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -308,18 +278,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
this.grid = [];
|
||||
this.tileQueue = [];
|
||||
this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this);
|
||||
|
||||
this.initProperties();
|
||||
|
||||
if (!OpenLayers.Animation.isNative) {
|
||||
this.deferMoveGriddedTiles = OpenLayers.Function.bind(function() {
|
||||
this.moveGriddedTiles(true);
|
||||
this.moveTimerId = null;
|
||||
}, this);
|
||||
}
|
||||
|
||||
this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1;
|
||||
},
|
||||
|
||||
@@ -358,15 +320,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* map - {<OpenLayers.Map>} The map.
|
||||
*/
|
||||
removeMap: function(map) {
|
||||
if (this.moveTimerId !== null) {
|
||||
window.clearTimeout(this.moveTimerId);
|
||||
this.moveTimerId = null;
|
||||
}
|
||||
this.clearTileQueue();
|
||||
if(this.backBufferTimerId !== null) {
|
||||
window.clearTimeout(this.backBufferTimerId);
|
||||
this.backBufferTimerId = null;
|
||||
}
|
||||
this.removeBackBuffer();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -388,7 +342,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* destroy() on each of them to kill circular references
|
||||
*/
|
||||
clearGrid:function() {
|
||||
this.clearTileQueue();
|
||||
if (this.grid) {
|
||||
for(var iRow=0, len=this.grid.length; iRow<len; iRow++) {
|
||||
var row = this.grid[iRow];
|
||||
@@ -456,13 +409,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
// we do not want to copy reference to grid, so we make a new array
|
||||
obj.grid = [];
|
||||
obj.gridResolution = null;
|
||||
// same for backbuffer and tile queue
|
||||
// same for backbuffer
|
||||
obj.backBuffer = null;
|
||||
obj.backBufferTimerId = null;
|
||||
obj.tileQueue = [];
|
||||
obj.tileQueueId = null;
|
||||
obj.loading = false;
|
||||
obj.moveTimerId = null;
|
||||
|
||||
return obj;
|
||||
},
|
||||
@@ -608,50 +558,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: queueTileDraw
|
||||
* Adds a tile to the animation queue that will draw it.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Object} Listener argument of the tile's beforedraw event
|
||||
*/
|
||||
queueTileDraw: function(evt) {
|
||||
var tile = evt.object;
|
||||
if (!~OpenLayers.Util.indexOf(this.tileQueue, tile)) {
|
||||
// queue only if not in queue already
|
||||
this.tileQueue.push(tile);
|
||||
}
|
||||
if (!this.tileQueueId) {
|
||||
this.tileQueueId = OpenLayers.Animation.start(
|
||||
OpenLayers.Function.bind(this.drawTileFromQueue, this),
|
||||
null, this.div
|
||||
);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawTileFromQueue
|
||||
* Draws the first tile from the tileQueue, and unqueues that tile
|
||||
*/
|
||||
drawTileFromQueue: function() {
|
||||
if (this.tileQueue.length === 0) {
|
||||
this.clearTileQueue();
|
||||
} else {
|
||||
this.tileQueue.shift().draw(true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: clearTileQueue
|
||||
* Clears the animation queue
|
||||
*/
|
||||
clearTileQueue: function() {
|
||||
OpenLayers.Animation.stop(this.tileQueueId);
|
||||
this.tileQueueId = null;
|
||||
this.tileQueue = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: destroyTile
|
||||
*
|
||||
@@ -881,7 +787,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* bounds - {<OpenLayers.Bounds>}
|
||||
*/
|
||||
initSingleTile: function(bounds) {
|
||||
this.clearTileQueue();
|
||||
this.events.triggerEvent("retile");
|
||||
|
||||
//determine new tile bounds
|
||||
var center = bounds.getCenterLonLat();
|
||||
@@ -1014,7 +920,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* bounds - {<OpenLayers.Bounds>}
|
||||
*/
|
||||
initGriddedTiles:function(bounds) {
|
||||
this.clearTileQueue();
|
||||
this.events.triggerEvent("retile");
|
||||
|
||||
// work out mininum number of rows and columns; this is the number of
|
||||
// tiles required to cover the viewport plus at least one for panning
|
||||
@@ -1093,8 +999,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
//shave off exceess rows and colums
|
||||
this.removeExcessTiles(rowidx, colidx);
|
||||
|
||||
var resolution = this.getServerResolution(),
|
||||
immediately = resolution === this.gridResolution;
|
||||
var resolution = this.getServerResolution();
|
||||
// store the resolution of the grid
|
||||
this.gridResolution = resolution;
|
||||
|
||||
@@ -1103,7 +1008,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
return a.distance - b.distance;
|
||||
});
|
||||
for (var i=0, ii=tileData.length; i<ii; ++i) {
|
||||
tileData[i].tile.draw(immediately);
|
||||
tileData[i].tile.draw();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1134,7 +1039,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
var tile = new this.tileClass(
|
||||
this, position, bounds, null, this.tileSize, this.tileOptions
|
||||
);
|
||||
tile.events.register("beforedraw", this, this.queueTileDraw);
|
||||
this.events.triggerEvent("addtile", {tile: tile});
|
||||
return tile;
|
||||
},
|
||||
|
||||
@@ -1165,7 +1070,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
aborted: evt.type === "unload"
|
||||
});
|
||||
//if that was the last tile, then trigger a 'loadend' on the layer
|
||||
if (this.tileQueue.length === 0 && this.numLoadingTiles === 0) {
|
||||
if (this.numLoadingTiles === 0) {
|
||||
this.loading = false;
|
||||
this.events.triggerEvent("loadend");
|
||||
if(this.backBuffer) {
|
||||
@@ -1218,21 +1123,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
|
||||
/**
|
||||
* Method: moveGriddedTiles
|
||||
*
|
||||
* Parameter:
|
||||
* deferred - {Boolean} true if this is a deferred call that should not
|
||||
* be delayed.
|
||||
*/
|
||||
moveGriddedTiles: function(deferred) {
|
||||
if (!deferred && !OpenLayers.Animation.isNative) {
|
||||
if (this.moveTimerId != null) {
|
||||
window.clearTimeout(this.moveTimerId);
|
||||
}
|
||||
this.moveTimerId = window.setTimeout(
|
||||
this.deferMoveGriddedTiles, this.tileLoadingDelay
|
||||
);
|
||||
return;
|
||||
}
|
||||
moveGriddedTiles: function() {
|
||||
var buffer = this.buffer + 1;
|
||||
while(true) {
|
||||
var tlTile = this.grid[0][0];
|
||||
|
||||
Reference in New Issue
Block a user