Fixed styleNames creation for layers with mixed strings and arrays.

Thanks dwins for spotting this and the quick patch, which, btw, was 
perfect (i.e. with unit tests that show the problem). r=me (closes #2025)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@9161 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2009-04-01 15:39:58 +00:00
parent b1c11b9814
commit bfc17248e9
2 changed files with 64 additions and 6 deletions

View File

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

View File

@@ -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;
}
</script>
</head>
<body>