Custom Map Styles

The HERE SDK for Android provides a flexible solution to customize the map by loading custom map schemes.

If you are looking for predefined map styles, see the Quick Start guide for an introduction. The HERE SDK already includes a set of pre-configured map styles such as MapStyle.NORMAL_DAY or MapStyle.SATELLITE.

Create and Load Custom Map Styles

The most flexible solution to customize the map is to create your own map styles using a configuration file generated with the WYSIWYG HERE Style Editor.

Note

To access the HERE Style Editor, please contact your HERE representative - as the editor is not yet publicly available. Please note that the resulting map styles are not compatible with the web editor, so only the HERE Style Editor can be used with the HERE SDK. This HERE SDK release is compatible with the HERE Style Editor 0.53. It is recommended to use the latest style editor and to update existing styles in case of unexpected behavior or errors.

Screenshot: The HERE Style Editor showing a custom map configuration.

As soon as you are satisfied with your custom map style, export it via File -> Export -> Here Rendering Engine Configuration. Please unzip the resulting file. You will find a few JSON files.

Copy all JSON files into the "assets" directory of your project. If not already added, you can add that folder via Android Studio (Right-click on the project: New -> Folder -> Assets folder). You can also manually generate the folder.

The main style file always ends with *.scene.json.

Load the style into a map scene as follows:

private void loadMapStyle() {
    // Place the style into the "assets" directory.
    // Full path example: app/src/main/assets/mymapstyle.scene.json
    // Adjust file name and path as appropriate for your project.
    String fileName = "omv/omv-traffic-traffic-normal-night.scene.json";
    AssetManager assetManager = context.getAssets();
    try {
        assetManager.open(fileName);
    } catch (IOException e) {
        Log.e("CustomMapStylesExample", "Error: Map style not found!");
        return;
    }

    mapView.getMapScene().loadScene("" + fileName, new MapScene.LoadSceneCallback() {
        @Override
        public void onLoadScene(@Nullable MapError mapError) {
            if (mapError == null) {
                // Scene loaded.
            } else {
                Log.d("CustomMapStylesExample", "onLoadScene failed: " + mapError.toString());
            }
        }
    });
}

In the above snippet, we use Android's AssetManager to verify that the *.scene.json file exists at the expected location. You only have to load this file. From there, the HERE SDK will find the other files - as exported from the editor. Make sure that all style files are kept together at the same folder level. *.scene.json is the main file that includes references to the other files.

Screenshot: Another example for a custom map style configuration.

Using custom map styles can be very effective to differentiate your app from other map applications. In addition, it is possible to change map styles on-the-fly, for example, to shift the user's attention to certain map elements based on the current state of your app.

Note

You can find a CustomMapStyles example app on GitHub.

results matching ""

    No results matching ""