Sorry, you need to enable JavaScript to visit this website.

Map layer filtering

Map layer filtering

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

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

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

To retrieve all those layers you can use findLayersBySourceLayerId method as shown below:

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

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

//ROAD_TYPE = "road_type"
val filteringExpression = ComparisonExpression.eq(GetExpression.get(ROAD_TYPE), LiteralExpression.string(ROAD_TYPE_MOTORWAY))

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


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



Show traffic on only motorways


Show traffic only on major roads


Show traffic on all roads

You are here