2

I would like to split the style of my labels, which consist of 2 attributes. I already managed to separate the lines, but I need to style them differently as well, as the second line should be bold.

Currently my map looks like this:

how it looks like

And I would like it to look like this:

how it should look like

I would prefer to do it in CSS, but I also prepared the style in SLD, so I would be happy for a solution in either of them.

My code looks like this in CSS:

* {
    label: [IDENT][LOWERLIMIT];
    -gt-label-auto-wrap: 1;
    font-weight: normal;
    font-fill: black;
}

and like this in SLD:

<Rule>
  <TextSymbolizer>
     <Label>
       <ogc:PropertyName>IDENT</ogc:PropertyName><![CDATA[
]]>
       <ogc:PropertyName>LOWERLIMIT</ogc:PropertyName>
      </Label>
      <Font>
       <CssParameter name="font-fill">black</CssParameter>
       <CssParameter name="font-weight">normal</CssParameter>
      </Font>
  </TextSymbolizer>
</Rule>
1

Here is a solution in SLD but I think you should be able to generate the same in CSS.

enter image description here

The trick is to use 2 TextSymbolizers and offset them so that they don't overlap.

     <TextSymbolizer>
        <Label>
          <ogc:PropertyName>STATE_ABBR</ogc:PropertyName>
        </Label>
        <Font>

          <CssParameter name="font-family">Arial</CssParameter>
          <CssParameter name="font-style">Normal</CssParameter>
          <CssParameter name="font-size">10</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>1.0</AnchorPointY>
            </AnchorPoint>
            <Displacement>
              <DisplacementX>
                0
              </DisplacementX>
              <DisplacementY>
                10
              </DisplacementY>
            </Displacement>
          </PointPlacement>
        </LabelPlacement>
      </TextSymbolizer>
      <TextSymbolizer>
        <Label>
          <ogc:PropertyName>MALE</ogc:PropertyName>
        </Label>
        <Font>

          <CssParameter name="font-family">Arial Bold</CssParameter>
          <CssParameter name="font-style">Normal</CssParameter>
          <CssParameter name="font-weight">bold</CssParameter>
          <CssParameter name="font-size">10</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>0.0</AnchorPointY>
            </AnchorPoint>
            <Displacement>
              <DisplacementX>
                0
              </DisplacementX>
              <DisplacementY>
                -10
              </DisplacementY>
            </Displacement>
          </PointPlacement>
        </LabelPlacement>
      </TextSymbolizer>

Depending on your font and polygon sizes you can play with the AnchorPoints and Displacements to adjust the exact placement of the labels.

  • For CSS it works if you set (at)mode "Flat" and set two styles for the same element. Do you have any idea how it could work while using (at)mode "Simple"? (So cascading is still enabled) – Michaela Sep 20 '17 at 14:26
  • 2
    You need to set it as a second symbolizer in the same property, e.g.: "label: [STATE_ABBR],[MALE]" and do the same for the other properties having different values. – Andrea Aime Sep 20 '17 at 16:09

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.