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;
}
// 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.top = (i * this.tileSize.h) + '%';
backBuffer.appendChild(tile);
@@ -472,15 +472,31 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
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
* Upstate states in the backBufferData property
*/
updateBackBufferData: function() {
this.backBufferData.resolution = this.getServerResolution();
var topLeftTile = this.grid[0][0];
this.backBufferData.lonlat = {lon: topLeftTile.bounds.left,
lat: topLeftTile.bounds.top};
// 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];
this.backBufferData.lonlat = {lon: topLeftTile.bounds.left,
lat: topLeftTile.bounds.top};
}
},
/**
@@ -902,13 +918,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//if that was the last tile, then trigger a 'loadend' on the layer
if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadend");
if(this.backBuffer && this.backBuffer.parentNode) {
this.div.removeChild(this.backBuffer);
this.backBuffer = null;
}
if(this.map) {
this.updateBackBufferData();
}
this.removeBackBuffer();
this.updateBackBufferData();
}
};
tile.events.register("loadend", this, tile.onLoadEnd);