Skip to main content

Building

Not compatible with the Maps SDK v10
This plugin is not compatible with the Maps SDK v10 or higher. To add 3D buildings in an application using the Maps SDK v10 or higher, see the Fill extrusion layer section of the Work with layers guide.

The Building Plugin for Android enables developers to add 3D buildings to a map in an Android application with a few lines of code.

Support for extrusions was added with 5.1.0 of the Map SDK, unlocking the possibility to display 3D buildings on your favorite map style. The building plugin extends this functionality and makes it even easier to add buildings to a map style.

Install the Building Plugin

To start developing an application using the Building Plugin, you'll need to add the appropriate dependencies inside your build.gradle file. This dependency includes the Maps SDK for Android. You can find all dependencies given below on MavenCentral.

Android's 64K method count limit
If your application is over the 64K method limit, you can shrink, obfuscate, and optimize your code with R8 or ProGuard. If those steps do not lower your method count below 64K, you can also enable multidex.

Add the dependency

Support for extrusions was added with 5.1.0 of the Maps SDK, unlocking the possibility to display 3D buildings on your favorite map style. The building plugin extends this functionality and makes it even easier to add buildings to a map style. To install, head over to the Mapbox Plugin Overview page which will walk you through adding the dependency.

  1. Start Android Studio.
  2. Open up your application's build.gradle file.
  3. Make sure that your project's minSdkVersion is API 14 or higher.
  4. Under dependencies, add a new build rule for the latest mapbox-android-plugin-building-v9.
repositories {
mavenCentral()
}

dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-building-v9:0.7.0'
}
  1. Click the Sync Project with Gradle Files near the toolbar in Studio.

Add the Building Plugin

The Building Plugin requires no additional permissions and initialized by passing in both the map view and mapboxMap objects that you'd like the building layer to show on. Besides the required parameters, you also have the option to provide a layer ID which you'd like the buildings to appear below. Once initialized, setting setVisibility() to true will result in the building layer getting added on top of your map style.

val buildingPlugin = BuildingPlugin(mapView, mapboxMap, style)
buildingPlugin.setVisibility(true)

Customization

While the building plugin provides default values which look good for most use cases, you might find yourself wanting to customize the look of the buildings to match a map style. Several APIs are available for changing building color, opacity, what zoom level buildings should start appearing, etc. The table below provides information on the current APIs useful for customization.

APIDescription
setMinZoomLevelThis is the minimum zoom level where buildings will start to show. useful to limit showing buildings at higher zoom levels.
setColorChange the building color to any Android color int value.
setOpacityFloat value between 0.0 and 1.0 representing the opacity of the buildings. 1.0 being solid and 0.0 being invisible.
Was this page helpful?