[OpenLayers-Dev] OpenLayers.Format.SLD - Graphics support (mostly)

m0n0 ole at monochrom.net
Mon Feb 27 07:19:47 EST 2012


 Hello there,

 this patch is not getting better when not beeing published, it's laying 
 around here for a few month. It's not so clean, but maybe someone is 
 interested.

 1. I needed to change 2 XML Schema attributes to make it work with 
 ArcGIS 10. That's included in the patch, but it has
    nothing to do with SLD Graphics support.
 2. All the other stuff is there to provide Graphics support within SLD 
 ( that was missing, but I needed it ). Works well for me.
    Tested against random WMS and ArcGIS 10 WMS.



 Greets,
 m
-------------- next part --------------
Index: v1.js
===================================================================
--- v1.js	(revision 12170)
+++ v1.js	(working copy)
@@ -534,8 +534,7 @@
                 var root = this.createElementNSPlus(
                     "sld:StyledLayerDescriptor",
                     {attributes: {
-                        "version": this.VERSION,
-                        "xsi:schemaLocation": this.schemaLocation
+                        "version": this.VERSION
                     }}
                 );
 
@@ -543,6 +542,8 @@
                 // at the root level (see ticket:2166).
                 root.setAttribute("xmlns:ogc", this.namespaces.ogc);
                 root.setAttribute("xmlns:gml", this.namespaces.gml);
+				root.setAttribute("xmlns:xsi", this.namespaces.xsi);
+				root.setAttribute("xsi:schemaLocation", this.schemaLocation );
 
                 // add in optional name
                 if(sld.name) {
@@ -792,6 +793,7 @@
                 // GraphicStroke here
 
                 // add in CssParameters
+				
                 if(symbolizer.strokeColor != undefined) {
                     this.writeNode(
                         "CssParameter",
@@ -982,19 +984,25 @@
             },
             "PolygonSymbolizer": function(symbolizer) {
                 var node = this.createElementNSPlus("sld:PolygonSymbolizer");
-                if(symbolizer.fill !== false) {
-                    this.writeNode("Fill", symbolizer, node);
-                }
+								
+				if (symbolizer.fill !== false) {
+						this.writeNode("Fill", symbolizer, node);
+					}
                 if(symbolizer.stroke !== false) {
                     this.writeNode("Stroke", symbolizer, node);
                 }
+				
                 return node;
             },
             "Fill": function(symbolizer) {
                 var node = this.createElementNSPlus("sld:Fill");
-                
-                // GraphicFill here
-                
+				if (symbolizer.graphicName != undefined || symbolizer.externalGraphic != undefined ) {
+					if ((symbolizer.graphicName != null && symbolizer.graphicName != "") 
+						|| (symbolizer.externalGraphic != null && symbolizer.externalGraphic != "") ) {
+						this.writeNode("GraphicFill", symbolizer, node);
+					}
+				}
+				
                 // add in CssParameters
                 if(symbolizer.fillColor) {
                     this.writeNode(
@@ -1017,9 +1025,14 @@
                 this.writeNode("Graphic", symbolizer, node);
                 return node;
             },
+			"GraphicFill": function(symbolizer){
+				var node = this.createElementNSPlus("sld:GraphicFill");
+				this.writeNode("Graphic", symbolizer, node);
+				return node;
+			},			
             "Graphic": function(symbolizer) {
                 var node = this.createElementNSPlus("sld:Graphic");
-                if(symbolizer.externalGraphic != undefined) {
+                if(symbolizer.externalGraphic != undefined && symbolizer.externalGraphic != "") {
                     this.writeNode("ExternalGraphic", symbolizer, node);
                 } else {
                     this.writeNode("Mark", symbolizer, node);
@@ -1048,12 +1061,22 @@
             },
             "Mark": function(symbolizer) {
                 var node = this.createElementNSPlus("sld:Mark");
-                if(symbolizer.graphicName) {
-                    this.writeNode("WellKnownName", symbolizer.graphicName, node);
-                }
-                if (symbolizer.fill !== false) {
-                    this.writeNode("Fill", symbolizer, node);
-                }
+                if (symbolizer.graphicName != null && symbolizer.graphicName != "" && symbolizer.graphicName != undefined ) {
+					this.writeNode("WellKnownName", symbolizer.graphicName, node);
+					//  manually write fill node to prevent recursion
+					if( symbolizer.fillColor != undefined || symbolizer.fill != false ){
+						var ob = {fillColor: symbolizer.fillColor};
+						if( symbolizer.fillOpacity != undefined ){
+							ob.fillOpacity = symbolizer.fillOpacity;
+						}
+						this.writeNode("Fill", ob, node);
+					}
+				}
+				else {
+					if (symbolizer.fill !== false) {
+						this.writeNode("Fill", symbolizer, node);
+					}
+				}
                 if (symbolizer.stroke !== false) {
                     this.writeNode("Stroke", symbolizer, node);
                 }


More information about the Dev mailing list