From c53374c797b3eabce6b288c39743ccdde3e1e686 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 29 Sep 2011 10:03:02 -0600 Subject: [PATCH] always start the map extent on the right of the dateline --- lib/OpenLayers/Map.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index cad15bf620..78eb0c3f74 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1940,7 +1940,18 @@ OpenLayers.Map = OpenLayers.Class({ var valid = false; if (lonlat != null) { 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; }, @@ -2254,12 +2265,9 @@ OpenLayers.Map = OpenLayers.Class({ } //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 - // for the center. Because our new bounds is at least partially - // 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. + // for the center. // - center = bounds.getCenterLonLat().wrapDateLine(maxExtent); + center = bounds.getCenterLonLat(); } this.setCenter(center, this.getZoomForExtent(bounds, closest)); },