Class Symbolizer

java.lang.Object
dev.avelar.mapnik.Symbolizer

public final class Symbolizer extends Object
One drawing instruction inside a Rule: how to draw the geometry of a matching feature. Build one with a factory such as polygon(), then set attributes, using the typed methods for common ones or attr(String, Object) for any other. Attribute names are the ones in Mapnik's XML reference, for example stroke-dasharray or halo-radius.

Mapnik silently ignores attributes it does not know. MapnikMap.addStyle(dev.avelar.mapnik.Style) therefore loads the style in Mapnik's strict mode, which rejects a misspelled attribute, or one that does not belong on that kind of symbolizer, and says which.

  • Method Details

    • polygon

      public static Symbolizer polygon()
      Fill polygons: fill, fill-opacity, gamma, smooth, ...
    • line

      public static Symbolizer line()
      Stroke lines and polygon outlines: stroke, stroke-width, stroke-dasharray, ...
    • markers

      public static Symbolizer markers()
      Draw markers at points, along lines or inside polygons: marker-type, width, fill, ...
    • point

      public static Symbolizer point(String file)
      Draw an image file at each point.
    • polygonPattern

      public static Symbolizer polygonPattern(String file)
      Fill polygons with a repeating image.
    • linePattern

      public static Symbolizer linePattern(String file)
      Stroke lines with a repeating image.
    • raster

      public static Symbolizer raster()
      Draw raster data.
    • building

      public static Symbolizer building()
      Extrude polygons into simple 3D buildings.
    • dot

      public static Symbolizer dot()
      Draw a dot at each point.
    • debug

      public static Symbolizer debug()
      Draw the collision boxes Mapnik computes, for debugging label placement.
    • text

      public static Symbolizer text(String expression)
      Draw text. expression says what to write, in Mapnik's expression language, for example "[name]" or "[name] + ' (' + [pop] + ')'". Needs a font: set face-name and register the fonts with Mapnik.registerFonts(java.lang.String).
    • formattedText

      public static Symbolizer formattedText(TextFormat... formats)
      Draw text made of several runs, each with its own look. The symbolizer itself still needs a face-name (or fontset-name) as the default, which each run may override:
      
       Symbolizer.formattedText(TextFormat.of("[name]").fontSize(14),
                                TextFormat.of("' ' + [pop]").fontSize(10).fill("gray"))
           .faceName("DejaVu Sans Bold");
       
    • placementList

      public Symbolizer placementList(TextPlacement... placements)
      Try these alternatives in order until one fits. Only for formattedText(dev.avelar.mapnik.TextFormat...). Sets placement-type to list.
    • placementPositions

      public Symbolizer placementPositions(String positions)
      Try these positions around a point, for example "E,NE,SE,W" (east, north-east and so on) and use the first that fits. Sets placement-type to simple.
    • group

      public static Symbolizer group()
      A group of symbols and labels drawn together for features that share a key, such as a cluster of points. Add rules with groupRule(dev.avelar.mapnik.GroupRule) and choose how members are laid out.

      Mapnik draws nothing for a group unless it has a column range and a key: call groupColumns(int, int, java.lang.String) too.

    • groupRule

      public Symbolizer groupRule(GroupRule rule)
    • groupColumns

      public Symbolizer groupColumns(int startColumn, int numColumns, String repeatKey)
      Which columns of the group layout this symbolizer fills (start-column, 1-based, and how many, num-columns) and the expression that says which features belong together (repeat-key, for example "[id]"). Mapnik draws a group only when all three are set. Only for group().
    • simpleLayout

      public Symbolizer simpleLayout(double itemMargin)
      Lay group members out in a column, itemMargin pixels apart. Only for group().
    • pairLayout

      public Symbolizer pairLayout(double itemMargin)
      Lay group members out in pairs side by side. Only for group().
    • shield

      public static Symbolizer shield(String expression, String file)
      A text label drawn on top of an image, such as a road shield.
    • attr

      public Symbolizer attr(String name, Object value)
      Set any attribute. The value is written with toString(), except that numbers have no trailing .0 and booleans are true or false.
    • fill

      public Symbolizer fill(String color)
      Fill colour: a name, #rrggbb or rgba(r,g,b,a).
    • fill

      public Symbolizer fill(Color color)
    • fillOpacity

      public Symbolizer fillOpacity(double v)
    • stroke

      public Symbolizer stroke(String color)
    • stroke

      public Symbolizer stroke(Color color)
    • strokeWidth

      public Symbolizer strokeWidth(double v)
    • strokeOpacity

      public Symbolizer strokeOpacity(double v)
    • strokeDasharray

      public Symbolizer strokeDasharray(String v)
      For example "5,3": 5 units on, 3 off.
    • strokeLinejoin

      public Symbolizer strokeLinejoin(String v)
      miter, round or bevel.
    • strokeLinecap

      public Symbolizer strokeLinecap(String v)
      butt, round or square.
    • opacity

      public Symbolizer opacity(double v)
      Opacity, for symbolizers that have it: markers, point, dot, raster, text and the pattern symbolizers. Polygons and lines have none; use fillOpacity(double) and strokeOpacity(double).
    • compOp

      public Symbolizer compOp(String v)
      Compositing mode, such as multiply or screen.
    • compOp

      public Symbolizer compOp(BlendMode mode)
    • size

      public Symbolizer size(double width, double height)
      Markers and dots: width and height in pixels.
    • allowOverlap

      public Symbolizer allowOverlap(boolean v)
    • faceName

      public Symbolizer faceName(String v)
      Text: the font face, for example "DejaVu Sans Book".
    • fontSize

      public Symbolizer fontSize(double v)
      Text: the font size in pixels.
    • labelPlacement

      public Symbolizer labelPlacement(Symbolizer.LabelPlacement placement)
      Text and shields: where labels go: along a line, at a point, inside a polygon and so on.
    • positions

      public Symbolizer positions(Symbolizer.Position... positions)
      Text: try these positions around the point in turn until a label fits, for example positions(Position.NORTH_EAST, Position.SOUTH_EAST, Position.EXACT). Add smaller font sizes to fall back to with placementSizes(int...).
    • placementSizes

      public Symbolizer placementSizes(int... sizes)
      Text: if a label does not fit at any position, try again at these smaller font sizes, in whole pixels and largest first. Mapnik tries every position at each size. Call positions(dev.avelar.mapnik.Symbolizer.Position...) first.
    • margin

      public Symbolizer margin(double pixels)
      Text: keep labels this many pixels away from other labels with the same text. (Mapnik's older minimum-distance is deprecated and refuses to combine with repeatDistance(double).)
    • minimumPadding

      public Symbolizer minimumPadding(double pixels)
      Text: keep labels this many pixels away from the edge of the map or tile.
    • avoidEdges

      public Symbolizer avoidEdges(boolean v)
      Text: do not draw labels that would be cut by the edge of the map or tile.
    • repeatDistance

      public Symbolizer repeatDistance(double pixels)
      Text on lines: repeat the label every this many pixels along the line.
    • labelSpacing

      public Symbolizer labelSpacing(double pixels)
      Text on lines: distance between labels along a line, in pixels.
    • minimumPathLength

      public Symbolizer minimumPathLength(double pixels)
      Text on lines: skip lines shorter than this many pixels.
    • maxCharAngleDelta

      public Symbolizer maxCharAngleDelta(double degrees)
      Text on lines: the largest angle in degrees between two letters, so labels do not bend sharply.
    • labelPositionTolerance

      public Symbolizer labelPositionTolerance(double pixels)
      Text: how far in pixels a label may move along a line to find room.
    • largestBoxOnly

      public Symbolizer largestBoxOnly(boolean v)
      Text: label only the largest part of a multipart geometry.
    • ignorePlacement

      public Symbolizer ignorePlacement(boolean v)
      Markers, points and shields (not text): draw without making room for it, so it never blocks later labels.
    • wrapWidth

      public Symbolizer wrapWidth(double pixels)
      Text: wrap lines longer than this many pixels.
    • wrapCharacter

      public Symbolizer wrapCharacter(String character)
      Text: the character to wrap at, a space by default.
    • wrapBefore

      public Symbolizer wrapBefore(boolean v)
      Text: wrap before the wrap character instead of after it.
    • justify

      public Symbolizer justify(String alignment)
      Text: how lines of a wrapped label line up with each other: left, center, right or auto.
    • horizontalAlignment

      public Symbolizer horizontalAlignment(String alignment)
      Text: horizontal alignment of the label to its position: left, middle, right, auto or adjust.
    • verticalAlignment

      public Symbolizer verticalAlignment(String alignment)
      Text: vertical alignment of the label to its position: top, middle, bottom or auto.
    • upright

      public Symbolizer upright(String upright)
      Text on lines: which way up the letters stand: auto, auto-down, left, right, left-only or right-only.
    • displacement

      public Symbolizer displacement(double dx, double dy)
      Text: shift the label by this many pixels. Positive x is right and positive y is down.
    • rotation

      public Symbolizer rotation(double degrees)
      Text: turn the label by this many degrees clockwise.
    • textTransform

      public Symbolizer textTransform(String transform)
      Text: change the case of the label: none, uppercase, lowercase, capitalize or reverse.
    • fontFeatureSettings

      public Symbolizer fontFeatureSettings(String settings)
      Text: OpenType features, for example "liga=0, smcp".
    • halo

      public Symbolizer halo(String color, double radius)
      Text: outline colour and width.
    • halo

      public Symbolizer halo(Color color, double radius)
    • child

      public Symbolizer child(String xml)
      Add a nested XML element, for symbolizers that take them, such as the colorizer of a raster symbolizer or a text placement. Typed builders such as RasterColorizer use this; write raw XML only for elements that have no builder. A symbolizer made with text(java.lang.String) keeps its expression as body text, so it cannot also have children.
    • colorizer

      public Symbolizer colorizer(RasterColorizer colorizer)
      Colour a single-band raster by value. Only for raster().
    • attribute

      public Optional<String> attribute(String name)
      One attribute's value, or empty if it is not set.
    • body

      public Optional<String> body()
      The text inside the element, such as the expression of a text symbolizer, if it has any.
    • children

      public List<String> children()
      Nested elements as XML text, in order.
    • element

      public String element()
      The element name, for example PolygonSymbolizer.
    • attributes

      public Map<String,String> attributes()
      The attributes set so far, in the order they were set.
    • toXml

      public String toXml()
    • toString

      public String toString()
      Overrides:
      toString in class Object