×
Apply Map Style | Maps SDK for Android | General Magic Apply Map Style — Maps & Navigation SDKs documentation
Skip to content

Apply Map Style

In this guide you will learn how to list the available map styles in the online content store, download a map style and change the map style used to render an interactive map.

Setup

First, get an API key token, see the Getting Started guide.

Download the Maps & Navigation SDK for Android archive file

Download the ApplyMapStyle 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

An android device should be connected via USB cable.
Press SHIFT+F10 to compile, install and run the example on the android device.
Android example screenshot

The example downloads a preset map style from the server, in this case, a map style with topography, and applies it to the map.

The map is interactive and fully 3D, supporting pan, pinch-zoom, rotate and tilt.

How it works

Android example screenshot

You can open the MainActivity.kt file to see how to change the map style.

1// Kotlin code
2SdkSettings.onMapDataReady =
3{
4    // Call to the content store to asynchronously retrieve the list of map styles.
5    contentStore.asyncGetStoreContentList(
6        EContentType.ViewStyleHighRes.value,
7        progressListener
8    )
9}

Get the list of map styles available for download from the online content store server. This launches the request to get the list.

 1contentStore.getStoreContentList(EContentType.ViewStyleHighRes.value)?.first?.let { styles ->
 2// The map style items list is not empty or null so we will select an item.
 3val style = if (styles.size > 1) styles[(styles.size / 2) - 1] else styles[0]
 4val styleName = style.getName() ?: "NO_NAME"
 5
 6// Define a listener to the progress of the map style download action.
 7val downloadProgressListener = ProgressListener.create(
 8    onStarted = {
 9        progressBar.visibility = View.VISIBLE
10        Toast.makeText(
11            this@MainActivity, "Started downloading $styleName.",
12            Toast.LENGTH_SHORT
13        ).show()
14    },
15
16    onCompleted = { _, _ ->
17        progressBar.visibility = View.GONE
18        Toast.makeText(
19            this@MainActivity,
20            "$styleName was downloaded. Applying style...",
21            Toast.LENGTH_SHORT
22        ).show()

This is the callback receiving the result of the list request. If the list of map styles from the server is not empty, select the map style in the middle of the list, or the first one, and download it.

1SdkCall.execute
2{
3    // Apply the style to the main map view.
4    gemSurfaceView.getDefaultMapView()?.preferences()
5        ?.setMapStyleById(style.getId())
6}

Set the map to use the newly downloaded map style.

Android Examples

Maps SDK for Android Examples can be downloaded or cloned with Git