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:
@@ -226,11 +226,13 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
|||||||
this.readChildNodes(node, symbolizer.colorMap);
|
this.readChildNodes(node, symbolizer.colorMap);
|
||||||
},
|
},
|
||||||
"ColorMapEntry": function(node, colorMap) {
|
"ColorMapEntry": function(node, colorMap) {
|
||||||
|
var q = node.getAttribute("quantity");
|
||||||
|
var o = node.getAttribute("opacity");
|
||||||
colorMap.push({
|
colorMap.push({
|
||||||
color: node.getAttribute("color"),
|
color: node.getAttribute("color"),
|
||||||
quantity: node.getAttribute("quantity") || undefined,
|
quantity: q !== null ? parseFloat(q) : undefined,
|
||||||
label: node.getAttribute("label") || undefined,
|
label: node.getAttribute("label") || undefined,
|
||||||
opacity: node.getAttribute("opacity") || undefined
|
opacity: o !== null ? parseFloat(o) : undefined
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"LineSymbolizer": function(node, rule) {
|
"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 node = this.createElementNSPlus("sld:ColorMapEntry");
|
||||||
var a = colorMapEntry;
|
var a = colorMapEntry;
|
||||||
node.setAttribute("color", a.color);
|
node.setAttribute("color", a.color);
|
||||||
a.opacity && node.setAttribute("opacity",
|
a.opacity !== undefined && node.setAttribute("opacity",
|
||||||
parseFloat(a.opacity));
|
parseFloat(a.opacity));
|
||||||
a.quantity && node.setAttribute("quantity",
|
a.quantity !== undefined && node.setAttribute("quantity",
|
||||||
parseFloat(a.quantity));
|
parseFloat(a.quantity));
|
||||||
a.label && node.setAttribute("label", a.label);
|
a.label !== undefined && node.setAttribute("label", a.label);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PolygonSymbolizer": function(symbolizer) {
|
"PolygonSymbolizer": function(symbolizer) {
|
||||||
|
|||||||
@@ -410,7 +410,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_RasterSymbolizer(t) {
|
function test_RasterSymbolizer(t) {
|
||||||
t.plan(1);
|
t.plan(4);
|
||||||
|
|
||||||
var format = new OpenLayers.Format.SLD.v1_0_0();
|
var format = new OpenLayers.Format.SLD.v1_0_0();
|
||||||
|
|
||||||
@@ -431,6 +431,10 @@
|
|||||||
var symbolizer = {};
|
var symbolizer = {};
|
||||||
format.readNode(expected, {symbolizer: 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"]);
|
var got = format.writeNode("sld:RasterSymbolizer", symbolizer["Raster"]);
|
||||||
|
|
||||||
t.xml_eq(got, expected, "Successfully round tripped RasterSymbolizer");
|
t.xml_eq(got, expected, "Successfully round tripped RasterSymbolizer");
|
||||||
|
|||||||
Reference in New Issue
Block a user