minor refactoring in Layer.Grid - add a removeBackBuffer function

This commit is contained in:
Éric Lemoine
2011-10-19 20:42:34 +02:00
parent b39f4fde1c
commit f9ae12f227

View File

@@ -462,7 +462,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
return; return;
} }
// to be able to correctly position the back buffer we // to be able to correctly position the back buffer we
// place the first tile at (0, 0) in the back buffer // place the tiles grid at (0, 0) in the back buffer
tile.style.left = (j * this.tileSize.w) + '%'; tile.style.left = (j * this.tileSize.w) + '%';
tile.style.top = (i * this.tileSize.h) + '%'; tile.style.top = (i * this.tileSize.h) + '%';
backBuffer.appendChild(tile); backBuffer.appendChild(tile);
@@ -472,15 +472,31 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
return backBuffer; return backBuffer;
}, },
/**
* Method: removeBackBuffer
* Remove back buffer from DOM.
*/
removeBackBuffer: function() {
if(this.backBuffer && this.backBuffer.parentNode) {
this.div.removeChild(this.backBuffer);
this.backBuffer = null;
}
},
/** /**
* Method: updateBackBufferData * Method: updateBackBufferData
* Upstate states in the backBufferData property * Upstate states in the backBufferData property
*/ */
updateBackBufferData: function() { updateBackBufferData: function() {
this.backBufferData.resolution = this.getServerResolution(); // updateBackBufferData is called asynchronously when tiles are
// received, so we need to check that the map is still there
if (this.map) {
var resolution = this.map.getResolution();
this.backBufferData.resolution = this.getServerResolution(resolution);
var topLeftTile = this.grid[0][0]; var topLeftTile = this.grid[0][0];
this.backBufferData.lonlat = {lon: topLeftTile.bounds.left, this.backBufferData.lonlat = {lon: topLeftTile.bounds.left,
lat: topLeftTile.bounds.top}; lat: topLeftTile.bounds.top};
}
}, },
/** /**
@@ -902,14 +918,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//if that was the last tile, then trigger a 'loadend' on the layer //if that was the last tile, then trigger a 'loadend' on the layer
if (this.numLoadingTiles == 0) { if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadend"); this.events.triggerEvent("loadend");
if(this.backBuffer && this.backBuffer.parentNode) { this.removeBackBuffer();
this.div.removeChild(this.backBuffer);
this.backBuffer = null;
}
if(this.map) {
this.updateBackBufferData(); this.updateBackBufferData();
} }
}
}; };
tile.events.register("loadend", this, tile.onLoadEnd); tile.events.register("loadend", this, tile.onLoadEnd);
tile.events.register("unload", this, tile.onLoadEnd); tile.events.register("unload", this, tile.onLoadEnd);