Modify initSingleTile to respect map or layer maxExtent when set and layer is not the map's baseLayer

This commit is contained in:
Matt Priour
2012-03-08 00:31:05 -06:00
parent 0566b0a5bb
commit 9fbadfa79f

View File

@@ -718,18 +718,50 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
*/
initSingleTile: function(bounds) {
this.clearTileQueue();
//determine if a maxExtent restriction exists
var maxExt = this.maxExtent || this.map.getMaxExtent() || this.map.maxExtent;
//determine new tile bounds
var tileWidth, tileHeight, tileBounds;
var center = bounds.getCenterLonLat();
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));
//adjust tile bounds to fit in maxExtent restriction
//if it is an overlay and there is a maxExtent restriction
if(this != this.map.baseLayer && maxExt && bounds.containsBounds(maxExt)) {
bounds.bottom = Math.max(maxExt.bottom, bounds.bottom);
bounds.top = Math.min(maxExt.top, bounds.top);
bounds.left = Math.max(maxExt.left, bounds.left);
bounds.right = Math.min(maxExt.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 = {
h : Math.abs(trPx.y - blPx.y),
w : Math.abs(trPx.x - blPx.x)
};
this._resetTileSize = true;
}
else {
tileWidth = bounds.getWidth() * this.ratio;
tileHeight = bounds.getHeight() * this.ratio;
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();
}
}
var px = this.map.getLayerPxFromLonLat({
lon: tileBounds.left,
lat: tileBounds.top