Migration guide
This guide is designed to assist developers in migrating from XML layouts that utilize MapView and MapFragment to modern Jetpack Compose approach. It includes a comprehensive cheat sheet that outlines the key differences and advantages of using the TomTomMap APIs within a Compose environment compared to legacy implementations.
Members
Get Camera Position
XML
tomtomMap.cameraPositionCompose
// TomTomMap's statemapViewState.cameraState.data?.positionGet Camera Tracking Mode
XML
tomtomMap.cameraTrackingModeCompose
// TomTomMap's statemapViewState.cameraState.trackingModeGet Current Location
XML
tomtomMap.currentLocationCompose
// TomTomMap's statemapViewState.locationState.getCurrentLocation()Is Current Location In Bounding Box
XML
tomtomMap.isCurrentLocationInMapBoundingBoxCompose
// TomTomMap's statemapViewState.locationState.isCurrentLocationInMapBoundingBox()Is Gestures Enabled
XML
tomtomMap.isMultiPointerPanEnabledtomtomMap.isRotationEnabledtomtomMap.isScrollEnabledtomtomMap.isTiltEnabledtomtomMap.isZoomEnabledCompose
// TomTomMap's statemapViewState.gestureState.config.isMultiPointerPanEnabledmapViewState.gestureState.config.isRotationEnabledmapViewState.gestureState.config.isScrollEnabledmapViewState.gestureState.config.isTiltEnabledmapViewState.gestureState.config.isZoomEnabledPrimitive Operations
Add Marker
XML
val marker = tomtomMap.addMarker( options = markerOptions,)Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Marker( state = markerState, data = MarkerData(geoPoint = MARKER_GEOPOINT), properties = MarkerProperties(pinImage = PIN_IMAGE), )}Marker APIs
XML
marker.select()marker.deselect()marker.isSelected()Compose
markerState.select()markerState.deselect()markerState.isSelected()Add Markers
XML
val markers = tomtomMap.addMarkers( options = markersOptions,)Compose
private val listOfMarkers = listOf( MarkerEntry( markerId = firstMarkerId, data = MarkerData(geoPoint = MARKER_GEOPOINT), properties = MarkerProperties(pinImage = PIN_IMAGE), ),)TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Markers( state = markersState, markers = listOfMarkers, )}Markers APIs
XML
markers.firstOrNull()?.select()markers.firstOrNull()?.deselect()markers.firstOrNull()?.isSelected()Compose
markersState.selectMarker(firstMarkerId)markersState.deselectMarker(firstMarkerId)markersState.isMarkerSelected(firstMarkerId)Add Polyline
XML
tomtomMap.addPolyline( options = polylineOptions,)Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Polyline( data = PolylineData( geoPoints = listOf(GEOPOINT, GEOPOINT_2), ), )}Style Operations
Hide Hill Shading
XML
tomtomMap.hideHillShading()Compose
// TomTomMap's statemapViewState.styleState.showHillShading = falseHide Traffic Flow
XML
tomtomMap.hideTrafficFlow()Compose
trafficState.showTrafficFlow = falseHide Traffic Incidents
XML
tomtomMap.hideTrafficIncidents()Compose
trafficState.showTrafficIncidents = falseHide Vehicle Restrictions
XML
tomtomMap.hideVehicleRestrictions()Compose
// TomTomMap's statemapViewState.styleState.showVehicleRestrictions = falseLoad Style
XML
tomtomMap.loadStyle( style = StandardStyles.TomTomOrbisMaps.BROWSING, callback = styleLoadingCallback,)Compose
// TomTomMap's statemapViewState.styleState.loadStyle( style = StandardStyles.TomTomOrbisMaps.BROWSING,)Set Style Mode
XML
tomtomMap.setStyleMode( mode = StyleMode.DARK,)Compose
// TomTomMap's statemapViewState.styleState.styleMode = StyleMode.DARKEvent Listeners
Camera Steady Listener
XML
tomtomMap.addCameraSteadyListener { println("Camera steady event occurred")}Compose
// TomTomMap's statemapViewState.cameraState.data?.isStableLocation Marker Click Listener
XML
tomtomMap.addLocationMarkerClickListener { point: Point, geoPoint: GeoPoint -> println("Clicked at geoPoint: $geoPoint, screen: $point")}Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { CurrentLocationMarker( onClick = { offset: Offset, geoPoint: GeoPoint -> println("Clicked at geoPoint: $geoPoint, screen: $offset") }, )}Map Gestures Listeners
XML
tomtomMap.addMapClickListener { geoPoint: GeoPoint -> println("Map clicked at: $geoPoint") true}tomtomMap.addMapDoubleClickListener { geoPoint: GeoPoint -> println("Map double clicked at: $geoPoint") true}tomtomMap.addMapLongClickListener { geoPoint: GeoPoint -> println("Map long clicked at: $geoPoint") true}tomtomMap.addMapPanningListener( listener = mapPanningListener,)Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState, onMapClick = { geoPoint: GeoPoint -> println("Map clicked at: $geoPoint") }, onMapDoubleClickListener = { geoPoint: GeoPoint -> println("Map double clicked at: $geoPoint") }, onMapLongClick = { geoPoint: GeoPoint -> println("Map long clicked at: $geoPoint") }, onMapPanningListener = { println("Map panning event occurred") },Marker Click Listener
XML
tomtomMap.addMarkerClickListener { marker: Marker -> println("Marker click event occurred for: $marker")}Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Marker( state = markerState, data = MarkerData(geoPoint = MARKER_GEOPOINT), properties = MarkerProperties(pinImage = PIN_IMAGE), onClick = { println("Marker click event occurred") }, )}Marker Long Click Listener
XML
tomtomMap.addMarkerLongClickListener { marker: Marker -> println("Marker long click event occurred for: $marker")}Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Marker( state = markerState, data = MarkerData(geoPoint = MARKER_GEOPOINT), properties = MarkerProperties(pinImage = PIN_IMAGE), onLongClick = { println("Marker long click event occurred") }, )}Polyline Click Listener
XML
tomtomMap.addPolylineClickListener { polyline: Polyline -> println("Polyline click event occurred for: $polyline")}Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Polyline( data = PolylineData( geoPoints = listOf(GEOPOINT, GEOPOINT_2), ), onClick = { println("Polyline click event occurred") }, )}Traffic Incident Click Listener
XML
tomtomMap.addTrafficIncidentClickListener { trafficIncidents: List<TrafficIncident>, geoPoint: GeoPoint -> println("Clicked traffic incidents at $geoPoint: $trafficIncidents")}Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { Traffic( onTrafficIncidentClick = { trafficIncidents: List<TrafficIncident>, geoPoint: GeoPoint -> println("Clicked traffic incidents at $geoPoint: $trafficIncidents") }, )}Camera Operations
Animate Camera
XML
tomtomMap.animateCamera( options = cameraOptions,)Compose
// TomTomMap's statemapViewState.cameraState.animateCamera( cameraOptions = cameraOptions,)Move Camera
XML
tomtomMap.moveCamera( options = cameraOptions,)Compose
// TomTomMap's statemapViewState.cameraState.moveCamera( cameraOptions = cameraOptions,)Zoom To Markers
XML
tomtomMap.zoomToMarkers( markers = markers, padding = padding,)Compose
// TomTomMap's statemapViewState.cameraState.zoomToMarkers( markersIds = markersIds, padding = padding,)Zoom To Routes
XML
tomtomMap.zoomToRoutes( padding = padding,)Compose
// TomTomMap's statemapViewState.cameraState.zoomToAllRoutes( padding = padding,)Other Utilities
Change Gesture Exclusion
XML
tomtomMap.changeGestureExclusions( gesture = GestureType.Move, exclusions = setOf(GestureType.Scale),)Compose
// TomTomMap's statemapViewState.gestureState.config = GesturesConfig { exclusions = mapOf( GestureType.Move to setOf(GestureType.Scale), )}Coordinate For Point
XML
tomtomMap.coordinateForPoint( point = POINT,)Compose
// TomTomMap's statemapViewState.getGeoPointForOffset( offset = offset,)Point For Coordinate
XML
tomtomMap.pointForCoordinate( coordinate = COORDINATE,)Compose
// TomTomMap's statemapViewState.getScreenOffsetForGeoPoint( geoPoint = geoPoint,)Enable Location Marker
XML
tomtomMap.enableLocationMarker( LocationMarkerOptions( type = LocationMarkerOptions.Type.Chevron, ),)Compose
TomTomMap( infrastructure = viewModel.mapDisplayInfrastructure, state = mapViewState,) { CurrentLocationMarker( properties = CurrentLocationMarkerProperties { type = LocationMarkerOptions.Type.Chevron }, )}Get Caption
XML
tomtomMap.getCaption( object : CopyrightsFetchingCallback { override fun onSuccess(result: String) { println("Caption: $result") }
override fun onFailure(failure: CopyrightsFetchingFailure) { println("Failure: $failure") } },)Compose
// TomTomMap's statemapViewState.copyrightsState.getCaption()Get Copyrights
XML
tomtomMap.getCopyrights( object : CopyrightsFetchingCallback { override fun onSuccess(result: String) { println("Copyrights: $result") }
override fun onFailure(failure: CopyrightsFetchingFailure) { println("Failure: $failure") } },)Compose
// TomTomMap's statemapViewState.copyrightsState.getCopyrights()Get Visible Region
XML
tomtomMap.getVisibleRegion()Compose
// TomTomMap's statemapViewState.getVisualRegion()Set Frame Rate
XML
tomtomMap.setFrameRate( frameRate = frameRate,)Compose
// TomTomMap's statemapViewState.frameRate = frameRateSet Language
XML
tomtomMap.setLanguage( language = locale,)Compose
// TomTomMap's statemapViewState.locale = localeSet Padding
XML
tomtomMap.setPadding( padding = padding,)Compose
// TomTomMap's statemapViewState.safeArea = paddingValuesUpdate Vehicle
XML
tomtomMap.updateVehicle( vehicle = Vehicle.Car(),)Compose
// TomTomMap's infrastructuremapDisplayInfrastructure = mapDisplayInfrastructure.copy { vehicle = Vehicle.Car()}