Enforcing existing zoomToExtent behavior.

The Map.html and WrapDateLine.html tests that check zoomToExtent were failing with the changes to this method.  These test changes make the expectations more explicit.  It is inconsistent to call wrapDateLine only in zoomToExtent, but this is the minimum change to get the tests passing again.  It would be more consistent to call wrapDateLine in the setCenter sequence.
This commit is contained in:
Tim Schaub
2011-10-11 21:14:07 -06:00
parent ea8404c3bd
commit 6af8178452
2 changed files with 77 additions and 45 deletions
+1 -1
View File
@@ -2226,7 +2226,7 @@ OpenLayers.Map = OpenLayers.Class({
// 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. // for the center.
// //
center = bounds.getCenterLonLat(); center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
} }
this.setCenter(center, this.getZoomForExtent(bounds, closest)); this.setCenter(center, this.getZoomForExtent(bounds, closest));
}, },
+70 -38
View File
@@ -1386,55 +1386,87 @@
} }
function test_Map_zoomToExtent(t) { function test_Map_zoomToExtent(t) {
t.plan(8); t.plan(9);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer(null, {isBaseLayer: true});
map.addLayer(layer);
var m = { var bounds = new OpenLayers.Bounds(-160, 15, -50, 69);
'baseLayer': { var center;
'wrapDateLine': false
}, // default for closest
'setCenter': function(center, zoomLevel) { map.zoomToExtent(bounds);
g_Center = center; center = map.getCenter();
g_ZoomLevel = zoomLevel; t.eq(center.lon, -105, "a) correct x");
}, t.eq(center.lat, 42, "a) correct y");
'getZoomForExtent': function(bounds, closest) { t.eq(map.getZoom(), 2, "a) correct zoom");
t.ok(bounds.equals(g_ToCenterBounds), "bounds correctly passed into getZoomForExtent()");
t.ok(closest == g_Closest, "closest correctly passed along to getZoomForExtent()"); // false for closest
return g_ZoomLevelReturn; map.zoomToExtent(bounds, false);
center = map.getCenter();
t.eq(center.lon, -105, "b) correct x");
t.eq(center.lat, 42, "b) correct y");
t.eq(map.getZoom(), 2, "b) correct zoom");
// true for closest
map.zoomToExtent(bounds, true);
center = map.getCenter();
t.eq(center.lon, -105, "c) correct x");
t.eq(center.lat, 42, "c) correct y");
t.eq(map.getZoom(), 3, "c) correct zoom");
map.destroy();
} }
};
//no wrapDateLine function test_Map_zoomToExtent_wrapped(t) {
g_ZoomLevelReturn = {}; t.plan(9);
g_Bounds = new OpenLayers.Bounds(-20,-15,0,5);
g_ExpectedCenter = new OpenLayers.LonLat(-10,-5);
g_Closest = {};
g_ToCenterBounds = g_Bounds;
var args = [g_Bounds, g_Closest];
OpenLayers.Map.prototype.zoomToExtent.apply(m, args);
t.ok(g_Center.equals(g_ExpectedCenter), "setCenter called on correct center"); var map = new OpenLayers.Map("map");
t.ok(g_ZoomLevel == g_ZoomLevelReturn, "correctly passes along zoom level as returned from getZoomForExtent()"); var layer = new OpenLayers.Layer(null, {isBaseLayer: true, wrapDateLine: true});
map.addLayer(layer);
var bounds, center;
//wrapDateLine var cases = [{
m.baseLayer.wrapDateLine = true; // real world
m.getMaxExtent = function() { return new OpenLayers.Bounds(-200,-200,200,200); }; bbox: [120, -20, 140, 0],
center: [130, -10]
g_ZoomLevelReturn = {}; }, {
g_BoundsCenter = {}; // one world to the right
g_Bounds = new OpenLayers.Bounds(160,-60,-60,60); bbox: [220, -45, 240, 45],
g_ExpectedCenter = new OpenLayers.LonLat(-150,0); center: [-130, 0]
g_Closest = {}; }, {
g_ToCenterBounds = new OpenLayers.Bounds(160,-60,340,60); // two worlds to the right
var args = [g_Bounds, g_Closest]; bbox: [550, -15, 560, 5],
OpenLayers.Map.prototype.zoomToExtent.apply(m, args); center: [-165, -5]
t.ok(g_Center.equals(g_ExpectedCenter), "setCenter called on correct center"); }, {
t.ok(g_ZoomLevel == g_ZoomLevelReturn, "correctly passes along zoom level as returned from getZoomForExtent()"); // one world to the left
bbox: [-240, -15, -220, 5],
center: [130, -5]
}, {
// two worlds to the left
bbox: [-600, -15, -580, 5],
center: [130, -5]
}];
var num = cases.length;
t.plan(num * 2);
var c, bounds, center;
for (var i=0; i<num; ++i) {
c = cases[i];
bounds = OpenLayers.Bounds.fromArray(c.bbox);
map.zoomToExtent(bounds);
center = map.getCenter();
t.eq(center.lon, c.center[0], "y: " + bounds);
t.eq(center.lat, c.center[1], "x: " + bounds);
} }
map.destroy();
}
function test_allOverlays(t) { function test_allOverlays(t) {
t.plan(18); t.plan(18);