Skip to main content

Overview

Factories provide convenient methods for creating map objects like icons, lines, and text labels. These objects can then be added to their respective layers.

IconFactory

Creates icon objects for display in an IconLayerInterface.

createIcon()

Creates a standard icon with default anchor point (center).
fun createIcon(
    identifier: String,
    coordinate: Coord,
    texture: TextureHolderInterface,
    iconSize: Vec2F,
    scaleType: IconType,
    blendMode: BlendMode
): IconInfoInterface
identifier
String
required
Unique identifier for the icon
coordinate
Coord
required
The position where the icon should be displayed
texture
TextureHolderInterface
required
The texture to display (use BitmapTextureHolder for drawables/bitmaps)
iconSize
Vec2F
required
The size of the icon (width, height)
scaleType
IconType
required
How the icon scales with camera zoom (INVARIANT keeps constant screen size)
blendMode
BlendMode
required
Blend mode for rendering (NORMAL is typical)
Returns: IconInfoInterface - The created icon object Example:
val texture = BitmapTextureHolder(drawable)
val icon = IconFactory.createIcon(
    identifier = "marker",
    coordinate = Coord(
        CoordinateSystemIdentifiers.EPSG4326(),
        8.378232,
        46.962592,
        0.0
    ),
    texture = texture,
    iconSize = Vec2F(32.0f, 32.0f),
    scaleType = IconType.INVARIANT,
    blendMode = BlendMode.NORMAL
)

createIconWithAnchor()

Creates an icon with a custom anchor point.
fun createIconWithAnchor(
    identifier: String,
    coordinate: Coord,
    texture: TextureHolderInterface,
    iconSize: Vec2F,
    scaleType: IconType,
    blendMode: BlendMode,
    iconAnchor: Vec2F
): IconInfoInterface
identifier
String
required
Unique identifier for the icon
coordinate
Coord
required
The position where the icon should be displayed
texture
TextureHolderInterface
required
The texture to display
iconSize
Vec2F
required
The size of the icon (width, height)
scaleType
IconType
required
How the icon scales with camera zoom
blendMode
BlendMode
required
Blend mode for rendering
iconAnchor
Vec2F
required
Anchor point as normalized coordinates (0.0-1.0). (0.5, 1.0) places the anchor at bottom center
Returns: IconInfoInterface - The created icon object Example:
val iconWithCustomAnchor = IconFactory.createIconWithAnchor(
    identifier = "pin",
    coordinate = coordinate,
    texture = texture,
    iconSize = Vec2F(32.0f, 48.0f),
    scaleType = IconType.INVARIANT,
    blendMode = BlendMode.NORMAL,
    iconAnchor = Vec2F(0.5f, 1.0f) // Bottom center
)

Updating Icon Position

You can update an icon’s position after creation:
val icon = IconFactory.createIcon(/* ... */)
iconLayer.add(icon)

// Later, update position
icon.setCoordinate(
    Coord(
        CoordinateSystemIdentifiers.EPSG4326(),
        newLongitude,
        newLatitude,
        0.0
    )
)

LineFactory

Creates line objects for display in a LineLayerInterface.

createLine()

Creates a styled line.
fun createLine(
    identifier: String,
    coordinates: List<Coord>,
    style: LineStyle
): LineInfoInterface
identifier
String
required
Unique identifier for the line
coordinates
List<Coord>
required
List of coordinates defining the line path
style
LineStyle
required
Styling configuration for the line
Returns: LineInfoInterface - The created line object Example:
val line = LineFactory.createLine(
    identifier = "route",
    coordinates = listOf(
        Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0),
        Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 47.0, 0.0),
        Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 46.0, 0.0)
    ),
    style = LineStyle(
        color = ColorStateList(
            normal = Color(1.0f, 0.0f, 0.0f, 1.0f),
            highlighted = Color(1.0f, 0.5f, 0.0f, 1.0f)
        ),
        gapColor = ColorStateList(
            normal = Color(0.0f, 0.0f, 0.0f, 0.0f),
            highlighted = Color(0.0f, 0.0f, 0.0f, 0.0f)
        ),
        opacity = 1.0f,
        blur = 0.0f,
        widthType = SizeType.SCREEN_PIXEL,
        width = 5.0f,
        dashArray = arrayListOf(4.0f, 2.0f),
        lineCap = LineCapType.SQUARE,
        lineJoin = LineJoinType.ROUND
    )
)

LineStyle

Configuration object for line appearance.

Properties

color
ColorStateList
required
Colors for normal and highlighted states
gapColor
ColorStateList
required
Colors for gaps in dashed lines (normal and highlighted states)
opacity
Float
required
Line opacity (0.0-1.0)
blur
Float
required
Blur amount for the line edges
widthType
SizeType
required
How width is measured: SCREEN_PIXEL or MAP_UNIT
width
Float
required
Line width in the specified unit type
dashArray
ArrayList<Float>
required
Pattern for dashed lines (e.g., [4.0, 2.0] for 4px dash, 2px gap)
dashFade
Float
default:"0.0"
Fade effect for dash transitions
dashAnimationSpeed
Float
default:"0.0"
Speed of dash animation (0 for no animation)
lineCap
LineCapType
required
End cap style: BUTT, ROUND, or SQUARE
lineJoin
LineJoinType
required
Join style at vertices: BEVEL, ROUND, or MITER
offset
Float
default:"0.0"
Offset perpendicular to the line direction
dotted
Boolean
default:"false"
Whether to render as dotted line
dottedSkew
Double
default:"0.0"
Skew factor for dotted rendering

Complete Layer Example

class MapActivity : AppCompatActivity() {
    private lateinit var mapView: MapView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Create icon layer
        val iconLayer = IconLayerInterface.create()
        val texture = BitmapTextureHolder(getDrawable(R.drawable.marker))
        val icon = IconFactory.createIconWithAnchor(
            identifier = "location_marker",
            coordinate = Coord(
                CoordinateSystemIdentifiers.EPSG4326(),
                8.378232,
                46.962592,
                0.0
            ),
            texture = texture,
            iconSize = Vec2F(32.0f, 48.0f),
            scaleType = IconType.INVARIANT,
            blendMode = BlendMode.NORMAL,
            iconAnchor = Vec2F(0.5f, 1.0f)
        )
        iconLayer.add(icon)
        mapView.addLayer(iconLayer.asLayerInterface())
        
        // Create line layer
        val lineLayer = LineLayerInterface.create()
        val line = LineFactory.createLine(
            identifier = "path",
            coordinates = listOf(
                Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.0, 47.0, 0.0),
                Coord(CoordinateSystemIdentifiers.EPSG4326(), 9.0, 46.5, 0.0)
            ),
            style = LineStyle(
                color = ColorStateList(
                    normal = Color(0.0f, 0.5f, 1.0f, 1.0f),
                    highlighted = Color(0.0f, 0.7f, 1.0f, 1.0f)
                ),
                gapColor = ColorStateList(
                    normal = Color(0.0f, 0.0f, 0.0f, 0.0f),
                    highlighted = Color(0.0f, 0.0f, 0.0f, 0.0f)
                ),
                opacity = 1.0f,
                blur = 0.0f,
                widthType = SizeType.SCREEN_PIXEL,
                width = 3.0f,
                dashArray = arrayListOf(),
                lineCap = LineCapType.ROUND,
                lineJoin = LineJoinType.ROUND
            )
        )
        lineLayer.add(line)
        mapView.addLayer(lineLayer.asLayerInterface())
    }
}

Build docs developers (and LLMs) love