Skip to main content
Raster tile layers display map data as pre-rendered image tiles. Open Mobile Maps provides convenient APIs to work with web mercator tiles and custom tile configurations.

Basic Setup

The simplest way to add a raster layer is using TiledRasterLayer with web mercator tiles.
val tiledRasterLayer = TiledRasterLayer()
mapView.addLayer(tiledRasterLayer)

Custom Data Loader

You can configure the data loader with custom parameters or provide your own implementation.
val dataLoader = DataLoader(this, cacheDir, 50L * 1024L * 1024L, "example-referrer")
val tiledRasterLayer = TiledRasterLayer(dataLoader)
mapView.addLayer(tiledRasterLayer)

DataLoader Parameters

context
Context
required
Android context for the loader
cacheDir
File
required
Directory for tile caching
cacheSize
Long
required
Maximum cache size in bytes (e.g., 50L * 1024L * 1024L for 50MB)
referrer
String
Referrer string for HTTP requests

Custom Layer Configuration

For different tile services or tile pyramids, create a custom Tiled2dMapLayerConfig.
private val customConfig = object : Tiled2dMapLayerConfig() {
    // Defines the bounds of the layer and implicitly the coordinate system used by the layer as well
    val epsg3857Bounds: RectCoord = RectCoord(
        Coord(CoordinateSystemIdentifiers.EPSG3857(), -20037508.34, 20037508.34, 0.0),
        Coord(CoordinateSystemIdentifiers.EPSG3857(), 20037508.34, -20037508.34, 0.0)
    )

    // Defines to map coordinate system of the layer
    override fun getCoordinateSystemIdentifier() : Int = CoordinateSystemIdentifiers.EPSG3857()

    // The layer's name
    override fun getLayerName(): String = "OSM_Layer"

    // Defines the url-pattern to load tiles. Enter a valid OSM tile server here
    override fun getTileUrl(x: Int, y: Int, t: Int, zoom: Int): String {
        return "https://a.tile.openstreetmap.org/$zoom/$x/$y.png"
    }

    // Defines origin corner of the data in vector tiles
    override fun getVectorSettings(): Tiled2dMapVectorSettings? = null

    // Defines the extent (in layer system coordinates) that defines the bounds of this layer
    override fun getBounds(): RectCoord? = null

    // Defines both an additional scale factor for the tiles (and if they are scaled to match the target
    // devices screen density), how many layers above the ideal one should be loaded an displayed as well,
    // as well as if the layer is drawn, when the zoom is smaller/larger than the valid range
    override fun getZoomInfo(): Tiled2dMapZoomInfo {
        return Tiled2dMapZoomInfo(
            zoomLevelScaleFactor = 0.6667f,
            numDrawPreviousLayers = 2,
            numDrawPreviousOrLaterTLayers = 0,
            adaptScaleToScreen = true,
            maskTile = false,
            underzoom = true,
            overzoom = true
        )
    }

    // List of valid zoom-levels and their target zoom-value, the tile size in
    // the layers coordinate system, the number of tiles on that level and the
    // zoom identifier used for the tile-url (see getTileUrl above)
    override fun getZoomLevelInfos(): ArrayList<Tiled2dMapZoomLevelInfo> = ArrayList(
        listOf(
            Tiled2dMapZoomLevelInfo(559082264.029, 40075016f, 1, 1, 1, 0, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(279541132.015, 20037508f, 2, 2, 1, 1, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(139770566.007, 10018754f, 4, 4, 1, 2, epsg3857Bounds),
            // ... additional zoom levels
        )
    )
}

Configuration Parameters

getCoordinateSystemIdentifier()
Int
required
The coordinate system identifier (e.g., EPSG3857)
getLayerName()
String
required
The name of the layer
getTileUrl()
String
required
URL pattern for loading tiles with {x}, {y}, and {zoom} placeholders
getBounds()
RectCoord
The extent in layer system coordinates that defines the bounds
getZoomInfo()
Tiled2dMapZoomInfo
required
Configuration for zoom behavior including scale factors and layer drawing preferences
getZoomLevelInfos()
ArrayList<Tiled2dMapZoomLevelInfo>
required
List of zoom level configurations including tile dimensions and identifiers

Zoom Info Parameters

zoomLevelScaleFactor
Float
Additional scale factor for tiles (e.g., 0.6667f)
numDrawPreviousLayers
Int
How many layers above the ideal one should be loaded and displayed
adaptScaleToScreen
Boolean
Whether tiles are scaled to match the target device’s screen density
underzoom
Boolean
Whether the layer is drawn when zoom is smaller than the valid range
overzoom
Boolean
Whether the layer is drawn when zoom is larger than the valid range

Build docs developers (and LLMs) love