always start the map extent on the right of the dateline

This commit is contained in:
ahocevar
2011-09-29 10:03:02 -06:00
parent 949a5db60e
commit c53374c797
+13 -5
View File
@@ -1941,6 +1941,17 @@ OpenLayers.Map = OpenLayers.Class({
if (lonlat != null) { if (lonlat != null) {
var maxExtent = this.getMaxExtent(); var maxExtent = this.getMaxExtent();
valid = maxExtent.containsLonLat(lonlat); valid = maxExtent.containsLonLat(lonlat);
if (!valid && this.baseLayer.wrapDateLine) {
lonlat = lonlat.clone();
var worldWidth = maxExtent.getWidth();
while(lonlat.lon > maxExtent.right) {
lonlat.lon -= worldWidth;
valid = maxExtent.containsLonLat(lonlat);
if (valid) {
break;
}
}
}
} }
return valid; return valid;
}, },
@@ -2254,12 +2265,9 @@ OpenLayers.Map = OpenLayers.Class({
} }
//if the bounds was straddling (see above), then the center point //if the bounds was straddling (see above), then the center point
// we got from it was wrong. So we take our new bounds and ask it // we got from it was wrong. So we take our new bounds and ask it
// for the center. Because our new bounds is at least partially // for the center.
// outside the bounds of maxExtent, the new calculated center
// might also be. We don't want to pass a bad center value to
// setCenter, so we have it wrap itself across the date line.
// //
center = bounds.getCenterLonLat().wrapDateLine(maxExtent); center = bounds.getCenterLonLat();
} }
this.setCenter(center, this.getZoomForExtent(bounds, closest)); this.setCenter(center, this.getZoomForExtent(bounds, closest));
}, },