Building Layer
Note
You can find the full source code of this example in BuildingFillExtrusionActivity.kt
of the MapLibreAndroidTestApp.
In this example will show how to add a Fill Extrusion layer to a style.
We use the OpenFreeMap Bright style which, unlike OpenFreeMap Libery, does not have a fill extrusion layer by default. However, if you inspect this style with Maputnik you will find that the multipolygons in the building
layer (of the openfreemap
source) each have render_min_height
and render_height
properties.
Setting up the fill extrusion layer
val fillExtrusionLayer = FillExtrusionLayer("building-3d", "openmaptiles")
fillExtrusionLayer.sourceLayer = "building"
fillExtrusionLayer.setFilter(
Expression.all(
Expression.has("render_height"),
Expression.has("render_min_height")
)
)
fillExtrusionLayer.minZoom = 15f
fillExtrusionLayer.setProperties(
PropertyFactory.fillExtrusionColor(Color.LTGRAY),
PropertyFactory.fillExtrusionHeight(Expression.get("render_height")),
PropertyFactory.fillExtrusionBase(Expression.get("render_min_height")),
PropertyFactory.fillExtrusionOpacity(0.9f)
)
style.addLayer(fillExtrusionLayer)