diff --git a/lib/OpenLayers/Layer/KaMap.js b/lib/OpenLayers/Layer/KaMap.js index 9b7f14ebce..c2f65c9b37 100644 --- a/lib/OpenLayers/Layer/KaMap.js +++ b/lib/OpenLayers/Layer/KaMap.js @@ -77,13 +77,6 @@ OpenLayers.Layer.KaMap.prototype = _initTiles:function() { - //first of all, clear out the main div - this.div.innerHTML = ""; - - //now clear out the old grid and start a new one - this.clearGrid(); - this.grid = new Array(); - var viewSize = this.map.getSize(); var bounds = this.map.getExtent(); var extent = this.map.getMaxExtent(); @@ -111,31 +104,53 @@ OpenLayers.Layer.KaMap.prototype = var startX = tileoffsetx; var startLon = tileoffsetlon; + var rowidx = 0; + do { - var row = new Array(); - this.grid.push(row); + var row; + + row = this.grid[rowidx++]; + if (!row) { + row = new Array(); + this.grid.push(row); + } + tileoffsetlon = startLon; tileoffsetx = startX; + + var colidx = 0; + do { var tileBounds = new OpenLayers.Bounds(tileoffsetlon, - tileoffsetlat, - tileoffsetlon+tilelon, - tileoffsetlat+tilelat); + tileoffsetlat, + tileoffsetlon + tilelon, + tileoffsetlat + tilelat); - var tile = this.addTile(tileBounds, - new OpenLayers.Pixel(tileoffsetx - parseInt(this.map.layerContainerDiv.style.left), - tileoffsety - parseInt(this.map.layerContainerDiv.style.top)) - ); - tile.draw(); - row.push(tile); + var x = tileoffsetx; + x -= parseInt(this.map.layerContainerDiv.style.left); + + var y = tileoffsety; + y -= parseInt(this.map.layerContainerDiv.style.top); + + var px = new OpenLayers.Pixel(x, y); + var tile; + + tile = row[colidx++]; + if (!tile) { + tile = this.addTile(tileBounds, px); + tile.draw(); + row.push(tile); + } else { + tile.moveTo(tileBounds, px); + } tileoffsetlon += tilelon; tileoffsetx += this.tileSize.w; - } while (tileoffsetlon < bounds.right) + } while (tileoffsetlon <= bounds.right + tilelon * this.buffer) tileoffsetlat -= tilelat; tileoffsety += this.tileSize.h; - } while(tileoffsetlat > bounds.bottom - tilelat) + } while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer) },