Modify initSingleTile to respect map or layer maxExtent when set and layer is not the map's baseLayer
This commit is contained in:
@@ -718,18 +718,50 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
*/
|
*/
|
||||||
initSingleTile: function(bounds) {
|
initSingleTile: function(bounds) {
|
||||||
this.clearTileQueue();
|
this.clearTileQueue();
|
||||||
|
//determine if a maxExtent restriction exists
|
||||||
|
var maxExt = this.maxExtent || this.map.getMaxExtent() || this.map.maxExtent;
|
||||||
|
|
||||||
//determine new tile bounds
|
//determine new tile bounds
|
||||||
|
var tileWidth, tileHeight, tileBounds;
|
||||||
var center = bounds.getCenterLonLat();
|
var center = bounds.getCenterLonLat();
|
||||||
var tileWidth = bounds.getWidth() * this.ratio;
|
//adjust tile bounds to fit in maxExtent restriction
|
||||||
var tileHeight = bounds.getHeight() * this.ratio;
|
//if it is an overlay and there is a maxExtent restriction
|
||||||
|
if(this != this.map.baseLayer && maxExt && bounds.containsBounds(maxExt)) {
|
||||||
var tileBounds =
|
bounds.bottom = Math.max(maxExt.bottom, bounds.bottom);
|
||||||
new OpenLayers.Bounds(center.lon - (tileWidth/2),
|
bounds.top = Math.min(maxExt.top, bounds.top);
|
||||||
center.lat - (tileHeight/2),
|
bounds.left = Math.max(maxExt.left, bounds.left);
|
||||||
center.lon + (tileWidth/2),
|
bounds.right = Math.min(maxExt.right, bounds.right);
|
||||||
center.lat + (tileHeight/2));
|
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({
|
var px = this.map.getLayerPxFromLonLat({
|
||||||
lon: tileBounds.left,
|
lon: tileBounds.left,
|
||||||
lat: tileBounds.top
|
lat: tileBounds.top
|
||||||
|
|||||||
Reference in New Issue
Block a user