[OpenLayers-Commits] r7333 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Format/SLD tests/Format/SLD
commits at openlayers.org
commits at openlayers.org
Mon Jun 9 13:18:35 EDT 2008
Author: tschaub
Date: 2008-06-09 13:18:35 -0400 (Mon, 09 Jun 2008)
New Revision: 7333
Modified:
trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js
trunk/openlayers/lib/OpenLayers/Style.js
trunk/openlayers/tests/Format/SLD/v1_0_0.html
Log:
Adding support for TextSymbolizer writing in the SLD format. Thanks to Bart for the original patch. This provides basic expression handling for text labels. Read support later. r=ahocevar (closes #1542)
Modified: trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js 2008-06-09 12:30:44 UTC (rev 7332)
+++ trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js 2008-06-09 17:18:35 UTC (rev 7333)
@@ -425,7 +425,9 @@
"stroke-width": "strokeWidth",
"stroke-linecap": "strokeLinecap",
"fill": "fillColor",
- "fill-opacity": "fillOpacity"
+ "fill-opacity": "fillOpacity",
+ "font-family": "fontFamily",
+ "font-size": "fontSize"
},
/**
@@ -732,6 +734,68 @@
value: obj.symbolizer[obj.key]
});
},
+ "TextSymbolizer": function(symbolizer) {
+ var node = this.createElementNSPlus("TextSymbolizer");
+ // add in optional Label
+ if(symbolizer.label != null) {
+ this.writeNode(node, "Label", symbolizer.label);
+ }
+ // add in optional Font
+ if(symbolizer.fontFamily != null ||
+ symbolizer.fontSize != null) {
+ this.writeNode(node, "Font", symbolizer);
+ }
+ // add in optional Fill
+ if(symbolizer.fillColor != null ||
+ symbolizer.fillOpacity != null) {
+ this.writeNode(node, "Fill", symbolizer);
+ }
+ return node;
+ },
+ "Font": function(symbolizer) {
+ var node = this.createElementNSPlus("Font");
+ // add in CssParameters
+ if(symbolizer.fontFamily) {
+ this.writeNode(
+ node, "CssParameter",
+ {symbolizer: symbolizer, key: "fontFamily"}
+ );
+ }
+ if(symbolizer.fontSize) {
+ this.writeNode(
+ node, "CssParameter",
+ {symbolizer: symbolizer, key: "fontSize"}
+ );
+ }
+ return node;
+ },
+ "Label": function(label) {
+ // only the simplest of ogc:expression handled
+ // {label: "some text and a ${propertyName}"}
+ var node = this.createElementNSPlus("Label");
+ var tokens = label.split("${");
+ node.appendChild(this.createTextNode(tokens[0]));
+ var item, last;
+ for(var i=1; i<tokens.length; i++) {
+ item = tokens[i];
+ last = item.indexOf("}");
+ if(last > 0) {
+ this.writeNode(
+ node, "ogc:PropertyName",
+ {property: item.substring(0, last)}
+ );
+ node.appendChild(
+ this.createTextNode(item.substring(++last))
+ );
+ } else {
+ // no ending }, so this is a literal ${
+ node.appendChild(
+ this.createTextNode("${" + item)
+ );
+ }
+ }
+ return node;
+ },
"PolygonSymbolizer": function(symbolizer) {
var node = this.createElementNSPlus("PolygonSymbolizer");
this.writeNode(node, "Fill", symbolizer);
Modified: trunk/openlayers/lib/OpenLayers/Style.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Style.js 2008-06-09 12:30:44 UTC (rev 7332)
+++ trunk/openlayers/lib/OpenLayers/Style.js 2008-06-09 17:18:35 UTC (rev 7333)
@@ -353,4 +353,4 @@
* {Array} prefixes of the sld symbolizers. These are the
* same as the main geometry types
*/
-OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];
+OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon', 'Text'];
Modified: trunk/openlayers/tests/Format/SLD/v1_0_0.html
===================================================================
--- trunk/openlayers/tests/Format/SLD/v1_0_0.html 2008-06-09 12:30:44 UTC (rev 7332)
+++ trunk/openlayers/tests/Format/SLD/v1_0_0.html 2008-06-09 17:18:35 UTC (rev 7333)
@@ -150,6 +150,42 @@
}
+ function test_writeTextSymbolizer(t) {
+ t.plan(1);
+ var parser = new OpenLayers.Format.SLD.v1_0_0();
+ var symbolizer = {
+ "Text": {
+ "label": "This is the ${city} in ${state}.",
+ "fontFamily": "Arial",
+ "fontSize": 10,
+ "fillColor": "blue"
+ }
+ };
+ var node = parser.writers["sld"]["TextSymbolizer"].apply(
+ parser, [symbolizer["Text"]]
+ );
+
+ var expected =
+ '<TextSymbolizer xmlns="http://www.opengis.net/sld">' +
+ '<Label>' +
+ 'This is the ' +
+ '<ogc:PropertyName xmlns:ogc="http://www.opengis.net/ogc">city</ogc:PropertyName>' +
+ ' in ' +
+ '<ogc:PropertyName xmlns:ogc="http://www.opengis.net/ogc">state</ogc:PropertyName>' +
+ '.' +
+ '</Label>' +
+ '<Font>' +
+ '<CssParameter name="font-family">Arial</CssParameter>' +
+ '<CssParameter name="font-size">10</CssParameter>' +
+ '</Font>' +
+ '<Fill>' +
+ '<CssParameter name="fill">blue</CssParameter>' +
+ '</Fill>' +
+ '</TextSymbolizer>';
+
+ t.xml_eq(node, expected, "TextSymbolizer correctly written");
+
+ }
</script>
</head>
More information about the Commits
mailing list