THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Map layer filtering

Allow your users to apply a filter based on feature properties to only show selected layers.

Sample use case: You are using Traffic Module in your application, and you only want to show the traffic flow on Motorways.

You can achieve that by applying a filter that takes the value of the "road_type" property defined in the Traffic Vector Flow Tiles and compares it with the "Motorway" value. In this case the filter needs to be applied on layers that have a layer with an id of "Traffic flow" as their source layer.

To retrieve all those layers you can use the findLayersBySourceLayerId method as shown in the following code snippet:

//LAYERS_REGEX = "Traffic flow"
val layers = tomtomMap.styleSettings.findLayersBySourceLayerId(LAYERS_REGEX)

Once you have a list of layers, you can create the expression defining the filter (it is required to create a new instance of the expression for every layer):

1//ROAD_TYPE = "road_type"
2//ROAD_TYPE_MOTORWAY = "Motorway"
3val filteringExpression = ComparisonExpression.eq(
4 GetExpression.get(ROAD_TYPE),
5 LiteralExpression.string(ROAD_TYPE_MOTORWAY)
6)

To apply the filer you have to provide it to the setFiler method of the Layer object:

layer.setFilter(filteringExpression)

Removing the filter is done by calling the resetFilter method of the Layer object.

layer.resetFilter()

image

Show traffic only on motorways

image

Show traffic only on major roads

image

Show traffic on all roads