New beforeload event and slightly changed loading sequence

Having the TileManager remove an image from the DOM, then setting the
cached image, and then having to position it felt a bit awkward. With the
new beforeload event, the setImage method and putting renderTile before
positionTile, providing the cached image feels way more natural.
This commit is contained in:
ahocevar
2012-12-18 01:21:11 +01:00
parent 64df7e3d04
commit a02e08ad2a
3 changed files with 38 additions and 17 deletions

View File

@@ -255,8 +255,8 @@ OpenLayers.TileManager = OpenLayers.Class({
addTile: function(evt) {
evt.tile.events.on({
beforedraw: this.queueTileDraw,
loadstart: this.manageTileCache,
reload: this.manageTileCache,
beforeload: this.manageTileCache,
loadend: this.addToCache,
unload: this.unloadTile,
scope: this
});
@@ -273,8 +273,7 @@ OpenLayers.TileManager = OpenLayers.Class({
var tile = evt.object;
tile.events.un({
beforedraw: this.queueTileDraw,
loadstart: this.manageTileCache,
reload: this.manageTileCache,
beforeload: this.manageTileCache,
loadend: this.addToCache,
unload: this.unloadTile,
scope: this
@@ -330,16 +329,9 @@ OpenLayers.TileManager = OpenLayers.Class({
// only use image from cache if it is not on a layer already
if (img && (!img.parentNode ||
OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer'))) {
if (tile.imgDiv) {
tile.layer.div.removeChild(tile.imgDiv);
}
tile.imgDiv = img;
tile.setImage(img);
OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url);
this.tileCacheIndex.push(tile.url);
tile.positionTile();
tile.layer.div.appendChild(tile.imgDiv);
} else if (evt.type === 'loadstart') {
tile.events.register('loadend', this, this.addToCache);
}
},
@@ -351,7 +343,6 @@ OpenLayers.TileManager = OpenLayers.Class({
*/
addToCache: function(evt) {
var tile = evt.object;
tile.events.unregister('loadend', this, this.addToCache);
if (!this.tileCache[tile.url]) {
if (!OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError')) {
if (this.tileCacheIndex.length >= this.cacheSize) {