diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 78b35da424..360c7868d1 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -287,6 +287,7 @@ "OpenLayers/Format/SLD.js", "OpenLayers/Format/SLD/v1.js", "OpenLayers/Format/SLD/v1_0_0.js", + "OpenLayers/Format/SLD/v1_0_0_GeoServer.js", "OpenLayers/Format/OWSCommon.js", "OpenLayers/Format/OWSCommon/v1.js", "OpenLayers/Format/OWSCommon/v1_0_0.js", diff --git a/lib/OpenLayers/Format/SLD.js b/lib/OpenLayers/Format/SLD.js index 20e8abf79f..2149b0a516 100644 --- a/lib/OpenLayers/Format/SLD.js +++ b/lib/OpenLayers/Format/SLD.js @@ -23,6 +23,15 @@ */ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { + /** + * APIProperty: profile + * {String} If provided, use a custom profile. + * + * Currently supported profiles: + * - GeoServer - parses GeoServer vendor specific capabilities for SLD. + */ + profile: null, + /** * APIProperty: defaultVersion * {String} Version number to assume if none found. Default is "1.0.0". diff --git a/lib/OpenLayers/Format/SLD/v1.js b/lib/OpenLayers/Format/SLD/v1.js index be1ce6effd..a6fe969c4a 100644 --- a/lib/OpenLayers/Format/SLD/v1.js +++ b/lib/OpenLayers/Format/SLD/v1.js @@ -338,6 +338,15 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { "CssParameter": function(node, symbolizer) { var cssProperty = node.getAttribute("name"); var symProperty = this.cssMap[cssProperty]; + // for labels, fill should map to fontColor and fill-opacity + // to fontOpacity + if (symbolizer.label) { + if (cssProperty === 'fill') { + symProperty = "fontColor"; + } else if (cssProperty === 'fill-opacity') { + symProperty = "fontOpacity"; + } + } if(symProperty) { // Limited support for parsing of OGC expressions var value = this.readers.ogc._expression.call(this, node); @@ -888,9 +897,12 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { this.writeNode("Halo", symbolizer, node); } // add in optional Fill - if(symbolizer.fillColor != null || - symbolizer.fillOpacity != null) { - this.writeNode("Fill", symbolizer, node); + if(symbolizer.fontColor != null || + symbolizer.fontOpacity != null) { + this.writeNode("Fill", { + fillColor: symbolizer.fontColor, + fillOpacity: symbolizer.fontOpacity + }, node); } return node; }, diff --git a/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js new file mode 100644 index 0000000000..49596be1c4 --- /dev/null +++ b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js @@ -0,0 +1,142 @@ +/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the Clear BSD license. + * See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + +/** + * @requires OpenLayers/Format/SLD/v1_0_0.js + */ + +/** + * Class: OpenLayers.Format.SLD/v1_0_0_GeoServer + * Read and write SLD version 1.0.0 with GeoServer-specific enhanced options. + * See http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-sld/src/main/resources/org/geotools/sld/bindings/StyledLayerDescriptor.xsd + * for more information. + * + * Inherits from: + * - + */ +OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class( + OpenLayers.Format.SLD.v1_0_0, { + + /** + * Property: version + * {String} The specific parser version. + */ + version: "1.0.0", + + /** + * Property: profile + * {String} The specific profile + */ + profile: "GeoServer", + + /** + * Constructor: OpenLayers.Format.SLD.v1_0_0_GeoServer + * Create a new parser for GeoServer-enhanced SLD version 1.0.0. + * + * Parameters: + * options - {Object} An optional object whose properties will be set on + * this instance. + */ + + /** + * Property: readers + * Contains public functions, grouped by namespace prefix, that will + * be applied when a namespaced node is found matching the function + * name. The function will be applied in the scope of this parser + * with two arguments: the node being read and a context object passed + * from the parent. + */ + readers: OpenLayers.Util.applyDefaults({ + "sld": OpenLayers.Util.applyDefaults({ + "Priority": function(node, obj) { + var value = this.readers.ogc._expression.call(this, node); + if (value) { + obj.priority = value; + } + }, + "VendorOption": function(node, obj) { + if (!obj.vendorOptions) { + obj.vendorOptions = []; + } + obj.vendorOptions.push({ + name: node.getAttribute("name"), + value: this.getChildValue(node) + }); + } + }, OpenLayers.Format.SLD.v1_0_0.prototype.readers["sld"]) + }, OpenLayers.Format.SLD.v1_0_0.prototype.readers), + + /** + * Property: writers + * As a compliment to the readers property, this structure contains public + * writing functions grouped by namespace alias and named like the + * node names they produce. + */ + writers: OpenLayers.Util.applyDefaults({ + "sld": OpenLayers.Util.applyDefaults({ + "Priority": function(priority) { + return this.writers.sld._OGCExpression.call( + this, "sld:Priority", priority + ); + }, + "VendorOption": function(option) { + return this.createElementNSPlus("sld:VendorOption", { + attributes: {name: option.name}, + value: option.value + }); + }, + "TextSymbolizer": function(symbolizer) { + var writers = OpenLayers.Format.SLD.v1_0_0.prototype.writers; + var node = writers["sld"]["TextSymbolizer"].apply(this, arguments); + if (symbolizer.externalGraphic || symbolizer.graphicName) { + this.writeNode("Graphic", symbolizer, node); + } + if ("priority" in symbolizer) { + this.writeNode("Priority", symbolizer.priority, node); + } + return this.addVendorOptions(node, symbolizer); + }, + "PointSymbolizer": function(symbolizer) { + var writers = OpenLayers.Format.SLD.v1_0_0.prototype.writers; + var node = writers["sld"]["PointSymbolizer"].apply(this, arguments); + return this.addVendorOptions(node, symbolizer); + }, + "LineSymbolizer": function(symbolizer) { + var writers = OpenLayers.Format.SLD.v1_0_0.prototype.writers; + var node = writers["sld"]["LineSymbolizer"].apply(this, arguments); + return this.addVendorOptions(node, symbolizer); + }, + "PolygonSymbolizer": function(symbolizer) { + var writers = OpenLayers.Format.SLD.v1_0_0.prototype.writers; + var node = writers["sld"]["PolygonSymbolizer"].apply(this, arguments); + return this.addVendorOptions(node, symbolizer); + } + }, OpenLayers.Format.SLD.v1_0_0.prototype.writers["sld"]) + }, OpenLayers.Format.SLD.v1_0_0.prototype.writers), + + /** + * Method: addVendorOptions + * Add in the VendorOption tags and return the node again. + * + * Parameters: + * node - {DOMElement} A DOM node. + * symbolizer - {Object} + * + * Returns: + * {DOMElement} A DOM node. + */ + addVendorOptions: function(node, symbolizer) { + var options = symbolizer.vendorOptions; + if (options) { + for (var i=0, ii=options.length; i + + + + + +
+ + diff --git a/tests/list-tests.html b/tests/list-tests.html index 1421c2b6dc..92ebdec19a 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -73,6 +73,7 @@
  • Format/Text.html
  • Format/SLD.html
  • Format/SLD/v1_0_0.html
  • +
  • Format/SLD/v1_0_0_GeoServer.html
  • Format/Filter.html
  • Format/Filter/v1.html
  • Format/Filter/v1_0_0.html