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
This commit is contained in:
crschmidt
2006-06-30 23:59:42 +00:00
parent c958f9f88a
commit 2117aa0539
4 changed files with 78 additions and 0 deletions

42
examples/wmst.html Normal file
View File

@@ -0,0 +1,42 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#map {
width: 512px;
height: 400px;
border: 1px solid black;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
<!--
var map,ia_wms;
function init(){
map = new OpenLayers.Map('map');
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} );
var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
"http://wms.jpl.nasa.gov/wms.cgi",
{layers: "modis,global_mosaic"});
ia_wms = new OpenLayers.Layer.WMS("Nexrad","http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?",{layers:"nexrad-n0r-wmst",transparent:true,format:'image/png',time:document.getElementById('time').value});
jpl_wms.setVisibility(false);
map.addLayers([ol_wms, jpl_wms, ia_wms]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
// -->
</script>
</head>
<body onload="init()">
<h1>OpenLayers Example</h1>
<p>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!</p>
<input type='text' id='time' value="2005-08-29T13:00:00Z" onChange='ia_wms.changeParams({"time":this.value});' >
<div id="map"></div>
</body>
</html>

View File

@@ -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

View File

@@ -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"
});

View File

@@ -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) {