[OpenLayers-Users] Re: OpenLayers SLD Bug?
IvanBell
Ivan.Bell at CCA.com
Fri Jun 10 08:34:15 EDT 2011
I found a more elegant solution to the "workaround". Instead of creating the
file on the server, I just use the URL of a JSP that writes the SLD to its
response. Don't know why I didn't think of that before. Guess I was too
busy trying to hack my way out of the weeds.
Anyway, for posterity, here is the new mergeNewParams line:
myLayer.mergeNewParams({ SLD:
"http://localhost:8080/MyMapApp/SldGenerator.jsp" });
And here is the Jsp. Although I have not yet written the business rule code
to "dynamically" create the SLD, this page exemplifies how you can write it
back out once you do.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="true" import="java.io.OutputStream"%>
<%
StringBuilder strBuilder = new StringBuilder(
"<sld:StyledLayerDescriptor" );
strBuilder.append( " xmlns:sld=\"http://www.opengis.net/sld\"" );
strBuilder.append( " version=\"1.0.0\"" );
strBuilder.append( "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" );
strBuilder.append( " xsi:schemaLocation=\"http://www.opengis.net/sld
http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd\"" );
strBuilder.append( " xmlns:ogc=\"http://www.opengis.net/ogc\"" );
strBuilder.append( " xmlns:gml=\"http://www.opengis.net/gml\">"
);
strBuilder.append( " <sld:NamedLayer>" );
strBuilder.append( "
<sld:Name>MyWorkspace:MyLayer</sld:Name>" );
strBuilder.append( " <sld:UserStyle>" );
strBuilder.append( " <sld:FeatureTypeStyle>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.1\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.2\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.3\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.4\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.5\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.6\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.7\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.8\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.9\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.10\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#0000FF</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#000080</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.11\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.12\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.13\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.14\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.15\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.16\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.17\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.18\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#FF0000</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#800000</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.19\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.20\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.21\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.22\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#00FF00</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#008000</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.23\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#FFFF00</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#808000</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.24\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.25\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.26\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.27\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.28\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.29\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#FF007F</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#C71585</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.30\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#FFC0CB</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#FF3E96</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.31\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.32\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.33\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.34\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.35\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.36\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.37\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.38\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.39\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.40\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#800080</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#68228B</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <ogc:Filter>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.41\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.42\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.43\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.44\"/>" );
strBuilder.append( " <ogc:FeatureId
fid=\"MyLayer.45\"/>" );
strBuilder.append( " </ogc:Filter>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#C00000</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#FF1CAE</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " <sld:Rule>" );
strBuilder.append( " <sld:ElseFilter/>" );
strBuilder.append( " <sld:PolygonSymbolizer>" );
strBuilder.append( " <sld:Fill>" );
strBuilder.append( " <sld:CssParameter
name=\"fill\">#00FFFF</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"fill-opacity\">0.8</sld:CssParameter>" );
strBuilder.append( " </sld:Fill>" );
strBuilder.append( " <sld:Stroke>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke\">#0000FF</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-opacity\">1</sld:CssParameter>" );
strBuilder.append( " <sld:CssParameter
name=\"stroke-width\">1</sld:CssParameter>" );
strBuilder.append( " </sld:Stroke>" );
strBuilder.append( " </sld:PolygonSymbolizer>" );
strBuilder.append( " </sld:Rule>" );
strBuilder.append( " </sld:FeatureTypeStyle>" );
strBuilder.append( " </sld:UserStyle>" );
strBuilder.append( " </sld:NamedLayer>" );
strBuilder.append( "</sld:StyledLayerDescriptor>" );
OutputStream oOutputStream = response.getOutputStream();
oOutputStream.write( strBuilder.toString().getBytes() );
oOutputStream.flush();
%>
-----
Up the Irons!!!
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/OpenLayers-SLD-Bug-tp6453498p6461977.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110610/d2a35c7d/attachment-0001.html
More information about the Users
mailing list