3D Buildings
Add a FillExtrusionLayer on the building source layer. The Street style ships this already; the other six styles draw buildings flat.
Filter on extrude. The layer carries a boolean marking the footprints meant to stand up, and the Street style filters on the same flag. Take the base from min_height, so parts that begin above ground level do not sink into the surface.
3D terrain is not available here: setTerrain() raises an UnsupportedError on MapLibre Native. See 3D Buildings and Terrain.
import org.maplibre.android.style.layers.FillExtrusionLayer
import org.maplibre.android.style.layers.PropertyFactory
import org.maplibre.android.style.expressions.Expression.eq
import org.maplibre.android.style.expressions.Expression.get
import org.maplibre.android.style.expressions.Expression.literal
mapView.getMapAsync { map ->
map.getStyle { style ->
val buildings = FillExtrusionLayer("buildings-3d", "mtk").apply {
sourceLayer = "building"
minZoom = 14f
setFilter(eq(get("extrude"), literal(true)))
setProperties(
PropertyFactory.fillExtrusionColor("#cfd8dc"),
PropertyFactory.fillExtrusionHeight(get("height")),
PropertyFactory.fillExtrusionBase(get("min_height")),
PropertyFactory.fillExtrusionOpacity(0.9f)
)
}
style.addLayer(buildings)
}
}Tilt the camera, or the extrusions are only ever seen from directly above:
map.cameraPosition = CameraPosition.Builder()
.target(LatLng(51.50222, -0.12025))
.zoom(15.5)
.tilt(60.0)
.build()