Overview
Open Mobile Maps for Android provides several layer types for rendering different kinds of map data. Each layer implements the LayerInterface and can be added to a MapView.
PolygonLayerInterface
Displays filled polygons on the map with support for holes and user interaction.
create()
Creates a new polygon layer instance.
val polygonLayer = PolygonLayerInterface.create()
Returns: PolygonLayerInterface - A new polygon layer
add()
Adds a polygon to the layer.
fun add(polygon: PolygonInfo)
The polygon to add, containing identifier, coordinates, colors, and styling
setLayerClickable()
Enables or disables click interaction for the layer.
fun setLayerClickable(clickable: Boolean)
Whether the layer should respond to click events
setCallbackHandler()
Sets the callback handler for user interactions.
fun setCallbackHandler(handler: PolygonLayerCallbackInterface)
handler
PolygonLayerCallbackInterface
required
Callback handler with onClickConfirmed(polygon: PolygonInfo) method
Example
val polygonLayer = PolygonLayerInterface.create()
polygonLayer.add(
PolygonInfo(
identifier = "Polygon",
coordinates = PolygonCoord(
positions = listOf(/* coordinates */),
holes = listOf(/* hole coordinates */)
),
color = Color(1.0f, 0.0f, 0.0f, 0.5f),
highlightColor = Color(1.0f, 0.4f, 0.4f, 0.7f)
)
)
polygonLayer.setLayerClickable(true)
polygonLayer.setCallbackHandler(object : PolygonLayerCallbackInterface() {
override fun onClickConfirmed(polygon: PolygonInfo) {
// Handle click
}
})
mapView.addLayer(polygonLayer.asLayerInterface())
IconLayerInterface
Displays icons (textures) at specified coordinates with configurable scaling and anchoring.
create()
Creates a new icon layer instance.
val iconLayer = IconLayerInterface.create()
Returns: IconLayerInterface - A new icon layer
add()
Adds an icon to the layer.
fun add(icon: IconInfoInterface)
icon
IconInfoInterface
required
The icon to add, created using IconFactory
setLayerClickable()
Enables or disables click interaction for the layer.
fun setLayerClickable(clickable: Boolean)
setCallbackHandler()
Sets the callback handler for user interactions.
fun setCallbackHandler(handler: IconLayerCallbackInterface)
handler
IconLayerCallbackInterface
required
Callback handler with onClickConfirmed() and onLongPress() methods
Example
val iconLayer = IconLayerInterface.create()
val texture = BitmapTextureHolder(/* drawable or bitmap */)
val icon = IconFactory.createIcon(
identifier = "Icon",
coordinate = coordinate,
texture = texture,
iconSize = Vec2F(iconSize, iconSize),
scaleType = IconType.INVARIANT,
blendMode = BlendMode.NORMAL
)
iconLayer.add(icon)
iconLayer.setLayerClickable(true)
iconLayer.setCallbackHandler(object : IconLayerCallbackInterface() {
override fun onClickConfirmed(icons: ArrayList<IconInfoInterface>): Boolean {
// Handle click
return true
}
override fun onLongPress(icons: ArrayList<IconInfoInterface>): Boolean {
// Handle long press
return true
}
})
mapView.addLayer(iconLayer.asLayerInterface())
LineLayerInterface
Displays styled lines on the map with support for dashed patterns, colors, and widths.
create()
Creates a new line layer instance.
val lineLayer = LineLayerInterface.create()
Returns: LineLayerInterface - A new line layer
add()
Adds a line to the layer.
fun add(line: LineInfoInterface)
line
LineInfoInterface
required
The line to add, created using LineFactory
setLayerClickable()
Enables or disables click interaction for the layer.
fun setLayerClickable(clickable: Boolean)
setCallbackHandler()
Sets the callback handler for user interactions.
fun setCallbackHandler(handler: LineLayerCallbackInterface)
handler
LineLayerCallbackInterface
required
Callback handler with onLineClickConfirmed(line: LineInfoInterface) method
Example
val lineLayer = LineLayerInterface.create()
val line = LineFactory.createLine(
identifier = "lineIdentifier",
coordinates = lineCoordinates,
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 = lineWidth,
dashArray = arrayListOf(4.0f, 2.0f),
lineCap = LineCapType.SQUARE,
lineJoin = LineJoinType.ROUND
)
)
lineLayer.add(line)
lineLayer.setLayerClickable(true)
lineLayer.setCallbackHandler(object : LineLayerCallbackInterface() {
override fun onLineClickConfirmed(line: LineInfoInterface) {
// Handle click
}
})
mapView.addLayer(lineLayer.asLayerInterface())
TiledRasterLayer
Displays tiled raster images (like OpenStreetMap tiles).
Constructor
val tiledRasterLayer = TiledRasterLayer()
Creates a layer with default DataLoader implementation using OkHttp.
Custom DataLoader
val dataLoader = DataLoader(context, cacheDir, 50L * 1024L * 1024L, "example-referrer")
Directory for caching tiles
Maximum cache size in bytes
HTTP referrer string for tile requests
TiledVectorLayer
Displays vector tiles using a style.json specification.
Constructor
val tiledVectorLayer = TiledVectorLayer(context, styleUrl)
URL to the vector tile style.json
Example:
val tiledVectorLayer = TiledVectorLayer(
context,
"https://www.sample.org/base-map/style.json"
)
mapView.addLayer(tiledVectorLayer)