Flat Labels

Flat Labels using Mappedin SDK for Android v5.

Flat Labels are painted on the polygon and fill the available space. They automatically flip to always face toward the camera. Flat labels can be added with default styles using mapView.flatLabelsManager.labelAllLocations(). This call should be made after MPIMapViewListener.onFirstMapLoaded is called, which indicates that the first map is loaded and can be modified. Note that Floating Labels are enabled by default. Floating Labels should be disabled using ShowVenue options before enabling Flat Labels.

Flat Labels can be added and removed all at once as mentioned above or individually using the MPIFlatLabelsManager.add() and MPIFlatLabelsManager.remove() methods.

A complete class that uses the code snippet in this guide can be found in the Mappedin Android Github repo: FlatLabels.kt

Styling Options

Flat Labels are highly customizable, allowing control of size, color and spacing of each label.

Flat Label Appearance - FlatLabelAppearance

  • height is the upper bounds of the Polygon by default. Height can be set if not using a Polygon or a custom height is desired.
  • margin is the amount of space to leave before starting the text from the edge of the bound of the canvas bound. These bounds are set in the Mappedin CMS. The default value is 5 pixels.
  • color is a string format of a hexadecimal color representation, such as #ff00000 for red.
  • fontSize in pixels, by default 12
  • scaleMin sets the minimum percentage to shrink the label to if it won't fit within the bounds at 100%. If it doesn't fit at that level, it won't be created.
  • scaleStep describes how much to decrement the scale each time it doesn't fit, so the map doesn't end up with too many different font sizes on screen at once. If only labelling a few Polygons rather than everything, set this and scaleMin to 0.1 to attempt to fit all text. The default value is 0.25.
val flatLabelAppearance: MPIOptions.FlatLabelAppearance = MPIOptions.FlatLabelAppearance (
fontSize = 8f,
color = "#0a0dbf")
val flatLabelLocations: MPIOptions.FlatLabelAllLocations =
MPIOptions.FlatLabelAllLocations(appearance = flatLabelAppearance)
mapView.flatLabelsManager.labelAllLocations(flatLabelLocations)

A complete class that uses the code snippet in this guide can be found in the Mappedin Android Github repo: FlatLabels.kt

Was this page helpful?

Next Topic

Markers