diff --git a/lib/OpenLayers/Control/WMSGetFeatureInfo.js b/lib/OpenLayers/Control/WMSGetFeatureInfo.js index a35940af3b..ec62dffc66 100644 --- a/lib/OpenLayers/Control/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Control/WMSGetFeatureInfo.js @@ -79,6 +79,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { * } * (end) */ + vendorParams: {}, /** * Property: formats @@ -284,8 +285,15 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { // specifying styles,we need the same number of commas to specify // the default style for each of the layers. We can't just leave it // blank as we may be including other layers that do specify styles. - styleNames = styleNames.concat(layers[i].params.STYLES || - layers[i].params.LAYERS.replace(/[^,]/g,"")); + if (layers[i].params.STYLES) { + styleNames = styleNames.concat(layers[i].params.STYLES); + } else { + if (layers[i].params.LAYERS instanceof Array) { + styleNames = styleNames.concat(new Array(layers[i].params.LAYERS.length)); + } else { // Assume it's a String + styleNames = styleNames.concat(layers[i].params.LAYERS.replace(/[^,]/g, "")); + } + } } var wmsOptions = { diff --git a/tests/Control/WMSGetFeatureInfo.html b/tests/Control/WMSGetFeatureInfo.html index 1fe5d359b3..d611d83d54 100644 --- a/tests/Control/WMSGetFeatureInfo.html +++ b/tests/Control/WMSGetFeatureInfo.html @@ -73,7 +73,7 @@ function test_Control_WMSGetFeatureInfo_request(t) { t.plan(1); var map = new OpenLayers.Map('map', { - getExtent: return(new OpenLayers.Bounds(-180,-90,180,90)); + getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));} }); var _request = OpenLayers.Request.GET; @@ -81,7 +81,9 @@ t.eq(options.params.RADIUS, 5, "vendor params passed correctly"); } // mock up active control - var control = new OpenLayers.Control.WMSGetFeatureInfo(); + var control = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms',{ + vendorParams:{ RADIUS: 5} + }); map.addControl(control); control.activate(); @@ -95,7 +97,7 @@ var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', { featureType: 'type', featureNS: 'http://localhost/ns', - layers: 'ns:type', + layers: 'ns:type' }); var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', { featureType: 'type', @@ -231,7 +233,7 @@ var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', { featureType: 'type', featureNS: 'http://localhost/ns', - layers: 'ns:type', + layers: 'ns:type' }); var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', { featureType: 'type', @@ -285,6 +287,54 @@ hover.deactivate(); } + // Verify that things work all right when we combine different types for the STYLES and LAYERS + // params in the WMS Layers involved + function test_Control_WMSGetFeatureInfo_MixedParams(t) { + t.plan(1); + var map = new OpenLayers.Map("map", { + getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));} + } + ); + + var a = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", { + layers: "a,b,c,d", + styles: "a,b,c,d" + }); + + var b = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", { + layers: ["a","b","c","d"], + styles: ["a","b","c","d"] + }); + + var c = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", { + layers: ["a","b","c","d"] + }); + + var d = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", { + layers: "a,b,c,d" + }); + + var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", { + featureType: 'type', + featureNS: 'ns', + layers: [a, b, c, d] + }); + + map.addControl(click); + + var _request = OpenLayers.Request.GET; + OpenLayers.Request.GET = function(options) { + t.eq( + options.params.styles.join(","), "a,b,c,d,a,b,c,d,,,,,,,,", + "Styles merged correctly" + ); + }; + + click.activate(); + click.getInfoForClick({xy: {x: 50, y: 50}}); + OpenLayers.Request.GET = _request; + } +