Apply Custom Map Style ¶
Setup ¶
Download the Maps & Navigation SDK for Android archive file
Download the
ApplyCustomMapStyle
project
archive file or clone the project with Git
See the Configure Android Example guide.
Run the example ¶
In Android Studio, from the
File
menu, select
Sync
Project
with
Gradle
Files
|
|
How it works ¶

You can open the MainActivity.kt file to see how an interactive map is rendered and then the custom map style is applied.
1private fun applyCustomAssetStyle(mapView: MapView?) = SdkCall.execute {
2 val filename = "(Desktop) Monochrome Deep Blue (5a1da93a-dbf2-4a36-9b5c-1370386c1496).style"
3
4 // Opens style input stream.
5 val inputStream = applicationContext.resources.assets.open(filename)
6
7 // Take bytes.
8 val data = inputStream.readBytes()
9 if (data.isEmpty()) return@execute
10
11 // Apply style.
12 mapView?.preferences?.setMapStyleByDataBuffer(DataBuffer(data))
13}
assets
folder of this example project.
mapView?.preferences?.setMapStyleByDataBuffer(DataBuffer(data))
1override fun onCreate(savedInstanceState: Bundle?)
2{
3 super.onCreate(savedInstanceState)
4 setContentView(R.layout.activity_main)
5
6 progressBar = findViewById(R.id.progressBar)
7 gemSurfaceView = findViewById(R.id.gem_surface)
8
9 SdkSettings.onMapDataReady = onMapDataReady@{ isReady ->
10 if (!isReady) return@onMapDataReady
11
12 applyCustomAssetStyle(gemSurfaceView.mapView)
13 }
14
15 SdkSettings.onApiTokenRejected = {
16 showDialog("TOKEN REJECTED")
17 }
18
19 if (!Util.isInternetConnected(this))
20 {
21 showDialog("You must be connected to internet!")
22 }
23}
MainActivity
overrides the
onCreate
function, which checks that
internet access is available, and then, when the map is ready, that is,
loaded and initialized, automatically applies the custom map style
stored in this example project’s
assets
folder:
applyCustomAssetStyle(gemSurfaceView.mapView)