Skip to main content
Version: 5.0

Flat Labels

Using Mappedin SDK for iOS with your own map requires an Enterprise license. Try a demo map for free or refer to the Pricing page for more information.

FlatLabels are painted on the polygon and fill the available space. They automatically flip to always face toward the camera.

Note: A complete class that uses the code snippet in this guide can be found in the Mappedin iOS Github repo: FlatLabelsVC.swift

Flat labels can be added with default styles using MPIMapView.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 MPIOptions.ShowVenue options before enabling Flat Labels.

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

Styling Options

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

Flat Label Appearance - MPIOptions.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.
let flatLabelAppearance = MPIOptions.FlatLabelAppearance(color: "#0a0dbf", fontSize: 8)
let flatLabelLocations = MPIOptions.FlatLabelAllLocations(appearance: flatLabelAppearance)
mapView?.flatLabelManager.labelAllLocations(options: flatLabelLocations)

Note: A complete class that uses the code snippet in this guide can be found in the Mappedin iOS Github repo: FlatLabelsVC.swift