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

Map colours and the accent

To show the map in your brand colours, make one call to the Styling Foundations module with the map's ten semantic colours. An eleventh colour, the accent, carries the theme to the routes, areas and pins drawn on top.

The ten colours below are the whole theme. Edit any of them and the map redraws in it. If you set them right after StylingFoundationsModule.get resolves, they appear on the first frame the map draws, with no fade from the default palette.

Map colours: setMapColors()

Partial objects are fine. An unknown name throws an Error, and a value that is not a colour throws a RangeError:

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

const styling = await StylingFoundationsModule.get(map);
styling.setMapColors({ land: '#f3f5f7', water: '#accbe2', roadMajor: '#a1b8ce', label: '#364659' });

mapColorNames lists all eleven, with accent last. baseMapColorNames (typed BaseMapColorName) lists only the ten, in the same order, for building a base-map colour picker. MapColors is the object type setMapColors takes. The table shows what each colour reaches:

Name Reaches
land Map background and other bare-land features, influences admin borders/labels. Also used to derive all map colours if undefined.
water Waterbodies, waterways and other water features. Also influences glaciers, water labels and ferry lines.
vegetation Forests and other land cover such as grass and shrubland. Also influences earth cover vegetation at smaller scales.
park City parks and sport/recreation grounds. Also influences National Parks and other protected areas at smaller scales.
artificial Built-up-areas and man-made features such as landuse grounds and buildings. Also influences railways.
roadMajor Most important road classes, from motorways & trunks to primary roads. Also influences outline and tunnel colours.
road Less important road classes, from secondary/tertiary to streets and service roads. Also influences tunnel colours.
roadOutline Road outlines for secondary/tertiary roads and minor classes. Also influences road labels and all other outline colours.
label Labels for capitals and other populated places/admin areas. Also influences border styling and all other label colours.
labelHalo Halos of populated places and admin area labels. Also influences border outlines and all other label halos.

How one name fans out:

await map.setStyle('monoLight');
styling.setMapColors({ land: 'hsl(38, 36%, 93%)' }); // a sepia map: water, roads and land cover follow

Pick each colour in the demo below to watch it fan out:

The ten colours are also the colors.* knobs:

import { getKnob, resetKnob, stylingFoundationsKnobCatalogue } from '@tomtom-org/maps-sdk/map';

getKnob(styling, stylingFoundationsKnobCatalogue, 'colors.water');   // the style's own, or derived from your land, until set
resetKnob(styling, stylingFoundationsKnobCatalogue, 'colors.roadMajor'); // one colour back to the style

The catalogue carries each summary from the table above as the knob's description. getConfig() returns the colours with the rest of the settings.

A palette is a recolour, not an inversion. Every literal is re-derived by its offset from the style's own colour. A palette near the loaded style's lightness lands cleanly. One that inverts it, such as dark land over streetLight, pushes the derived shades to the ends of their range and washes out the road hierarchy. Pair a dark palette with streetDark and recolour from there:

await map.setStyle('streetDark');
styling.setMapColors({ land: '#161b27', water: '#2c486d', roadMajor: '#b68e54', label: '#dce0e5' });

The goal is a coherent recolour, faithful for reasonable palettes and approximate for extreme ones. The colours a mono style derives from land match the theme exactly. The shades within each colour are re-derived from the loaded style, not pixel-matched to a compiled theme.

The demo below gives each standard style four themes, each one close to that style's lightness. On the mono styles a theme sets only land. On satellite it sets only the roads and labels, because the imagery covers the land:

From a few colours, a stylesheet or an image

If your look starts as a brand's swatches, a website's CSS, a photo or a mood instead of ten named colours, the Map Theme plugin assigns the roles for you:

import {
    deriveMapColors,
    deriveMapColorsFromCss,
    deriveMapColorsFromImage,
} from '@tomtom-org/maps-sdk-plugin-map-theme';

styling.setMapColors(deriveMapColors(['#1d3f8a', '#e63312', '#f5d000', '#111111', '#f4f1ea']));
styling.setMapColors(deriveMapColorsFromCss(await cssFile.text()));
styling.setMapColors(await deriveMapColorsFromImage(fileInput.files[0]));

The accent: what a theme reaches beyond the base map

colors.accent is the colour for what is drawn on top of the map. It is a knob like the other colours, so getKnob, setKnob, resetKnob and getConfig() carry it, but it paints no style layer.

The map publishes it in map.mapColors, with the ten map colours in force. map.mapColors is empty until a Styling Foundations module exists. The modules that draw their own layers read the accent as their default, so one theme recolours the base map and the routes, areas and pins drawn on it:

import { RoutingModule, StylingFoundationsModule } from '@tomtom-org/maps-sdk/map';
import { deriveMapColors } from '@tomtom-org/maps-sdk-plugin-map-theme';

const styling = await StylingFoundationsModule.get(map);
const routes = await RoutingModule.create(map); // no colour chosen
styling.setMapColors(deriveMapColors(['#1d3f8a', '#e63312', '#f5d000', '#111111', '#f4f1ea']));
// the base map is Miró, and so is the route drawn across it
map.mapColors.accent; // the colour the route took
Module What takes the accent Your own colour instead
RoutingModule the route line, its outline and the waypoint icons color, or a layers paint override for one layer
GeometriesModule the fill and the outline color, fill.color or fill.palette for both, line.color for the outline, a feature's color property
PlacesModule the pin, the selected label, connection lines and entry points color for all four; over it, icon.default.style.fillColor for the pin, label.color or layers.selected for the label, connections.layers and entryPoints.layers for the rest
ReachableRangesModule its bands, as a ramp from the accent (innermost) toward the map's land colour (outermost), reversed for fill.style: 'inverted' fill.palette

To theme only the base map, leave the accent out or reset it. The modules go back to their own defaults:

import { resetKnob, stylingFoundationsKnobCatalogue } from '@tomtom-org/maps-sdk/map';
import { deriveMapColors } from '@tomtom-org/maps-sdk-plugin-map-theme';

const { accent, ...baseMapColors } = deriveMapColors(['#1d3f8a', '#e63312', '#f5d000', '#111111', '#f4f1ea']);
styling.setMapColors(baseMapColors);

// or, with an accent already set:
resetKnob(styling, stylingFoundationsKnobCatalogue, 'colors.accent');

Only those four modules read it:

To match the theme in your own layers, read map.mapColors.accent whenever the settings change:

styling.events.on('config-change', () =>
    map.mapLibreMap.setPaintProperty('my-trail', 'line-color', map.mapColors.accent ?? '#0a3653'),
);

The demo below themes the base map, an area, pins and a route in one call:

Related guides and examples

Related guides

Related examples