diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 407ad14fc4..646f6b4232 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -274,13 +274,28 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { // We want to redraw whenever even the slightest part of the // current bounds is not contained by our tile. // (thus, we do not specify partial -- its default is false) + if ( forceReTile || (!dragging && !tilesBounds.containsBounds(bounds))) { + + // In single tile mode with no transition effect, we insert + // a non-scaled backbuffer when the layer is moved. But if + // a zoom occurs right after a move, i.e. before the new + // image is received, we need to remove the backbuffer, or + // an ill-positioned image will be visible during the zoom + // transition. + + if(lastResolution !== serverResolution && + this.transitionEffect !== 'resize') { + this.removeBackBuffer(); + } + if(lastResolution === serverResolution || (lastResolution && this.transitionEffect === 'resize')) { this.applyBackBuffer(serverResolution); } + this.initSingleTile(bounds); } } else { diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 0e9852d9a7..84680826a1 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -1033,6 +1033,45 @@ map.destroy(); } + function test_singleTile_move_and_zoom(t) { + + // + // In single tile mode with no transition effect, we insert a non-scaled + // backbuffer when the layer is moved. But if a zoom occurs right after + // a move, i.e. before the new image is received, we need to remove the + // backbuffer, or an ill-positioned image will be visible during the + // zoom transition. + // + + t.plan(2); + + var map = new OpenLayers.Map('map'); + var layer = new OpenLayers.Layer.WMS('', '', {}, { + isBaseLayer: true, + singleTile: true, + ratio: 1 + }); + map.addLayer(layer); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); + + // pretend the image has been loaded + layer.updateBackBufferData(); + layer.grid[0][0].isLoading = false; // this is to be able to create + // a back buffer + + // move + map.setCenter(new OpenLayers.LonLat(10, 10)); + t.ok(layer.backBuffer && layer.backBuffer.parentNode === layer.div, + 'backbuffer inserted after map move'); + + // zoom + map.zoomTo(1); + t.eq(layer.backBuffer, null, + 'back buffer removed when zooming'); + + map.destroy(); + } + function test_backbuffer_scaled_layer(t) { t.plan(15);