Use 3D Terrain
This example demonstrates how to create a realistic 3D terrain map with atmospheric and sky effects using the Mapbox Maps SDK for Android. It sets up a map styled with the Style.SATELLITE_STREETS
style, incorporating a raster DEM (Digital Elevation Model) source to render detailed elevation data. The terrain uses tiles from the Mapbox Terrain-DEM v1 tileset.
The map also includes an atmospheric sky layer configured with SkyType.ATMOSPHERE
to simulate realistic daylight conditions. The globe projection is enabled to provide an accurate representation of the Earth's curvature. This setup offers a visually engaging and immersive experience, highlighting the advanced capabilities of the Maps SDK for creating dynamic 3D environments.
This example code is part of the Maps SDK for Android Examples App, a working Android project available on GitHub. Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.
See our Run the Maps SDK for Android Examples App tutorial for step-by-step instructions.
package com.mapbox.maps.testapp.examples.terrain3D
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.atmosphere.generated.atmosphere
import com.mapbox.maps.extension.style.layers.generated.skyLayer
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
import com.mapbox.maps.extension.style.layers.properties.generated.SkyType
import com.mapbox.maps.extension.style.projection.generated.projection
import com.mapbox.maps.extension.style.sources.generated.rasterDemSource
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.extension.style.terrain.generated.terrain
import com.mapbox.maps.testapp.databinding.ActivityTerrainShowcaseBinding
/**
* Example that demonstrates realistic map with 3D terrain and atmosphere sky layer.
*/
class Terrain3DShowcaseActivity : AppCompatActivity() {
private lateinit var mapboxMap: MapboxMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityTerrainShowcaseBinding.inflate(layoutInflater)
setContentView(binding.root)
mapboxMap = binding.mapView.mapboxMap
mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE_STREETS) {
+rasterDemSource(SOURCE) {
url(TERRAIN_URL_TILE_RESOURCE)
// 514 specifies padded DEM tile and provides better performance than 512 tiles.
tileSize(514)
}
+terrain(SOURCE)
+skyLayer(SKY_LAYER) {
skyType(SkyType.ATMOSPHERE)
skyAtmosphereSun(listOf(-50.0, 90.2))
}
+atmosphere { }
+projection(ProjectionName.GLOBE)
}
)
}
companion object {
private const val SOURCE = "TERRAIN_SOURCE"
private const val SKY_LAYER = "sky"
private const val TERRAIN_URL_TILE_RESOURCE = "mapbox://mapbox.mapbox-terrain-dem-v1"
}
}