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();
|
this.clearTileQueue();
|
||||||
|
|
||||||
//determine new tile bounds
|
//determine new tile bounds
|
||||||
var tileWidth, tileHeight, tileBounds;
|
|
||||||
var center = bounds.getCenterLonLat();
|
var center = bounds.getCenterLonLat();
|
||||||
|
|
||||||
//adjust tile bounds to fit in maxExtent restriction
|
var tileWidth = bounds.getWidth() * this.ratio;
|
||||||
//if there is a maxExtent restriction
|
var tileHeight = bounds.getHeight() * this.ratio;
|
||||||
if(this.maxExtent && bounds.containsBounds(this.maxExtent, true)) {
|
var tileBounds =
|
||||||
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 =
|
|
||||||
new OpenLayers.Bounds(
|
new OpenLayers.Bounds(
|
||||||
center.lon - (tileWidth / 2),
|
center.lon - (tileWidth / 2),
|
||||||
center.lat - (tileHeight / 2),
|
center.lat - (tileHeight / 2),
|
||||||
center.lon + (tileWidth / 2),
|
center.lon + (tileWidth / 2),
|
||||||
center.lat + (tileHeight / 2)
|
center.lat + (tileHeight / 2)
|
||||||
);
|
);
|
||||||
if(this._resetTileSize === true) {
|
//adjust tile bounds to fit in maxExtent restriction
|
||||||
this.setTileSize();
|
//if there is a maxExtent restriction
|
||||||
delete this._resetTileSize;
|
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({
|
var px = this.map.getLayerPxFromLonLat({
|
||||||
lon: tileBounds.left,
|
lon: tileBounds.left,
|
||||||
lat: tileBounds.top
|
lat: tileBounds.top
|
||||||
|
|||||||
@@ -467,9 +467,8 @@
|
|||||||
t.ok(ul.lon === desiredUL.lon && ul.lat === desiredUL.lat, "correct ul passed to translation");
|
t.ok(ul.lon === desiredUL.lon && ul.lat === desiredUL.lat, "correct ul passed to translation");
|
||||||
return translatedPX;
|
return translatedPX;
|
||||||
},
|
},
|
||||||
getResolution: function() {
|
getResolution:function(){return 1;}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var newTile = {
|
var newTile = {
|
||||||
draw: function() {
|
draw: function() {
|
||||||
@@ -528,7 +527,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
//test bound fully contains the maxExtent
|
//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);
|
layer.maxExtent = new OpenLayers.Bounds(0,20,40,90);
|
||||||
desiredTileBounds = new OpenLayers.Bounds(0,20,40,90);
|
desiredTileBounds = new OpenLayers.Bounds(0,20,40,90);
|
||||||
translatedPX = {x:0,y:90};
|
translatedPX = {x:0,y:90};
|
||||||
@@ -536,9 +535,10 @@
|
|||||||
|
|
||||||
//test bound overlaps the maxExtent
|
//test bound overlaps the maxExtent
|
||||||
bounds = new OpenLayers.Bounds(-10,10,50,100);
|
bounds = new OpenLayers.Bounds(-10,10,50,100);
|
||||||
layer.maxExtent = new OpenLayers.Bounds(-30,20,40,110);
|
//with ratio applied tile bounds are -40,-35,80,145
|
||||||
desiredTileBounds = new OpenLayers.Bounds(-10,20,40,100);
|
layer.maxExtent = new OpenLayers.Bounds(-50,20,40,150);
|
||||||
translatedPX = {x:-10,y:100};
|
desiredTileBounds = new OpenLayers.Bounds(-40,20,40,145);
|
||||||
|
translatedPX = {x:-40,y:145};
|
||||||
layer.grid = [[ tile ]];
|
layer.grid = [[ tile ]];
|
||||||
layer.initSingleTile(bounds);
|
layer.initSingleTile(bounds);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user