From 499c8db92af49180d983af07eb25f9ce12d168d7 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sat, 17 Feb 2007 15:00:05 +0000 Subject: [PATCH] the mergeNewParams function does not reinitialize the tiles for layers other than WMS. It should do this for any Grid layer. Ticket #496 includes a patch for this: it adds a mergeNewParams call at the Layer.Grid level, (subclassing Layer.HTTPRequest) which reinits the tile grid. This commit also includes tests for this functionality. Since testing directly on the Grid layer doesn't work (it's meant to be subclassed), we need to instead pick a second layer to test -- in this case, ka-Map. Thanks to Bill Woodall for the patch. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2237 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Grid.js | 14 ++++++++++++++ lib/OpenLayers/Layer/WMS.js | 4 ---- tests/test_Layer_KaMap.html | 25 +++++++++++++++++++++++++ tests/test_Layer_WMS.html | 8 +++++++- 4 files changed, 46 insertions(+), 5 deletions(-) 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;