3
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 
    xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
    xmlns="http://www.opengis.net/sld" 
    xmlns:ogc="http://www.opengis.net/ogc" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>Parcel</Name>
    <UserStyle>
      <Title>Parcels</Title>
      <FeatureTypeStyle>
        <Rule>
          <MinScaleDenominator>100</MinScaleDenominator>
          <MaxScaleDenominator>6000</MaxScaleDenominator>          
          <PointSymbolizer>
             <Graphic>
               <Mark>
                 <WellKnownName>circle</WellKnownName>
                 <Fill>
                   <CssParameter name="fill">#CC3300</CssParameter>
                 </Fill>
               </Mark>
               <Size>6</Size>
             </Graphic>
           </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

This is my style file. I want to get legend graphic wit a query http://localhost:8080/geoserver/PGIS/wms?REQUEST=GetLegendGraphic

This is returning a circle but not include text: enter image description here

Bu it should be like this: enter image description here

If I add multiple rules, text label is appearing.

  • Try to give a title for the rule <FeatureTypeStyle> <Rule> <Title>your_title</Title> – user30184 Dec 2 '14 at 11:51
7

If you add LEGEND_OPTIONS parameter to your request and the value forceLabels:on then you can force GeoServer to draw the text for a single rule. Here is an example of a request:

http://demo.opengeo.org/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&STYLE=point&LEGEND_OPTIONS=forceLabels:on

  • This example doesn't print the label, currently. Not sure what's going on there! – Alex Leith Mar 15 '16 at 22:07
  • That is because the title in the polygon SLD was removed in the demo server. If you change the STYLE parameter from polygon to point then you will see the label again. – taudorf Mar 16 '16 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.