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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user