Support for basic literal/propertyname combinations in SLD. r=elemoine (closes http://trac.osgeo.org/openlayers/ticket/3506)
This commit is contained in:
@@ -219,16 +219,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
}
|
||||
},
|
||||
"Label": function(node, symbolizer) {
|
||||
// only supporting literal or property name
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
if(obj.property) {
|
||||
symbolizer.label = "${" + obj.property + "}";
|
||||
} else {
|
||||
var value = this.readOgcExpression(node);
|
||||
if(value) {
|
||||
symbolizer.label = value;
|
||||
}
|
||||
var value = this.readers.ogc._expression.call(this, node);
|
||||
if (value) {
|
||||
symbolizer.label = value;
|
||||
}
|
||||
},
|
||||
"Font": function(node, symbolizer) {
|
||||
@@ -243,7 +236,7 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
symbolizer.haloOpacity = obj.fillOpacity;
|
||||
},
|
||||
"Radius": function(node, symbolizer) {
|
||||
var radius = this.readOgcExpression(node);
|
||||
var radius = this.readers.ogc._expression.call(this, node);
|
||||
if(radius != null) {
|
||||
// radius is only used for halo
|
||||
symbolizer.haloRadius = radius;
|
||||
@@ -345,7 +338,7 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
var symProperty = this.cssMap[cssProperty];
|
||||
if(symProperty) {
|
||||
// Limited support for parsing of OGC expressions
|
||||
var value = this.readOgcExpression(node);
|
||||
var value = this.readers.ogc._expression.call(this, node);
|
||||
// always string, could be an empty string
|
||||
if(value) {
|
||||
symbolizer[symProperty] = value;
|
||||
@@ -376,7 +369,13 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
symbolizer.graphicOpacity = graphic.opacity;
|
||||
}
|
||||
if(graphic.size != undefined) {
|
||||
symbolizer.pointRadius = graphic.size / 2;
|
||||
var pointRadius = graphic.size / 2;
|
||||
if (isNaN(pointRadius)) {
|
||||
// likely a property name
|
||||
symbolizer.graphicWidth = graphic.size;
|
||||
} else {
|
||||
symbolizer.pointRadius = graphic.size / 2;
|
||||
}
|
||||
}
|
||||
if(graphic.href != undefined) {
|
||||
symbolizer.externalGraphic = graphic.href;
|
||||
@@ -395,21 +394,21 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
graphic.graphicName = this.getChildValue(node);
|
||||
},
|
||||
"Opacity": function(node, obj) {
|
||||
var opacity = this.readOgcExpression(node);
|
||||
var opacity = this.readers.ogc._expression.call(this, node);
|
||||
// always string, could be empty string
|
||||
if(opacity) {
|
||||
obj.opacity = opacity;
|
||||
}
|
||||
},
|
||||
"Size": function(node, obj) {
|
||||
var size = this.readOgcExpression(node);
|
||||
var size = this.readers.ogc._expression.call(this, node);
|
||||
// always string, could be empty string
|
||||
if(size) {
|
||||
obj.size = size;
|
||||
}
|
||||
},
|
||||
"Rotation": function(node, obj) {
|
||||
var rotation = this.readOgcExpression(node);
|
||||
var rotation = this.readers.ogc._expression.call(this, node);
|
||||
// always string, could be empty string
|
||||
if(rotation) {
|
||||
obj.rotation = rotation;
|
||||
@@ -530,6 +529,36 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
*/
|
||||
writers: OpenLayers.Util.applyDefaults({
|
||||
"sld": {
|
||||
"_OGCExpression": function(nodeName, value) {
|
||||
// only the simplest of ogc:expression handled
|
||||
// {label: "some text and a ${propertyName}"}
|
||||
var node = this.createElementNSPlus(nodeName);
|
||||
var tokens = typeof value == "string" ?
|
||||
value.split("${") :
|
||||
[value];
|
||||
node.appendChild(this.createTextNode(tokens[0]));
|
||||
var item, last;
|
||||
for(var i=1, len=tokens.length; i<len; i++) {
|
||||
item = tokens[i];
|
||||
last = item.indexOf("}");
|
||||
if(last > 0) {
|
||||
this.writeNode(
|
||||
"ogc:PropertyName",
|
||||
{property: item.substring(0, last)},
|
||||
node
|
||||
);
|
||||
node.appendChild(
|
||||
this.createTextNode(item.substring(++last))
|
||||
);
|
||||
} else {
|
||||
// no ending }, so this is a literal ${
|
||||
node.appendChild(
|
||||
this.createTextNode("${" + item)
|
||||
);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"StyledLayerDescriptor": function(sld) {
|
||||
var root = this.createElementNSPlus(
|
||||
"sld:StyledLayerDescriptor",
|
||||
@@ -897,32 +926,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
return node;
|
||||
},
|
||||
"Label": function(label) {
|
||||
// only the simplest of ogc:expression handled
|
||||
// {label: "some text and a ${propertyName}"}
|
||||
var node = this.createElementNSPlus("sld:Label");
|
||||
var tokens = label.split("${");
|
||||
node.appendChild(this.createTextNode(tokens[0]));
|
||||
var item, last;
|
||||
for(var i=1, len=tokens.length; i<len; i++) {
|
||||
item = tokens[i];
|
||||
last = item.indexOf("}");
|
||||
if(last > 0) {
|
||||
this.writeNode(
|
||||
"ogc:PropertyName",
|
||||
{property: item.substring(0, last)},
|
||||
node
|
||||
);
|
||||
node.appendChild(
|
||||
this.createTextNode(item.substring(++last))
|
||||
);
|
||||
} else {
|
||||
// no ending }, so this is a literal ${
|
||||
node.appendChild(
|
||||
this.createTextNode("${" + item)
|
||||
);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
return this.writers.sld._OGCExpression.call(
|
||||
this, "sld:Label", label
|
||||
);
|
||||
},
|
||||
"Halo": function(symbolizer) {
|
||||
var node = this.createElementNSPlus("sld:Halo");
|
||||
@@ -1030,6 +1036,8 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
}
|
||||
if(symbolizer.pointRadius != undefined) {
|
||||
this.writeNode("Size", symbolizer.pointRadius * 2, node);
|
||||
} else if (symbolizer.graphicWidth != undefined) {
|
||||
this.writeNode("Size", symbolizer.graphicWidth, node);
|
||||
}
|
||||
if(symbolizer.rotation != undefined) {
|
||||
this.writeNode("Rotation", symbolizer.rotation, node);
|
||||
@@ -1070,9 +1078,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
});
|
||||
},
|
||||
"Size": function(value) {
|
||||
return this.createElementNSPlus("sld:Size", {
|
||||
value: value
|
||||
});
|
||||
return this.writers.sld._OGCExpression.call(
|
||||
this, "sld:Size", value
|
||||
);
|
||||
},
|
||||
"Rotation": function(value) {
|
||||
return this.createElementNSPlus("sld:Rotation", {
|
||||
|
||||
Reference in New Issue
Block a user