New TileManager
This removes all tile queueing/loading specific code from Layer.Grid and creates a new class that manages tile loading and caching.
This commit is contained in:
@@ -146,11 +146,12 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
* Check that a tile should be drawn, and draw it.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Was a tile drawn?
|
||||
* {Boolean} Was a tile drawn? Or null if a beforedraw listener returned
|
||||
* false.
|
||||
*/
|
||||
draw: function() {
|
||||
var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments);
|
||||
if (drawn) {
|
||||
var shouldDraw = OpenLayers.Tile.prototype.draw.apply(this, arguments);
|
||||
if (shouldDraw) {
|
||||
// The layer's reproject option is deprecated.
|
||||
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
|
||||
// getBoundsFromBaseLayer is defined in deprecated.js.
|
||||
@@ -158,17 +159,17 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
}
|
||||
if (this.isLoading) {
|
||||
//if we're already loading, send 'reload' instead of 'loadstart'.
|
||||
this._loadEvent = "reload";
|
||||
this._loadEvent = "reload";
|
||||
} else {
|
||||
this.isLoading = true;
|
||||
this._loadEvent = "loadstart";
|
||||
}
|
||||
this.positionTile();
|
||||
this.renderTile();
|
||||
} else {
|
||||
} else if (shouldDraw === false) {
|
||||
this.unload();
|
||||
}
|
||||
return drawn;
|
||||
return shouldDraw;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -287,9 +288,11 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
this.events.triggerEvent(this._loadEvent);
|
||||
var img = this.getImage();
|
||||
if (this.url && img.getAttribute("src") == this.url) {
|
||||
this.onImageLoad();
|
||||
this._loadTimeout = window.setTimeout(
|
||||
OpenLayers.Function.bind(this.onImageLoad, this), 0
|
||||
);
|
||||
} else {
|
||||
OpenLayers.Event.stopObservingElement(img);
|
||||
this.stopLoading();
|
||||
if (this.crossOriginKeyword) {
|
||||
img.removeAttribute("crossorigin");
|
||||
}
|
||||
@@ -328,7 +331,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
} else {
|
||||
// Remove reference to the image, and leave it to the browser's
|
||||
// caching and garbage collection.
|
||||
OpenLayers.Event.stopObservingElement(this.imgDiv);
|
||||
this.stopLoading();
|
||||
this.imgDiv = null;
|
||||
if (img.parentNode) {
|
||||
img.parentNode.removeChild(img);
|
||||
@@ -378,7 +381,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
*/
|
||||
onImageLoad: function() {
|
||||
var img = this.imgDiv;
|
||||
OpenLayers.Event.stopObservingElement(img);
|
||||
this.stopLoading();
|
||||
img.style.visibility = 'inherit';
|
||||
img.style.opacity = this.layer.opacity;
|
||||
this.isLoading = false;
|
||||
@@ -409,6 +412,16 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: stopLoading
|
||||
* Stops a loading sequence so <onImageLoad> won't be executed.
|
||||
*/
|
||||
stopLoading: function() {
|
||||
OpenLayers.Event.stopObservingElement(this.imgDiv);
|
||||
window.clearTimeout(this._loadTimeout);
|
||||
delete this._loadTimeout;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getCanvasContext
|
||||
|
||||
Reference in New Issue
Block a user