Simplified tile queue; using the tile's beforedraw listener.

Since draw is the only tile operation that we defer, the tile queue can be an array of tiles and queue handling can be simplified. We now use the beforedraw event to defer drawing, and remove all occurrences of a tile from the tile queue when we draw it.

Instead of layers that want to defer tile drawing having to override the tile's draw method, layers can now abort drawing by returning false from a beforedraw listener, and later call draw(true) to draw the tile directly, without clearing it first.
This commit is contained in:
ahocevar
2012-01-28 16:12:29 +01:00
parent 0e435b5483
commit dde45696f7
11 changed files with 93 additions and 77 deletions
+23 -8
View File
@@ -25,6 +25,10 @@ OpenLayers.Tile = OpenLayers.Class({
/**
* Supported event types:
* - *beforedraw* Triggered before the tile is drawn. Used to defer
* drawing to an animation queue. To defer drawing, listeners need
* to return false, which will abort drawing. The queue handler needs
* to call <draw>(true) to actually draw the tile.
* - *loadstart* Triggered when tile loading starts.
* - *loadend* Triggered when tile loading ends.
* - *reload* Triggered when an already loading tile is reloaded.
@@ -83,7 +87,7 @@ OpenLayers.Tile = OpenLayers.Class({
* {Boolean} Is the tile loading?
*/
isLoading: false,
/** TBD 3.0 -- remove 'url' from the list of parameters to the constructor.
* there is no need for the base tile class to have a url.
*
@@ -149,15 +153,26 @@ OpenLayers.Tile = OpenLayers.Class({
* it should actually be re-drawn. This is an example implementation
* that can be overridden by subclasses. The minimum thing to do here
* is to call <clear> and return the result from <shouldDraw>.
*
* Parameters:
* deferred - {Boolean} When drawing was aborted by returning false from a
* *beforedraw* listener, the queue manager needs to pass true, so the
* tile will not be cleared and immediately be drawn. Otherwise, the
* tile will be cleared and a *beforedraw* event will be fired.
*
* Returns:
* {Boolean} Whether or not the tile should actually be drawn.
*/
draw: function() {
//clear tile's contents and mark as not drawn
this.clear();
return this.shouldDraw();
draw: function(deferred) {
if (!deferred) {
//clear tile's contents and mark as not drawn
this.clear();
}
var draw = this.shouldDraw();
if (draw && !deferred) {
draw = this.events.triggerEvent("beforedraw") !== false;
}
return draw;
},
/**
@@ -228,10 +243,10 @@ OpenLayers.Tile = OpenLayers.Class({
/**
* Method: clear
* Clear the tile of any bounds/position-related data so that it can
* be reused in a new location. To be implemented by subclasses.
* be reused in a new location.
*/
clear: function(draw) {
// to be implemented by subclasses
// to be extended by subclasses
},
CLASS_NAME: "OpenLayers.Tile"