diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 87b79d87cf..c66807717b 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -63,31 +63,34 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { } return; } + var gridBounds = this.getGridBounds(); if (!this.grid || zoomChanged) { this._initTiles(); - } else if ( bounds.top > this.getGridBounds().bottom || - bounds.left > this.getGridBounds().right || - bounds.right < this.getGridBounds().left || - bounds.bottom < this.getGridBounds().top ) { + } else if ( bounds.top < gridBounds.bottom || + bounds.left > gridBounds.right || + bounds.right < gridBounds.left || + bounds.bottom > gridBounds.top ) { + console.log("else if"); this._initTiles(); } else { var i = 0; - while (this.getGridBounds().bottom > bounds.bottom) { + while (gridBounds.bottom > bounds.bottom) { this.insertRow(false); } - while (this.getGridBounds().left > bounds.left) { + while (gridBounds.left > bounds.left) { this.insertColumn(true); } - while (this.getGridBounds().top < bounds.top) { + while (gridBounds.top < bounds.top) { this.insertRow(true); } - while (this.getGridBounds().right < bounds.right) { + while (gridBounds.right < bounds.right) { this.insertColumn(false); } } }, getGridBounds:function() { + if (!this.grid) return null; var topLeftTile = this.grid[0][0]; var bottomRightTile = this.grid[this.grid.length-1][this.grid[0].length-1]; return new OpenLayers.Bounds(topLeftTile.bounds.left,