Skip to main content
This example demonstrates how to set up a basic raster map using OpenStreetMap tiles. The map displays a tiled raster layer with web mercator projection.

Complete Setup

import io.openmobilemaps.mapscore.map.MapView
import io.openmobilemaps.mapscore.map.MapConfig
import io.openmobilemaps.mapscore.shared.map.coordinates.CoordinateSystemFactory
import io.openmobilemaps.mapscore.shared.map.coordinates.CoordinateSystemIdentifiers
import io.openmobilemaps.mapscore.shared.map.coordinates.Coord
import io.openmobilemaps.mapscore.shared.map.layers.tiled.raster.TiledRasterLayer
import io.openmobilemaps.mapscore.MapsCore

class MainActivity : AppCompatActivity() {
    private lateinit var mapView: MapView
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Initialize the library
        MapsCore.initialize()
        
        // Get reference to MapView from layout
        mapView = findViewById(R.id.mapView)
        
        // Setup map with EPSG:3857 coordinate system (Web Mercator)
        mapView.setupMap(MapConfig(CoordinateSystemFactory.getEpsg3857System()))
        mapView.registerLifecycle(lifecycle)
        
        // Create tiled raster layer with OpenStreetMap tiles
        val tiledRasterLayer = TiledRasterLayer()
        
        // Add layer to map
        mapView.addLayer(tiledRasterLayer)
        
        // Move camera to initial position (Switzerland)
        mapView.getCamera().moveToCenterPositionZoom(
            Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.378232525377973, 46.962592372639634, 0.0),
            10000000.0,
            false
        )
    }
}

Installation

Add the MavenCentral dependency to your build.gradle:
dependencies {
  implementation 'io.openmobilemaps:mapscore:3.7.1'
}
Make sure you have mavenCentral() listed in your project repositories.

Result

The map will display OpenStreetMap tiles centered on Switzerland with a zoom level of 10,000,000 units. Users can pan, zoom, and interact with the map using standard gestures.

Build docs developers (and LLMs) love