only change bounds when wrapDateLine is true; remove unused variable

This commit is contained in:
ahocevar
2011-09-27 07:37:08 -06:00
parent 6925ac0ab1
commit 61a3c2a072
4 changed files with 117 additions and 7 deletions

View File

@@ -103,7 +103,7 @@ OpenLayers.Tile = OpenLayers.Class({
initialize: function(layer, position, bounds, url, size, options) {
this.layer = layer;
this.position = position.clone();
this.bounds = bounds.clone();
this.setBounds(bounds);
this.url = url;
if (size) {
this.size = size.clone();
@@ -171,14 +171,58 @@ OpenLayers.Tile = OpenLayers.Class({
* Returns:
* {Boolean} Whether or not the tile should actually be drawn.
*/
shouldDraw: function() {
var maxExtent = this.layer.maxExtent;
var withinMaxExtent = (maxExtent &&
this.bounds.intersectsBounds(maxExtent, false));
shouldDraw: function() {
var withinMaxExtent = false,
maxExtent = this.layer.maxExtent;
if (maxExtent) {
// prepare up to 3 versions of the layer's maxExtent, to make sure
// that the intersectsBounds check below catches all cases of
// extents that cross the dateline:
// (1) left bound positive, right bound negative (wrapped)
// (2) left bound positive, right bound positive (exceeding world)
// (3) left bound negative (exceeding world), right bound positive
var maxExtents = [maxExtent];
if (this.layer.map.baseLayer.wrapDateLine) {
var worldExtentWidth = this.layer.map.getMaxExtent().getWidth();
maxExtent = this.layer.maxExtent.clone();
if (maxExtent.left > maxExtent.right) {
maxExtent.left -= worldExtentWidth;
}
maxExtents.push(maxExtent);
maxExtent = this.layer.maxExtent.clone();
if (maxExtent.right < maxExtent.left) {
maxExtent.right += worldExtentWidth;
}
maxExtents.push(maxExtent);
}
for (var i=maxExtents.length-1; i>=0; --i) {
if (this.bounds.intersectsBounds(maxExtents[i], false)) {
withinMaxExtent = true;
break;
}
}
}
return withinMaxExtent || this.layer.displayOutsideMaxExtent;
},
/**
* Method: setBounds
* Sets the bounds on this instance
*
* Parameters:
* bounds {<OpenLayers.Bounds>}
*/
setBounds: function(bounds) {
bounds = bounds.clone();
var maxExtent = this.layer.maxExtent,
worldExtent = this.layer.map.getMaxExtent();
if (maxExtent && this.layer.map.baseLayer.wrapDateLine) {
bounds = bounds.wrapDateLine(worldExtent);
}
this.bounds = bounds;
},
/**
* Method: moveTo
* Reposition the tile.
@@ -194,7 +238,7 @@ OpenLayers.Tile = OpenLayers.Class({
redraw = true;
}
this.bounds = bounds.clone();
this.setBounds(bounds);
this.position = position.clone();
if (redraw) {
this.draw();