This is the documentation of version 1.0.0-rc.4. Go to the latest version, 1.0.0-rc.5.

Route styling

The Routing module draws routes in its own look. color, widthPreset and opacity style the whole route, waypoints.sizePreset and waypoints.label the waypoints, summaryBubbles the bubbles, and layers each layer. You can try them all on the route style playground. Styling knobs reach route layers only through the accent, which a route without a color defaults to, the label and halo colours its summary bubbles take, and the delay colours of its traffic sections.

Colour, width and waypoint size

import { RoutingModule } from '@tomtom-org/maps-sdk/map';

const routingModule = await RoutingModule.create(map, {
    color: '#DF1B12',        // the route line, its outline (a darker shade) and the waypoint pins
    widthPreset: 'l',        // 's' | 'm' | 'l'
    widthFactor: 1.2,        // multiplies the preset, 0.5 to 2
    opacity: 0.7,            // the route lines and their outlines, 0 to 1
    waypoints: {
        sizePreset: 's',     // 's' | 'm' | 'l'
        sizeFactor: 1.5,     // multiplies the preset, 0.5 to 2
    },
});

Without a color, routes take the map's accent when a theme sets one, or the SDK's route blue otherwise:

const brandedRoutes = await RoutingModule.create(map, { color: '#DF1B12' }); // stays red through any theme
const themedRoutes = await RoutingModule.create(map); // follows map.mapColors.accent

Summary bubbles

Each route carries a bubble with its duration, distance and traffic delay. summaryBubbles decides what it says, which routes carry one, where it sits, how it looks and at which zooms it appears. You can try each setting on the summary bubbles playground:

const routingModule = await RoutingModule.create(map, {
    summaryBubbles: {
        fields: ['duration', 'trafficDelay'], // drops the distance
        minZoom: 8,                           // hidden while the whole country is in view
        color: '#1A2024',                     // the bubble, deselected routes a shade darker
        label: { size: 14, typeface: 'serif' },
    },
});

Which routes, and where

Alternatives often share most of their way, so each bubble sits on its route's longest distinct section, a stretch of road the route has to itself, where the other bubbles can't hide it. routes picks which routes carry one, to keep them out of the way of a panel or popup of your own:

routingModule.updateConfig({
    summaryBubbles: {
        routes: 'alternatives',  // the selected route's trip is in your own panel
        fields: ['duration', 'durationDifference'],
    },
});

Your own text

To write your own text, set label.title. A function receives each route's summary and returns its text, again whenever another route is selected, so it can read routeState, and a route it returns an empty string for gets no bubble:

routingModule.updateConfig({
    summaryBubbles: {
        label: {
            title: (summary) => (summary.properties.routeIndex === 0 ? `Fastest, ${summary.properties.formattedDuration}` : ''),
        },
    },
});

Layer overrides

layers is keyed by part (mainLines, waypoints, sections, …) and then by layer. Each entry is a partial MapLibre layer, and its paint and layout merge property by property onto the layer the rest of the config built. Section layers are in Route sections.

const routingModule = await RoutingModule.create(map, {
    widthPreset: 's',
    layers: {
        mainLines: {
            routeLine: { paint: { 'line-blur': 1 } } // keeps the 's' width, the colour and the opacity
        }
    }
});

Every setting as data

routingKnobCatalogue lists every plain-valued display setting of the module with its kind, its range or options, and its default where one value holds everywhere. Each id is the setting's path in the config, so a UI can build its controls from it without a loaded map:

import { routingKnobCatalogue } from '@tomtom-org/maps-sdk/map';

const tunnelKnobs = routingKnobCatalogue.filter(({ id }) => id.startsWith('sections.tunnel.'));
// [{ id: 'sections.tunnel.visible', kind: 'toggle', description: '…', default: true }, …,
//  { id: 'sections.tunnel.style', kind: 'enum', description: '…', options: ['halo', 'inline'], default: 'inline' }, …]

The route-wide knobs come first, then each section type's knobs, where <type> stands for any of drawnSectionTypes:

Id Kind
visible toggle
color color
widthPreset, waypoints.sizePreset enum: s, m or l
widthFactor, waypoints.sizeFactor factor, 0.5 to 2
opacity number, 0 to 1
highlight.outline.widthFactor factor, 1 to 1.25
highlight.section.outline.color color
highlight.section.outline.widthFactor factor, 0.5 to 2
waypoints.icon.style.fillColor, waypoints.icon.style.outlineColor color
waypoints.icon.style.outlineOpacity number, 0 to 1
waypoints.icon.start.style.fillColor, waypoints.icon.start.style.outlineColor, waypoints.icon.middle.style.fillColor, waypoints.icon.middle.style.outlineColor, waypoints.icon.finish.style.fillColor, waypoints.icon.finish.style.outlineColor color
waypoints.icon.start.style.outlineOpacity, waypoints.icon.middle.style.outlineOpacity, waypoints.icon.finish.style.outlineOpacity number, 0 to 1
waypoints.stopNumbering enum: numbers, letters or none
waypoints.highlight.sizeFactor factor, 1 to 1.5
waypoints.label.visible toggle
waypoints.label.color, waypoints.label.haloColor color
waypoints.label.size number, 6 to 48 pixels
waypoints.label.haloWidth number, 0 to 10 pixels
waypoints.label.opacity number, 0 to 1
waypoints.label.font enums: mapFonts
waypoints.label.typeface enum: mapTypefaces, following the map's typeface by default
waypoints.entryPoints enum: main-when-available or ignore
displayUnits.distance.type enum: metric, imperial_us or imperial_uk
displayUnits.distance.kilometers, displayUnits.distance.meters, displayUnits.distance.miles, displayUnits.distance.feet, displayUnits.distance.yards text
displayUnits.time.hours, displayUnits.time.minutes text
summaryBubbles.visible toggle
summaryBubbles.routes enum: all, selected and alternatives
summaryBubbles.fields enums: duration, distance, durationDifference and trafficDelay
summaryBubbles.minZoom, summaryBubbles.maxZoom number, 0 to 22
summaryBubbles.color, summaryBubbles.label.color color
summaryBubbles.label.size number, 6 to 48 pixels
summaryBubbles.label.opacity number, 0 to 1
summaryBubbles.label.typeface enum: mapTypefaces, the map's typeface unset
countryCrossings.visible toggle
countryCrossings.minZoom number, 0 to 22
countryCrossings.color, countryCrossings.label.color color
sections.<type>.visible toggle
sections.<type>.color color
sections.<type>.opacity number, 0 to 1
sections.<type>.widthPreset enum: s, m or l
sections.<type>.widthFactor factor, 0.5 to 2
sections.<type>.style, sections.<type>.pattern enum
sections.<type>.icon.image image
sections.<type>.icon.placement enum
sections.<type>.icon.sizeFactor factor, 0.25 to 2
sections.speedLimit.sign.placement, sections.speedLimit.sign.priority, sections.speedLimit.sign.unit enum
sections.speedLimit.sign.minZoom number, 0 to 22
sections.curve.kerb.visible toggle
sections.curve.kerb.color color

Layer positioning

By default, the route lines sit below the map's labels and the route icons above them. beforeLayerConfig moves them. It takes one target for the whole route ('top' or a key of mapStyleLayerIDs), or a record keyed by part, plus all for the parts it leaves out:

// Route lines under the road network; instruction lines and icons stay where they are
routingModule.updateConfig({ beforeLayerConfig: { mainLines: 'lowestRoadLine' } });

Related guides and examples

Related guides

Related examples