Added parseFloat for quantity and opacity on read, as suggested in bartvde's review. With additional tests to show that everything works as suggested now. See #2642.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10349 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-05-20 21:57:13 +00:00
parent 5f96b1f914
commit d57b603d07
2 changed files with 12 additions and 6 deletions

View File

@@ -226,11 +226,13 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
this.readChildNodes(node, symbolizer.colorMap);
},
"ColorMapEntry": function(node, colorMap) {
var q = node.getAttribute("quantity");
var o = node.getAttribute("opacity");
colorMap.push({
color: node.getAttribute("color"),
quantity: node.getAttribute("quantity") || undefined,
quantity: q !== null ? parseFloat(q) : undefined,
label: node.getAttribute("label") || undefined,
opacity: node.getAttribute("opacity") || undefined
opacity: o !== null ? parseFloat(o) : undefined
});
},
"LineSymbolizer": function(node, rule) {
@@ -838,11 +840,11 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
var node = this.createElementNSPlus("sld:ColorMapEntry");
var a = colorMapEntry;
node.setAttribute("color", a.color);
a.opacity && node.setAttribute("opacity",
a.opacity !== undefined && node.setAttribute("opacity",
parseFloat(a.opacity));
a.quantity && node.setAttribute("quantity",
a.quantity !== undefined && node.setAttribute("quantity",
parseFloat(a.quantity));
a.label && node.setAttribute("label", a.label);
a.label !== undefined && node.setAttribute("label", a.label);
return node;
},
"PolygonSymbolizer": function(symbolizer) {

View File

@@ -410,7 +410,7 @@
}
function test_RasterSymbolizer(t) {
t.plan(1);
t.plan(4);
var format = new OpenLayers.Format.SLD.v1_0_0();
@@ -431,6 +431,10 @@
var symbolizer = {};
format.readNode(expected, {symbolizer: symbolizer});
t.eq(symbolizer.Raster.colorMap[0].quantity, 0, "quantity set correctly");
t.eq(symbolizer.Raster.colorMap[0].opacity, 0.5, "opacity set correctly");
t.eq(symbolizer.Raster.colorMap[1].opacity, undefined, "non-existent opacity results in undefined");
var got = format.writeNode("sld:RasterSymbolizer", symbolizer["Raster"]);
t.xml_eq(got, expected, "Successfully round tripped RasterSymbolizer");