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

Dynamic map sources

Dynamic map sources

Add layers and sources (e.g. GeoJSON, images) to the map in real time. This will allow you to
dynamically change 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. 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:

_

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

To create an Image source:

_

//IMAGE_SOURCE_ID = unique_source_id
//IMAGE_CORNERS = Four corners of the image (top left, top right, bottom right, bottom left)
ImageSource source = SourceFactory.createImageSource(IMAGE_SOURCE_ID, IMAGE_CORNERS);
source.setImage(getContext().getResources().getDrawable(R.drawable.buckingham_palace_plan));
tomtomMap.getStyleSettings().addSource(source);
//IMAGE_SOURCE_ID = unique_source_id
//IMAGE_CORNERS = Four corners of the image (top left, top right, bottom right, bottom left)
val source = SourceFactory.createImageSource(IMAGE_SOURCE_ID, IMAGE_CORNERS)
source.setImage(context.resources.getDrawable(R.drawable.buckingham_palace_plan))
tomtomMap.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

You are here