diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 880f070acd..5cc262f270 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -351,6 +351,20 @@ OpenLayers.Layer.Grid.prototype = // Should be implemented by subclasses }, + /** + * Once params have been changed, we will need to re-init our tiles + * + * @param {Object} newParams Hashtable of new params to use + */ + mergeNewParams:function(newArguments) { + OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, + [newArguments]); + + if (this.map != null) { + this._initTiles(); + } + }, + /** go through and remove all tiles from the grid, calling * destroy() on each of them to kill circular references diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 68a7827bd6..91126df6ed 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -126,10 +126,6 @@ OpenLayers.Layer.WMS.prototype = var newArguments = [upperParams]; OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, newArguments); - - if (this.map != null) { - this._initTiles(); - } }, /** combine the layer's url with its params and these newParams. diff --git a/tests/test_Layer_KaMap.html b/tests/test_Layer_KaMap.html index 4638b17a3b..570209fe33 100644 --- a/tests/test_Layer_KaMap.html +++ b/tests/test_Layer_KaMap.html @@ -101,6 +101,31 @@ t.eq( zoom, 2, "getZoomForExtent() returns correct value"); } + + function test_06_Layer_kaMap_mergeNewParams (t) { + t.plan( 5 ); + + var map = new OpenLayers.Map("map"); + var url = "http://octo.metacarta.com/cgi-bin/mapserv"; + layer = new OpenLayers.Layer.KaMap(name, url, params); + + var newParams = { layers: 'sooper', + chickpeas: 'image/png'}; + + map.addLayer(layer); + map.zoomToMaxExtent(); + t.ok( !layer.grid[0][0].url.match("chickpeas"), "chickpeas is not in URL of first tile in grid" ); + + layer.mergeNewParams(newParams); + + t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well"); + t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well"); + t.ok( layer.grid[0][0].url.match("chickpeas"), "CHICKPEAS is in URL of first tile in grid" ); + + newParams.chickpeas = 151; + + t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable"); + } /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR diff --git a/tests/test_Layer_WMS.html b/tests/test_Layer_WMS.html index 0cefe1558b..744507b98a 100644 --- a/tests/test_Layer_WMS.html +++ b/tests/test_Layer_WMS.html @@ -120,18 +120,24 @@ } function test_06_Layer_WMS_mergeNewParams (t) { - t.plan( 3 ); + t.plan( 5 ); + var map = new OpenLayers.Map("map"); var url = "http://octo.metacarta.com/cgi-bin/mapserv"; layer = new OpenLayers.Layer.WMS(name, url, params); var newParams = { layers: 'sooper', chickpeas: 'image/png'}; + map.addLayer(layer); + map.zoomToMaxExtent(); + t.ok( !layer.grid[0][0].url.match("CHICKPEAS"), "CHICKPEAS is not in URL of first tile in grid" ); + layer.mergeNewParams(newParams); t.eq( layer.params.LAYERS, "sooper", "mergeNewParams() overwrites well"); t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() adds well"); + t.ok( layer.grid[0][0].url.match("CHICKPEAS"), "CHICKPEAS is in URL of first tile in grid" ); newParams.CHICKPEAS = 151;