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
Unique identifier for the icon
The position where the icon should be displayed
texture
TextureHolderInterface
required
The texture to display (use BitmapTextureHolder for drawables/bitmaps)
The size of the icon (width, height)
How the icon scales with camera zoom (INVARIANT keeps constant screen size)
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
Unique identifier for the icon
The position where the icon should be displayed
texture
TextureHolderInterface
required
The texture to display
The size of the icon (width, height)
How the icon scales with camera zoom
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
Unique identifier for the line
List of coordinates defining the line path
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
Colors for normal and highlighted states
Colors for gaps in dashed lines (normal and highlighted states)
Blur amount for the line edges
How width is measured: SCREEN_PIXEL or MAP_UNIT
Line width in the specified unit type
Pattern for dashed lines (e.g., [4.0, 2.0] for 4px dash, 2px gap)
Fade effect for dash transitions
Speed of dash animation (0 for no animation)
End cap style: BUTT, ROUND, or SQUARE
Join style at vertices: BEVEL, ROUND, or MITER
Offset perpendicular to the line direction
Whether to render as dotted line
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())
}
}