diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index adf2fc25d1..45a21a57e6 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1749,7 +1749,12 @@ OpenLayers.Map = OpenLayers.Class({ } } if (this.baseLayer.wrapDateLine) { + var requestedZoom = zoom; zoom = this.adjustZoom(zoom); + if (zoom !== requestedZoom) { + // zoom was adjusted, so keep old lonlat to avoid panning + lonlat = this.getCenter(); + } } // dragging is false by default var dragging = options.dragging || this.dragging; diff --git a/tests/Map.html b/tests/Map.html index 856434ac6d..faad0b30c7 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -380,11 +380,13 @@ */ function test_Map_isValidZoomLevel(t) { - t.plan(4); + t.plan(5); var map = new OpenLayers.Map("map"); map.addLayer(new OpenLayers.Layer(null, { - isBaseLayer: true, numZoomLevels: 19 - })) + isBaseLayer: true, wrapDateLine: true, numZoomLevels: 19 + })); + map.zoomToMaxExtent(); + var valid; valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [-1]); @@ -398,6 +400,9 @@ valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [19]); t.eq(valid, false, "19 is not a valid zoomLevel"); + + map.moveTo([16, 48], 0); + t.eq(map.getCenter().toShortString(), "0, 0", "no panning when moveTo is called with invalid zoom"); map.destroy(); } @@ -1966,7 +1971,7 @@ } function test_adjustZoom(t) { - t.plan(3); + t.plan(4); var map = new OpenLayers.Map({ div: 'map', layers: [ @@ -1981,6 +1986,9 @@ t.eq(map.adjustZoom(9), 9, "valid zoom maintained"); t.eq(map.adjustZoom(1), 2, "zoom adjusted to not exceed world width"); + + map.moveTo([16, 48], 0); + t.eq(map.getCenter().toShortString(), "0, 0", "no panning when moveTo is called with invalid zoom"); }