AW: [OpenLayers-Users] WMS polygon fill color

IvanBell Ivan.Bell at CCA.com
Wed May 18 00:40:46 EDT 2011


Ok.  After *A LOT* of troubleshooting and Googling and trial-and-error, I
figured out that defining certain attributes (copied from other example) was
causing the problem.  Namely, "Name" and "Title", as well as the "ogc:Or"
tags.


So, I have part of my problem solved.  The following works for coloring some
of the polygons red and the rest yellow.




var sld = '<StyledLayerDescriptor version="1.0.0"';
sld += '    xsi:schemaLocation="http://www.opengis.net/sld
StyledLayerDescriptor.xsd" ';
sld += '    xmlns="http://www.opengis.net/sld" ';
sld += '    xmlns:ogc="http://www.opengis.net/ogc" ';
sld += '    xmlns:xlink="http://www.w3.org/1999/xlink" ';
sld += '   
xmlns:xsi="http://www.w3.org/2001/<MLSchema-instance">';
sld += '   <NamedLayer>';
sld += '      <Name>MyStore:MyLayer</Name>';
sld += '      <UserStyle>';
<DEL>
sld += '         <Title>Colored Polygon</Title>';
sld += '         <Name>Colored Polygon</Name>'; 
sld += '         <FeatureTypeStyle>';
sld += '            <Rule>';
sld += '               <ogc:Filter>';
sld += '                  <ogc:Or>';
sld += '                     <ogc:FeatureId fid="MyLayer.1" />';
sld += '                     <ogc:FeatureId fid="MyLayer.2" />';
sld += '                     <ogc:FeatureId fid="MyLayer.3" />';
sld += '                  </ogc:Or>';
sld += '               </ogc:Filter>';
sld += '               <PolygonSymbolizer>';
sld += '                  <Fill>';
sld += '                     <CssParameter
name="fill">#FF0000</CssParameter>';
sld += '                     <CssParameter
name="fill-opacity">0.5</CssParameter>';
sld += '                  </Fill>';
sld += '                  <Stroke>';
sld += '                     <CssParameter
name="stroke">#800000</CssParameter>';
sld += '                     <CssParameter
name="stroke-width">2</CssParameter>';
sld += '                  </Stroke>';
sld += '               </PolygonSymbolizer>';
sld += '            </Rule>';
sld += '            <Rule>';
sld += '<ElseFilter/>';
sld += '               <ogc:Filter>';
sld += '                  <ogc:Not>';
sld += '                     <ogc:Or>';
sld += '                        <ogc:FeatureId fid="MyLayer.1" />';
sld += '                        <ogc:FeatureId fid="MyLayer.2" />';
sld += '                        <ogc:FeatureId fid="MyLayer.3" />';
sld += '                     </ogc:Or>';
sld += '                  </ogc:Not>';
sld += '               </ogc:Filter>';
sld += '               <PolygonSymbolizer>';
sld += '                  <Fill>';
sld += '                     <CssParameter
name="fill">#FFFF00</CssParameter>';
sld += '                     <CssParameter
name="fill-opacity">0.5</CssParameter>';
sld += '                  </Fill>';
sld += '                  <Stroke>';
sld += '                     <CssParameter
name="stroke">#CCCC00</CssParameter>';
sld += '                     <CssParameter
name="stroke-width">2</CssParameter>';
sld += '                  </Stroke>';
sld += '               </PolygonSymbolizer>';
sld += '            </Rule>';
sld += '         </FeatureTypeStyle>';
sld += '      </UserStyle>';
sld += '   </NamedLayer>';
sld += '</StyledLayerDescriptor>';


coloredLayer = new OpenLayers.Layer.WMS(
   "Polygons-Room", "http://localhost:8081/geoserver/wms",
   {
      layers: "MyStore:MyLayer",
      transparent: true,
      format: 'image/png',
      sld_body: sld
   },
   {
     singleTile: true,
     ratio: 1,
     isBaseLayer: false
   }
);



I would like to know how to write the rule for coloring some polygons red,
some blue, some green, and the rest yellow.  Is this possible?  I have tried
different permutations of the "Or".  I have tried to have more than one
"ElseFilter".  I have tried to separate the rules by FeatureTypeStyle.  None
of which have worked.


Any help with this would be greatly appreciated.  I would settle for a
decent SLD resource.  The cookbook has only basic examples and not even the
spec has anything remotely sophisticated as multiple polygon rules.  I have
only seen a multiple rule with line, polygon, and point.  It seems that the
OpenLayers.js errs when combining multiple polygon rules.


Sincerely,

Ivan



--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/WMS-polygon-fill-color-tp6374589p6376411.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/20110517/94a80d5c/attachment.html


More information about the Users mailing list