Skip to main content

Overview

Open Mobile Maps provides factory classes to create map elements like icons, lines, and text. These factories simplify the creation of styled map objects with consistent configuration.

MCIconFactory

MCIconFactory creates icon objects for display on the icon layer.

createIcon

Creates an icon with specified properties:
let image = UIImage(named: "marker")
let texture = try! TextureHolder(image!.cgImage!)

let icon = MCIconFactory.createIcon(
    "icon-id",
    coordinate: MCCoord(lat: 46.962592372639634, lon: 8.378232525377973),
    texture: texture,
    iconSize: .init(x: Float(texture.getImageWidth()), y: Float(texture.getImageHeight())),
    scale: .FIXED,
    blendMode: .NORMAL
)
identifier
String
required
Unique identifier for the icon
coordinate
MCCoord
required
Position where the icon should be displayed on the map
texture
TextureHolder
required
Image texture for the icon. Create from CGImage using TextureHolder
iconSize
Vec2F
required
Size of the icon in pixels. Use Vec2F(x: width, y: height)
scale
IconScale
required
How the icon scales with camera movements:
  • .FIXED - Icon size remains constant regardless of zoom
  • .INVARIANT - Icon scales with the map
blendMode
BlendMode
required
Blend mode for rendering the icon:
  • .NORMAL - Standard alpha blending
  • .ADDITIVE - Additive blending
  • .MULTIPLY - Multiply blending

Complete Example

let iconLayer = MCIconLayerInterface.create()

// Load image
let image = UIImage(named: "location-marker")
guard let cgImage = image?.cgImage else { return }

// Create texture
let texture = try! TextureHolder(cgImage)

// Create icon
let icon = MCIconFactory.createIcon(
    "poi-marker",
    coordinate: MCCoord(lat: 47.3769, lon: 8.5417),
    texture: texture,
    iconSize: .init(
        x: Float(texture.getImageWidth()),
        y: Float(texture.getImageHeight())
    ),
    scale: .FIXED,
    blendMode: .NORMAL
)

// Add to layer
iconLayer?.add(icon)
mapView.add(layer: iconLayer?.asLayerInterface())

TextureHolder

Create texture holders from CGImage:
let image = UIImage(named: "icon")
let texture = try! TextureHolder(image!.cgImage!)

// Get texture dimensions
let width = texture.getImageWidth()
let height = texture.getImageHeight()

MCLineFactory

MCLineFactory creates styled line objects for display on the line layer.

createLine

Creates a line with specified coordinates and style:
let coords: [MCCoord] = [
    MCCoord(lat: 47.0, lon: 8.0),
    MCCoord(lat: 47.5, lon: 8.5),
    MCCoord(lat: 48.0, lon: 9.0)
]

let line = MCLineFactory.createLine(
    "route-line",
    coordinates: coords,
    style: MCLineStyle(
        color: MCColorStateList(
            normal: UIColor.systemBlue.mapCoreColor,
            highlighted: UIColor.systemBlue.withAlphaComponent(0.7).mapCoreColor
        ),
        gapColor: MCColorStateList(
            normal: UIColor.white.mapCoreColor,
            highlighted: UIColor.gray.mapCoreColor
        ),
        opacity: 1.0,
        widthType: .SCREEN_PIXEL,
        width: 5,
        dashArray: [],
        dashFade: 0.0,
        dashAnimationSpeed: 0.0,
        lineCap: .ROUND,
        lineJoin: .ROUND,
        offset: 0.0,
        dotted: false,
        dottedSkew: 0.0
    )
)
identifier
String
required
Unique identifier for the line
coordinates
[MCCoord]
required
Array of coordinates defining the line path
style
MCLineStyle
required
Style configuration for the line appearance

MCLineStyle

Line style configuration object:
let style = MCLineStyle(
    color: MCColorStateList(
        normal: UIColor.systemPink.withAlphaComponent(0.5).mapCoreColor,
        highlighted: UIColor.blue.withAlphaComponent(0.5).mapCoreColor
    ),
    gapColor: MCColorStateList(
        normal: UIColor.red.withAlphaComponent(0.5).mapCoreColor,
        highlighted: UIColor.gray.withAlphaComponent(0.5).mapCoreColor
    ),
    opacity: 1.0,
    widthType: .SCREEN_PIXEL,
    width: 50,
    dashArray: [1, 1],
    dashFade: 0.0,
    dashAnimationSpeed: 0.0,
    lineCap: .BUTT,
    lineJoin: .ROUND,
    offset: 0.0,
    dotted: false,
    dottedSkew: 0.0
)
color
MCColorStateList
required
Line color for normal and highlighted states
gapColor
MCColorStateList
Color for gaps in dashed lines
opacity
Float
Line opacity from 0.0 (transparent) to 1.0 (opaque)
widthType
WidthType
How line width is measured:
  • .SCREEN_PIXEL - Width in screen pixels
  • .MAP_UNIT - Width in map units
width
Float
Line width in the specified unit type
dashArray
[Float]
Dash pattern array. Example: [10, 5] = 10 units line, 5 units gap. Empty array [] for solid line
dashFade
Float
Fade effect for dash transitions
dashAnimationSpeed
Float
Speed of dash pattern animation. 0.0 for no animation
lineCap
LineCap
End cap style:
  • .BUTT - Flat cap at line end
  • .ROUND - Rounded cap
  • .SQUARE - Square cap extending beyond end point
lineJoin
LineJoin
Join style for line segments:
  • .ROUND - Rounded join
  • .BEVEL - Beveled join
  • .MITER - Mitered join
offset
Float
Offset distance from the line path
dotted
Bool
Whether to render as dotted line
dottedSkew
Float
Skew angle for dotted pattern

MCColorStateList

Defines colors for different interaction states:
let colorState = MCColorStateList(
    normal: UIColor.systemBlue.mapCoreColor,
    highlighted: UIColor.systemBlue.withAlphaComponent(0.7).mapCoreColor
)
normal
Color
required
Color in normal state
highlighted
Color
required
Color when highlighted or selected

Complete Example

Solid Line

let lineLayer = MCLineLayerInterface.create()

let coords: [MCCoord] = [
    MCCoord(lat: 47.0, lon: 8.0),
    MCCoord(lat: 47.5, lon: 8.5),
    MCCoord(lat: 48.0, lon: 9.0)
]

let solidLine = MCLineFactory.createLine(
    "solid-route",
    coordinates: coords,
    style: MCLineStyle(
        color: MCColorStateList(
            normal: UIColor.systemBlue.mapCoreColor,
            highlighted: UIColor.systemBlue.withAlphaComponent(0.7).mapCoreColor
        ),
        gapColor: MCColorStateList(
            normal: UIColor.clear.mapCoreColor,
            highlighted: UIColor.clear.mapCoreColor
        ),
        opacity: 1.0,
        widthType: .SCREEN_PIXEL,
        width: 5,
        dashArray: [],
        lineCap: .ROUND,
        offset: 0.0
    )
)

lineLayer?.add(solidLine)
mapView.add(layer: lineLayer?.asLayerInterface())

Dashed Line

let dashedLine = MCLineFactory.createLine(
    "dashed-route",
    coordinates: coords,
    style: MCLineStyle(
        color: MCColorStateList(
            normal: UIColor.systemPink.withAlphaComponent(0.5).mapCoreColor,
            highlighted: UIColor.blue.withAlphaComponent(0.5).mapCoreColor
        ),
        gapColor: MCColorStateList(
            normal: UIColor.red.withAlphaComponent(0.5).mapCoreColor,
            highlighted: UIColor.gray.withAlphaComponent(0.5).mapCoreColor
        ),
        opacity: 1.0,
        widthType: .SCREEN_PIXEL,
        width: 50,
        dashArray: [1, 1],
        lineCap: .BUTT,
        offset: 0.0
    )
)

lineLayer?.add(dashedLine)

MCTextFactory

While not extensively documented in the readme, MCTextFactory is available for creating text elements on the map.

Usage Pattern

Similar to other factories, MCTextFactory creates text objects for display:
// Create text layer
let textLayer = MCTextLayerInterface.create()

// Create text element (example pattern)
let text = MCTextFactory.createText(
    "label-id",
    coordinate: MCCoord(lat: 47.3769, lon: 8.5417),
    text: "Location Label",
    style: textStyle
)

textLayer?.add(text)
mapView.add(layer: textLayer?.asLayerInterface())
For detailed MCTextFactory API documentation, refer to the SDK source code or contact the Open Mobile Maps team.

Color Conversion

UIColor to MapCore Color

Convert UIKit colors to MapCore format:
let uiColor = UIColor.systemBlue
let mapCoreColor = uiColor.mapCoreColor

With Alpha Component

let transparentRed = UIColor.red.withAlphaComponent(0.5).mapCoreColor
let semiTransparentBlue = UIColor.systemBlue.withAlphaComponent(0.7).mapCoreColor

Best Practices

Icon Sizing

Use actual texture dimensions for natural appearance:
// Good: Use actual texture size
let texture = try! TextureHolder(image!.cgImage!)
let icon = MCIconFactory.createIcon(
    "icon",
    coordinate: coord,
    texture: texture,
    iconSize: .init(
        x: Float(texture.getImageWidth()),
        y: Float(texture.getImageHeight())
    ),
    scale: .FIXED,
    blendMode: .NORMAL
)

// Also valid: Custom size for scaling
let icon = MCIconFactory.createIcon(
    "icon",
    coordinate: coord,
    texture: texture,
    iconSize: .init(x: 32, y: 32),  // Custom size
    scale: .FIXED,
    blendMode: .NORMAL
)

Line Width Units

Choose the appropriate width type:
// Screen pixels: Consistent visual width regardless of zoom
widthType: .SCREEN_PIXEL,
width: 5

// Map units: Scales with map zoom level
widthType: .MAP_UNIT,
width: 100

Color State Consistency

Provide meaningful color differences for interaction states:
// Good: Clear visual feedback
color: MCColorStateList(
    normal: UIColor.systemBlue.mapCoreColor,
    highlighted: UIColor.systemBlue.withAlphaComponent(0.6).mapCoreColor
)

// Avoid: No visual difference
color: MCColorStateList(
    normal: UIColor.systemBlue.mapCoreColor,
    highlighted: UIColor.systemBlue.mapCoreColor
)

Dash Patterns

Use clear, readable dash patterns:
// Good patterns:
dashArray: [10, 5]      // Long dash, short gap
dashArray: [5, 5]       // Equal dash and gap
dashArray: [10, 5, 2, 5] // Complex pattern

// Solid line:
dashArray: []

Build docs developers (and LLMs) love