diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 93fdc5816b..3984a3e6f6 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -8,7 +8,9 @@ OpenLayers.Layer.WMS.prototype = version: "1.1.1", request: "GetMap", srs: "EPSG:4326", - exceptions: "application/vnd.ogc.se_inimage" + styles: "", + exceptions: "application/vnd.ogc.se_inimage", + format: "image/jpeg" }, /** @@ -18,7 +20,7 @@ OpenLayers.Layer.WMS.prototype = */ initialize: function(name, url, params) { OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments); - Object.extend(this.params, this.DEFAULT_PARAMS); + OpenLayers.Util.applyDefaults( this.params, this.DEFAULT_PARAMS ); }, /** diff --git a/tests/test_Layer_WMS.html b/tests/test_Layer_WMS.html index e47f543fc9..448aca8d19 100644 --- a/tests/test_Layer_WMS.html +++ b/tests/test_Layer_WMS.html @@ -5,24 +5,27 @@ var layer; function test_01_Layer_WMS_constructor (t) { - t.plan( 4 ); + t.plan( 6 ); - layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); + layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/png'}); t.ok( layer instanceof OpenLayers.Layer.WMS, "new OpenLayers.Layer.WMS returns object" ); t.eq( layer.name, "Test Layer", "layer.name is correct" ); t.eq( layer.url, "http://octo.metacarta.com/cgi-bin/mapserv", "layer.url is correct" ); t.eq( layer.params.map, "/mapdata/vmap_wms.map", "layer.params.map is correct" ); + t.eq( layer.params.format, "image/png", "layer.params.format is correctly overridden" ); + t.eq( layer.params.exceptions, "application/vnd.ogc.se_inimage", + "other default layer.params are set correctly" ); } function test_02_Layer_WMS_addtile (t) { t.plan( 6 ); layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); var pixel = new OpenLayers.Pixel(5,6); var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); - t.eq( tile.img.src, "http://octo.metacarta.com/cgi-bin/mapserv?bbox=1,2,3,4&width=256&height=256&map=/mapdata/vmap_wms.map&layers=basic&format=image/jpeg&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:4326&exceptions=application/vnd.ogc.se_inimage", "image src is created correctly via addtile" ); + t.eq( tile.img.src, "http://octo.metacarta.com/cgi-bin/mapserv?bbox=1,2,3,4&width=256&height=256&map=/mapdata/vmap_wms.map&layers=basic&format=image/jpeg&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:4326&styles=&exceptions=application/vnd.ogc.se_inimage", "image src is created correctly via addtile" ); t.eq( tile.img.style.top, "6px", "image top is set correctly via addtile" ); t.eq( tile.img.style.left, "5px", "image top is set correctly via addtile" ); t.ok( layer.div.firstChild instanceof HTMLImageElement, "div first child is an image object" ); - t.eq( layer.div.firstChild.src, "http://octo.metacarta.com/cgi-bin/mapserv?bbox=1,2,3,4&width=256&height=256&map=/mapdata/vmap_wms.map&layers=basic&format=image/jpeg&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:4326&exceptions=application/vnd.ogc.se_inimage", "div first child is correct image object" ); + t.eq( layer.div.firstChild.src, "http://octo.metacarta.com/cgi-bin/mapserv?bbox=1,2,3,4&width=256&height=256&map=/mapdata/vmap_wms.map&layers=basic&format=image/jpeg&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:4326&styles=&exceptions=application/vnd.ogc.se_inimage", "div first child is correct image object" ); var pos = tile.getPosition(); t.eq( pos.toString(), "x=5,y=6", "Position of tile is set correctly." ); }