diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index c9f59a8e9d..218ff3afb2 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -778,47 +778,33 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { this.clearTileQueue(); //determine new tile bounds - var tileWidth, tileHeight, tileBounds; var center = bounds.getCenterLonLat(); - //adjust tile bounds to fit in maxExtent restriction - //if there is a maxExtent restriction - if(this.maxExtent && bounds.containsBounds(this.maxExtent, true)) { - bounds.bottom = Math.max(this.maxExtent.bottom, bounds.bottom); - bounds.top = Math.min(this.maxExtent.top, bounds.top); - bounds.left = Math.max(this.maxExtent.left, bounds.left); - bounds.right = Math.min(this.maxExtent.right, bounds.right); - tileWidth = bounds.getWidth(); - tileHeight = bounds.getHeight(); - tileBounds = bounds; - var blPx = this.map.getLayerPxFromLonLat({ - lon : tileBounds.left, - lat : tileBounds.bottom - }); - var trPx = this.map.getLayerPxFromLonLat({ - lon : tileBounds.right, - lat : tileBounds.top - }); - this.tileSize = new OpenLayers.Size( - Math.abs(trPx.x - blPx.x), - Math.abs(trPx.y - blPx.y) - ); - this._resetTileSize = true; - } else { - tileWidth = bounds.getWidth() * this.ratio; - tileHeight = bounds.getHeight() * this.ratio; - tileBounds = + var tileWidth = bounds.getWidth() * this.ratio; + var tileHeight = bounds.getHeight() * this.ratio; + var tileBounds = new OpenLayers.Bounds( center.lon - (tileWidth / 2), center.lat - (tileHeight / 2), center.lon + (tileWidth / 2), center.lat + (tileHeight / 2) ); - if(this._resetTileSize === true) { - this.setTileSize(); - delete this._resetTileSize; - } + //adjust tile bounds to fit in maxExtent restriction + //if there is a maxExtent restriction + if(this.maxExtent) { + tileBounds.bottom = Math.max(this.maxExtent.bottom, tileBounds.bottom); + tileBounds.top = Math.min(this.maxExtent.top, tileBounds.top); + tileBounds.left = Math.max(this.maxExtent.left, tileBounds.left); + tileBounds.right = Math.min(this.maxExtent.right, tileBounds.right); + tileWidth = tileBounds.getWidth(); + tileHeight = tileBounds.getHeight(); + var resolution = this.map.getResolution(); + this.tileSize = new OpenLayers.Size( + tileWidth / resolution, + tileHeight / resolution + ); } + var px = this.map.getLayerPxFromLonLat({ lon: tileBounds.left, lat: tileBounds.top diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 016cf68873..ffff2a3482 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -467,9 +467,8 @@ t.ok(ul.lon === desiredUL.lon && ul.lat === desiredUL.lat, "correct ul passed to translation"); return translatedPX; }, - getResolution: function() { - } - } + getResolution:function(){return 1;} + }; var newTile = { draw: function() { @@ -528,7 +527,7 @@ } }; //test bound fully contains the maxExtent - //tile bounds -10,10,50,100 + //tile bounds -10,10,50,100 -> apply ratio -40,-35,80,145 layer.maxExtent = new OpenLayers.Bounds(0,20,40,90); desiredTileBounds = new OpenLayers.Bounds(0,20,40,90); translatedPX = {x:0,y:90}; @@ -536,9 +535,10 @@ //test bound overlaps the maxExtent bounds = new OpenLayers.Bounds(-10,10,50,100); - layer.maxExtent = new OpenLayers.Bounds(-30,20,40,110); - desiredTileBounds = new OpenLayers.Bounds(-10,20,40,100); - translatedPX = {x:-10,y:100}; + //with ratio applied tile bounds are -40,-35,80,145 + layer.maxExtent = new OpenLayers.Bounds(-50,20,40,150); + desiredTileBounds = new OpenLayers.Bounds(-40,20,40,145); + translatedPX = {x:-40,y:145}; layer.grid = [[ tile ]]; layer.initSingleTile(bounds); }