From 2117aa053919d6389d5c602287df629fc6d095cf Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 30 Jun 2006 23:59:42 +0000 Subject: [PATCH] Commit a 'changeParams' method, along with test and example, to show how it would be possible to use WMS-T with changeParams. ChangeParams sets the new params, then recalls initTiles with the new params set. git-svn-id: http://svn.openlayers.org/trunk/openlayers@843 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/wmst.html | 42 +++++++++++++++++++++++++++++ lib/OpenLayers/Layer/Grid.js | 10 +++++++ lib/OpenLayers/Layer/WMS/Untiled.js | 11 ++++++++ tests/test_Layer_WMS.html | 15 +++++++++++ 4 files changed, 78 insertions(+) create mode 100644 examples/wmst.html diff --git a/examples/wmst.html b/examples/wmst.html new file mode 100644 index 0000000000..129b0b0667 --- /dev/null +++ b/examples/wmst.html @@ -0,0 +1,42 @@ + + + + + + + +

OpenLayers Example

+

WMS-T example: update the times, and the radar image will change. Uses Layer.changeParams. Thanks to Howard Butler for the inspiration, the original code, and the kick in the butt!

+ +
+ + + diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index d85129bf72..5cbef0d72c 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -309,6 +309,16 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { addTile:function(bounds,position) { // Should be implemented by subclasses }, + + /** + * changeParams is designed to allow you to change the + * parameters of a layer after it's created. + * @param {Object} params Hash of new params to use + */ + changeParams:function(params) { + this.params = Object.extend(this.params, OpenLayers.Util.upperCaseObject(params)); + this._initTiles(); + }, /** * @returns Degrees per Pixel diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 4486c4f02a..0aac1bca19 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -92,6 +92,17 @@ OpenLayers.Layer.WMS.Untiled.prototype = tile.draw(); } }, + + /** + * changeParams is designed to allow you to change the + * parameters of a layer after it's created. + * @param {Object} params Hash of new params to use + */ + changeParams:function(params) { + this.params = Object.extend(this.params, OpenLayers.Util.upperCaseObject(params)); + this._initTiles(); + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.WMS.Untiled" }); diff --git a/tests/test_Layer_WMS.html b/tests/test_Layer_WMS.html index 4d7e314fa1..7ee9c46487 100644 --- a/tests/test_Layer_WMS.html +++ b/tests/test_Layer_WMS.html @@ -50,6 +50,21 @@ t.eq( layer.grid.length, 4, "Grid rows is correct." ); t.eq( layer.grid[0].length, 2, "Grid cols is correct." ); + } + function test_03_Layer_WMS_changeParams (t) { + t.plan( 4 ); + var map = new OpenLayers.Map($('map')); + layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); + map.addLayer(layer); + map.setCenter(new OpenLayers.LonLat(0,0),5); + t.eq( layer.params.MAP, "/mapdata/vmap_wms.map", "Map param set to original." ); + layer.changeParams({'map':'newparam'}); + t.eq( layer.params.MAP, "newparam", "Map param changed."); + layer.changeParams({'MAP':'newparam2'}); + t.eq( layer.params.MAP, "newparam2", "Map param changed again with upper-case."); + var firstChild = layer.div.firstChild; + t.eq( firstChild.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=newparam2&LAYERS=basic&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=-11.25,11.25,0,22.5&WIDTH=256&HEIGHT=256", "div first child is correct image object after param change." ); + } function test_99_Layer_WMS_destroy (t) {