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

Map Extensions

Map Extensions

Have a look at our map extensions to make development more concise and pleasant.

Map UI Extensions

Android Maps SDK provides the following built-in UI views:

  • Compass button

  • Current location button

  • Panning controls

  • Zooming controls

You can toggle the visibility of these views using the UiSettings class.
Changes made on this class are reflected on the map immediately.
Each UI element has a pre defined style that determines its position relative to the edge of the map.
This style can be overridden to provide custom position, adjust size or replace default colors.
It is also possible to alter these parameters in runtime by modifying view’s LayoutParams.

To use this library, add the following dependency to the build.gradle file:

api("com.tomtom.online:sdk-maps-ui-extensions:2.+")
Compass

By default, the compass button is enabled and located in the top left corner of the map - ‘MapView'. The compass appears only when the map orientation is different than zero (‘North' position). When the user clicks on the compass button, the map orientation is set to zero and the compass disappears.

 



image

Default

image

Pressed

image

North up

 

  • To disable the compass button:

tomtomMap.getUiSettings().getCompassView().hide();

 

  • To enable the compass button:

tomtomMap.getUiSettings().getCompassView().show();

 

  • To override default style:

<style name="CompassView" parent="BaseCompactView">
    <item name="android:layout_gravity">top|start</item>
    <item name="android:layout_marginStart">@dimen/compass_default_margin_start</item>
    <item name="android:layout_marginTop">@dimen/compass_default_margin_top</item>
</style>

 

Current location

By default, the current location button is enabled and placed in the bottom left corner of the map -'MapView'. The current location button appears only when the map center position on the screen is different from user’s current location. When the user clicks on the current location button, the map location is set to the user’s location and the button disappears.
The default action for the button centres the map on the user’s location if 'MapView' has set up shown current position on 'YES'.

 



image

Default

image

Pressed

 

  • To disable the current location button:

tomtomMap.getUiSettings().getCurrentLocationView().hide();

 

  • To enable the current location button:

tomtomMap.getUiSettings().getCurrentLocationView().show();

 

  • To override default style:

<style name="CenterOnCurrentLocationView" parent="BaseCompactView">
    <item name="android:layout_gravity">bottom|start</item>
    <item name="android:layout_marginStart">@dimen/compass_default_margin_start</item>
    <item name="android:layout_marginBottom">@dimen/current_location_default_margin_bottom
    </item>
</style>

 

Panning controls

By default, the panning controls view is disabled and it is placed vertically in the center and horizontally on right site of the map -'MapView'.
The default action for the view is to move the map in desired direction.

 



image
image

Pan down

image
image

Pan left

image
image

Pan right

image
image

Pan up

 

  • To enable the panning controls:

tomtomMap.getUiSettings().getPanningControlsView().show();

 

  • To disable the panning controls:

tomtomMap.getUiSettings().getPanningControlsView().hide();

 

  • To override default style:

<style name="ArrowButton" parent="GenericControlButton" />

<style name="ArrowButtonsGroup" parent="GenericControlButtonsGroup">
    <item name="android:layout_width">150dp</item>
    <item name="android:layout_marginRight">80dp</item>
</style>

 

Zooming controls

By default, the zooming controls view is disabled and it is placed vertically in the center and horizontally on right site of the map -'MapView'.
The default action for the view is to zoom in or zoom out the map.

 



image
image

Zoom in

image
image

Zoom out

 

  • To enable the zooming controls:

tomtomMap.getUiSettings().getZoomingControlsView().show();

 

  • To disable the zooming controls:

tomtomMap.getUiSettings().getZoomingControlsView().hide();

 

  • To override default style:

<style name="ZoomButton" parent="GenericControlButton" />

<style name="ZoomButtonsGroup" parent="GenericControlButtonsGroup">
    <item name="android:layout_width">@dimen/control_button_default_size</item>
</style>

 

Map ReactX Extensions

Additional classes that allow to write reactive components using TomtomMap. Specific map callbacks
(e.g. map click listener) are transformed to Observables so they can be easily integrated
with RxJava2 types. This module does not add any new features to the existing TomtomMap API.

To use this library, add the following dependency to the build.gradle file:

api("com.tomtom.online:sdk-maps-rx-extensions:2.+")

To initialize the Rx wrapper for TomtomMap:

RxTomtomMap rxTomtomMap = new RxTomtomMap(tomtomMap);

To subscribe for map click events:

Disposable mapClickDisposable = rxTomtomMap
        .getOnMapClickObservable()
        .observeOn(mainThread())
        .subscribe(new Consumer<LatLng>() {
            @Override
            public void accept(LatLng latLng) throws Exception {
                displayMessage(
                        R.string.menu_events_on_map_click,
                        latLng.getLatitude(),
                        latLng.getLongitude()
                );
            }
        });

Map Kotlin Extensions

Additional classes that make development with Kotlin more pleasant and idiomatic.
This module does not add any new features to the existing TomtomMap API.

To use this library, add the following dependency to the build.gradle file:

api("com.tomtom.online:sdk-maps-ktx-extensions:2.+")

To apply an operation on the TomtomMap:

inline fun MapFragment.applyOnTomtomMap(noinline block: TomtomMap.() -> Unit) {
    getAsyncMap(block)
}

To take advantage of coroutines:

suspend inline fun MapFragment.getTomtomMap(): TomtomMap = suspendCoroutine { cont ->
    val callback = OnMapReadyCallback { tomtomMap -> cont.resume(tomtomMap) }
    getAsyncMap(callback)
}

Static Map Image

Allow your user to render a user-defined, rectangular image, containing a map section.

For more details, please visit Static Map Image documentation

Sample use case 1: Your app is designed to use simple map. You do not want to show the entire map,
just some part of it to show and mark something simple. You don’t have to download the whole sdk-maps
library which is much heavier comparing to this library.

To use this library, add the following dependency to the build.gradle file:

api("com.tomtom.online:sdk-maps-static-image:2.+")

Example of displaying static map:

StaticImage.builder(getMapApiKey(getContext()))
        .center(Locations.AMSTERDAM_LOCATION) //use center or boundingBox
        .layerBasic() // basic layer is default
        .styleMain() // main style is default
        .mapSize(512, 512) // default size in px
        .png() //png is default
        .build()
        .downloadInto(staticMap1);


image

Sample image retrieved from static map service.

image

Examples of static map images.

Map Styles Extensions

Maps SDK gives you a possibility to use either online or offline styles in your mobile application.

  • If you choose to use offline styles, they will be imported to your app with the Map SDK package.
    Thanks to that the style will be included in your app already at the app download time.
    The styles are added to the Maps SDK package by default.

  • If you choose to use online styles, they will be downloaded into your application when the map is
    to displayed for the first time. Thanks to that, your mobile app size is smaller at the app download
    time so your app downloadable is lighter. In this case you need exclude offline styles from sdk.

Offline styles

To use offline style library you don’t have to do any action, because offline styles are attached to
the map by default. To use offline style library with your custom map, add the following dependency to
the build.gradle file:

implementation("com.tomtom.online:sdk-maps-styles-extensions:2.+")

When offline style are not attached to the project and online style is not setup for the map then black screen will instead a map.

 



image

Screen without style

 

Online styles

To exclude offline style from sdk-maps module use exclude declaration when sdk-maps module is
decelerated.

api("com.tomtom.online:sdk-maps:$rootProject.internalVersions.sdk@aar") {
            transitive = true
            exclude module: 'sdk-maps-styles-extensions'
        }

When offline style are excluded then the online style should be setup.
You can setup online style in MapFragment:

<fragment
    android:id="@+id/map_fragment"
    android:name="com.tomtom.online.sdk.map.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tomtom:customStyleUrl="http://your-server:port/style/example-merged.json" />

You can setup online style in MapView:

<?xml version="1.0" encoding="utf-8"?>
<com.tomtom.online.sdk.map.MapView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tomtom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map_view"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    tomtom:styleUrl="asset://styles/night.json"
    >
</com.tomtom.online.sdk.map.MapView>

To use offline style library you don’t have to do any action, because offline style are
attached to the map by default.

To use offline style library with your custom map, add the following dependency to the build.gradle file:

implementation("com.tomtom.online:sdk-maps-styles-extensions:2.+")