Simplify maxExtent restriction logic and prevent unneeded calls to `getLayerPxFromLonLat`
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user