THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Dynamic map sources

Add layers and sources (e.g., GeoJSON, images) to the map in real time. This will allow you to dynamically change a map’s style in response to user interaction and context.

Sample use case 1: You want to add extra layers with building plans from your custom source.

Sample use case 2: You want to dynamically modify source parameters (e.g., a URL).

To create a layer and dynamically add it to the style:

Layer layer = LayerFactory.createLayer(layerJson)
tomtomMap.getStyleSettings().addLayer(layer);
val layer = LayerFactory.createLayer(layerJson)
tomtomMap.styleSettings.addLayer(layer)

To create a GeoJSON source and dynamically add it to the style:

1//GEOJSON_SOURCE_ID = unique_source_id
2//GeoJsonData = JSON representing source data
3GeoJsonSource source = SourceFactory.createGeoJsonSource(GEOJSON_SOURCE_ID);
4source.setGeoJson(geoJsonData);
5tomtomMap.getStyleSettings().addSource(source);
1//GEOJSON_SOURCE_ID = unique_source_id
2//GeoJsonData = JSON representing source data
3val source = SourceFactory.createGeoJsonSource(GEOJSON_SOURCE_ID)
4source.setGeoJson(geoJsonData)
5tomtomMap.styleSettings.addSource(source)

To create an Image source:

1//IMAGE_SOURCE_ID = unique_source_id
2//IMAGE_CORNERS = Four corners of the image (top left, top right, bottom right, bottom left)
3ImageSource source = SourceFactory.createImageSource(IMAGE_SOURCE_ID, IMAGE_CORNERS);
4source.setImage(getContext().getResources().getDrawable(R.drawable.buckingham_palace_plan));
5tomtomMap.getStyleSettings().addSource(source);
1//IMAGE_SOURCE_ID = unique_source_id
2//IMAGE_CORNERS = Four corners of the image (top left, top right, bottom right, bottom left)
3val source = SourceFactory.createImageSource(IMAGE_SOURCE_ID, IMAGE_CORNERS)
4ContextCompat.getDrawable(context, R.drawable.buckingham_palace_plan)?.let { source.setImage(it) }
5tomtomMap.styleSettings.addSource(source)

To remove a source or a layer from the style:

tomtomMap.getStyleSettings().removeLayer(GEOJSON_LAYER_ID);
tomtomMap.getStyleSettings().removeSource(GEOJSON_SOURCE_ID);
tomtomMap.styleSettings.removeLayer(layerId)
tomtomMap.styleSettings.removeSource(sourceId)

image

Custom GeoJSON source

image

Custom image source