Route styling
The Routing module draws routes in its own look, with color and widthPreset for the whole route,
waypoints.sizePreset and waypoints.label for the waypoints, or layers per layer, all live on the route style
playground. Styling knobs reach route layers only through the
accent, which a route without a color
defaults to, 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 waypoints: { sizePreset: 's', // 's' | 'm' | 'l' sizeFactor: 1.5, // multiplies the preset, 0.5 to 2 },});- A factor multiplies its preset instead of replacing it, and is clamped to its
rangeinroutingKnobCatalogue, whichknobEntryOf(routingKnobCatalogue, 'widthFactor')reads. - The instruction arrows keep one size whatever the
widthPreset, and follow onlywidthFactor. - The stop marks scale with their pins, by preset and factor, and stay centred in the pin head at every zoom.
- The waypoint labels follow the map’s light or dark theme, like the labels of places and geometries, with
dark text on a white halo on a light map and the reverse on a dark one.
waypoints.labelsets their colour, halo and size, aslabeldoes for places. Waypoints covers pins per role, your own labels and icons per waypoint.
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 themeconst themedRoutes = await RoutingModule.create(map); // follows map.mapColors.accentLayer overrides
layers is keyed by part (mainLines, waypoints, sections, …) and then by layer. Each entry’s partial
paint and layout merge onto the SDK’s own. Section layers are in
Route sections.
const routingModule = await RoutingModule.create(map, { layers: { mainLines: { routeLine: { paint: { 'line-color': '#FF0000', 'line-width': 6 } } } }});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 |
highlight.outline.widthFactor | factor, 1 to 1.25 |
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.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 |
countryCrossings.visible | toggle |
countryCrossings.minZoom | number, 0 to 22 |
countryCrossings.color, countryCrossings.label.color | color |
countryCrossings.alignment | enum: viewport or route |
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 |
- A section type lists only the knobs it supports.
speedLimittakes onlyvisibleandsign.traffic, which colours its line by delay, has nocolor,patternoriconentry. routingKnobIdslists the ids in catalogue order.RoutingKnobIdis their union, andRoutingKnobValueOf<ID>is the plain value one takes.- The unit labels after distances and durations are
textentries with no default. AdisplayUnitsknob left unset takes its value from the global configuration. - Not in it:
layers,beforeLayerConfig, and the waypoint images,mappingandtitle, which take structured, MapLibre or function values, andevents. - Its entries share their shape,
KnobEntry, with every module’s catalogue.
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:
mainLines- The route lines, and every section line drawn with them.instructionLines- The guidance lines and their arrows, above the route lines by default.icons- Waypoints, summary bubbles, border crossings and section icons. The tunnel sign and icons requested by generated section types sit lowest. A target puts them all beneath it in that order.
// Route lines under the road network; instruction lines and icons stay where they areroutingModule.updateConfig({ beforeLayerConfig: { mainLines: 'lowestRoadLine' } });- Each part keeps its own layers in order wherever it goes.
applyConfigandupdateConfigrestack them at runtime. - A target the style lacks (the satellite style has no
lowestRoadLine) puts the part on top. getLayerToRenderLinesUnder()followsmainLines, and returnsundefinedwhen the lines are on top.- The speed limit signs are not a part. Their
sign.prioritydecides which symbols they give way to, wherever the parts are.
Related guides and examples
Related guides
- Routing module - Showing routes and waypoints, events and shown data
- Route sections - The overlays drawn per stretch of road, on the same set of knobs
- Map modules - The knob kinds every catalogue shares
Related examples
- Route style playground - The route’s colour, width, waypoint size, waypoint label colour and clicked outline on knobs, and a toggle that hides it
- Route waypoints playground - Per-role pins, stop numbering, labels, hover growth, a category pin per stop and a finish image of your own
- Map theme - A route following the accent of a theme