To style labels with SLD, you can use a TextSymbolizer
, which includes settings to configure the label content, the label location, and styling settings such as the font and the
color.
To enhance the readability of labels, users commonly want to add a box around a label.
LuciadRIA supports OGC SE standard 1.1, which doesn’t offer this capability. LuciadRIA does support label boxing, by means
of an SE extension, though.
To add a box around label text:
-
Add the well-known mark
square
as a graphic to theTextSymbolizer
. You can configure the desired stroke and fill settings for the box on the graphic. -
Add the vendor option
graphic-resize=stretch
to theTextSymbolizer
. With this setting, you make sure to stretch the well-known marksquare
to contain the label. -
Add the vendor option
graphic-margin
to theTextSymbolizer
. This vendor option takes an integer value to represent the desired padding in pixels between the label and its box.
LuciadRIA supports regular stretched square boxes only. If you use other graphics or other resize possibilities, LuciadRIA shows you a warning and skips them without generating a label box. There is no support for label boxes for world-sized text. |
Program: Defining a text style with a box shows you an example of adding a label with a box to a line geometry:
<?xml version='1.0' encoding='UTF-8'?> <FeatureTypeStyle xmlns="http://www.opengis.net/se" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/se http://schemas.opengis.net/se/1.1.0/FeatureStyle.xsd" version="1.1.0"> <Rule> <Name>Text_style_with_label_box</Name> <TextSymbolizer> <Label>MyLabel</Label> <Font> <SvgParameter name="font-style">normal</SvgParameter> <SvgParameter name="font-weight">normal</SvgParameter> <SvgParameter name="font-size">10</SvgParameter> <SvgParameter name="font-family">Lucida Sans</SvgParameter> </Font> <LabelPlacement> <LinePlacement> <PerpendicularOffset>-16.0</PerpendicularOffset> </LinePlacement> </LabelPlacement> <Graphic> <Mark> <WellKnownName>square</WellKnownName> <Fill> <SvgParameter name="fill-opacity">1.0</SvgParameter> <SvgParameter name="fill">#FFFF00</SvgParameter> </Fill> <Stroke> <SvgParameter name="stroke-opacity">1.0</SvgParameter> <SvgParameter name="stroke">#0000FF</SvgParameter> <SvgParameter name="stroke-width">3</SvgParameter> </Stroke> </Mark> </Graphic> <VendorOption name="graphic-resize">stretch</VendorOption> <VendorOption name="graphic-margin">4</VendorOption> </TextSymbolizer> <LineSymbolizer> <Stroke> <SvgParameter name="stroke-width">1</SvgParameter> <SvgParameter name="stroke">#FF0000</SvgParameter> <SvgParameter name="stroke-opacity">1.0</SvgParameter> </Stroke> </LineSymbolizer> </Rule> </FeatureTypeStyle>