THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Map layers visibility

Allow your users to dynamically toggle the visibility of map entities. You can hide map layers to get the level of detail you need and highlight the layers that are important for your use case.

Sample use case: You want to provide a clear map view for driving that focuses on the road network in your app. You can achieve that by switching off some map layers e.g., woodland, build-up areas, etc. You can turn these layers back on at run time to bring back the details for a better map viewing experience.

The following articles provide more information on map layer visibility and map layers available in the default style: Map layers.

You can retrieve all layers available in the style or only those that match the provided regex. To filter, you can use layer ID or source layer ID properties, as shown in the following code snippets:

//ROADS_NETWORK_LAYER_REGEX = "[mM]otorway.*|.*[rR]oad.*"
List<Layer> layers = tomtomMap.getStyleSettings().findLayersBySourceLayerId(ROADS_NETWORK_LAYER_REGEX)
//regex = e.g. "[mM]otorway.*|.*[rR]oad.*" or "[wW]oodland" or "Built-up area"
val layers = tomtomMap.styleSettings.findLayersBySourceLayerId(String.format(regex))

Once you have a list of layers, you can modify their visibility:

1for (Layer layer : layers) {
2 layer.setVisibility(visibility);
3}
layers.forEach { layer -> layer.visibility = visibility }

image

Road network hidden

image

Woodland and build-up shown