Skip to main content
This example demonstrates how to enable 3D rendering mode to display your map as a globe. The 3D mode provides a more realistic representation of the Earth with proper perspective and curvature.

3D Map 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.shared.map.layers.tiled.vector.TiledVectorLayer
import io.openmobilemaps.mapscore.MapsCore

class Globe3DActivity : AppCompatActivity() {
    private lateinit var mapView: MapView
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        MapsCore.initialize()
        mapView = findViewById(R.id.mapView)
        
        // Setup map with EPSG:3857 coordinate system
        val mapConfig = MapConfig(CoordinateSystemFactory.getEpsg3857System())
        mapView.setupMap(mapConfig)
        mapView.registerLifecycle(lifecycle)
        
        // Add vector or raster layer for 3D rendering
        val tiledVectorLayer = TiledVectorLayer(
            this,
            "https://www.sample.org/base-map/style.json"
        )
        mapView.add(tiledVectorLayer)
        
        // Alternatively, use raster layer:
        // val tiledRasterLayer = TiledRasterLayer()
        // mapView.addLayer(tiledRasterLayer)
        
        // Set camera to view from higher altitude for globe effect
        mapView.getCamera().moveToCenterPositionZoom(
            Coord(CoordinateSystemIdentifiers.EPSG4326(), 0.0, 30.0, 0.0),
            50000000.0, // Higher zoom value for globe view
            false
        )
        
        // Set minimum zoom to maintain globe perspective
        mapView.getCamera().setMinZoom(20000000.0)
        mapView.getCamera().setMaxZoom(300.0)
    }
}

3D Mode with Custom Projection

You can use different coordinate systems for 3D rendering:
// Setup map with EPSG:2056 coordinate system for 3D
val mapConfig = MapConfig(
    CoordinateSystemFactory.getEpsg2056System()
)
mapView.setupMap(mapConfig)
mapView.registerLifecycle(lifecycle)

// Add layers
val tiledRasterLayer = TiledRasterLayer()
mapView.addLayer(tiledRasterLayer)

// Camera settings for 3D view
mapView.getCamera().moveToCenterPositionZoom(
    Coord(CoordinateSystemIdentifiers.EPSG4326(), 8.378232525377973, 46.962592372639634, 0.0),
    5000000.0,
    false
)

3D with Multiple Layers

Combine raster base maps with vector overlays in 3D:
// Add base raster layer
val baseRasterLayer = TiledRasterLayer()
mapView.addLayer(baseRasterLayer)

// Add vector overlay for labels and details
val vectorOverlay = TiledVectorLayer(
    this,
    "https://www.sample.org/overlay/style.json"
)
mapView.add(vectorOverlay)

// Set camera for globe view
mapView.getCamera().moveToCenterPositionZoom(
    Coord(CoordinateSystemIdentifiers.EPSG4326(), 0.0, 20.0, 0.0),
    40000000.0,
    true
)

Camera Controls for 3D

When using 3D mode, adjust the camera zoom limits to provide the best globe experience:
// Set minimum zoom (higher value = more zoomed out)
mapView.getCamera().setMinZoom(20000000.0)

// Set maximum zoom (lower value = more zoomed in)
mapView.getCamera().setMaxZoom(300.0)

Best Practices for 3D

  1. Vector over Raster: Use vector layers when possible for crisp rendering at all zoom levels and angles
  2. Zoom Limits: Set appropriate minimum zoom to maintain globe perspective
  3. Initial Position: Start with a higher altitude view to showcase the globe effect
  4. Performance: 3D rendering is more GPU-intensive; test on target devices
  5. Layer Order: Place base terrain layers first, then overlays and labels

Result

The map will render as a 3D globe with proper Earth curvature and perspective. Users can rotate, tilt, and zoom the globe to explore the map from any angle.

Build docs developers (and LLMs) love