Configuration Options for ShieldSymbolizer

allow_overlapAllow the symbolizer to overlap others. (Default "false")
avoid_edgesAttempts to stay away from the edge of the image. (Default "false")
baseBase symbol template. See #574 (XML config only)
character_spacingHorizontal spacing between characters (in pixels). Currently works for point placement only, not line placement. (Default 0)
dxOffset the text horizontally. Unit: pixels from the image's center
dyOffset the text vertically. Unit: pixels from the image's center. Also see note at vertical_alignment.
face_nameFont name for the shield text
fileThe file to use for the shield background
fillColor of the shield text, e.g. #FFFFFF
fontset_nameName of the FontSet to use. (XML config only)
halo_fillColor of the colored halo around the text, e.g. #AF2304. (Default white)
halo_radiusThickness of the colored halo around the text as an integer value in pixels. (Default 0)
heightThe height of the shield file (Defaults to image's height)
horizontal_alignment(Default "middle")
justify_alignment(Default "middle")
line_spacingVertical spacing between lines of multi-line labels, in pixels. (Default 0)
min_distanceMinimum distance to the next shield symbol, not necessarily the same shield. (Default 0.0)
nameThis is the query field you want to use for the label text, e.g. "ref"
no_text(Default "false")
opacity(Default 1.0)
placement"line" or "point"
sizeFont size of the shield text (a value of zero will prevent text from being written)
spacingThe spacing between repeated occurrences of the same shield
text_convertAllows conversion of text to lower or upper case before display. Values are "none" (default), "toupper", and "tolower".
typeType of the shield file, e.g. "png"
unlock_image(Default "false)
vertical_alignmentPosition of label relative to point position ("top" to label on top of a point, "middle", "bottom") default is "middle" for dy = 0, "bottom" for dy > 0, "top" for dy < 0
widthThe width of the shield file. (Defaults to image's width)
wrap_before(Default "false")
wrap_characterUse this character instead of a space to wrap long names. (Default " ")
wrap_widthLength before wrapping long names. (Default 0)

Good to know

ShieldSymbolizer can be used to label points.
E.G. If you want to place points on cities and their name above it. If you try to use a TextSymbolizer and a PointSymbolizer separated you will often see points without texts and/or texts without points.
To draw labeled points configure your shield symbolizer with placement = point and custom value for dx/dy to move the text around the point

Examples


http://wiki.openstreetmap.org/images/thumb/6/63/Mapnik-highway-motorway.png/120px-Mapnik-highway-motorway.png

Setting up a sample shield symbolizer, from the Cascade Users of OpenSource GeoSpatial (CUGOS) list: http://groups.google.com/group/cugos/browse_thread/thread/b62b4890e1933bba

Default

XML

<Style name="My Style">
    <Rule>
        <ShieldSymbolizer name="NAME" face_name="DejaVu Sans Bold" size="6" fill="#000000" min_distance="50" file="images/ushighway_shield_20.png" type="png" width="20" height="20" spacing="100" min_distance="50"></ShieldSymbolizer>
    </Rule>
</Style>

Python

shield = ShieldSymbolizer('NAME','DejaVu Sans Bold',6,Color('#000000'),'images/ushighway_shield_20.png','png',20,20)
# parameters are: (name, font name, font size, font color, image file, image type, width, height)
shield.minimum_distance = 50
shield.label_spacing = 100

C++

rule_type rule;
/* Parameters:
      name
      face name
      size
      color
      image
      image type
      width
      height
*/
shield_symbolizer ss("NAME", "DejaVu Sans Bold", 6, color(0, 0, 0), "/path/to/icon.png", "png", 20, 20);
ss.set_label_placement(mapnik::LINE_PLACEMENT); // Place label along the line
ss.set_displacement(dx, dy);
ss.set_label_spacing(min_distance);
rule.append(ss);

Resources