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

About MapLibre

The TomTom Maps SDK for JavaScript renders through MapLibre GL JS, the open-source map renderer, and exposes it as is. This guide covers what that gives you, what the SDK adds on top, and when to use MapLibre directly.

MapLibre underneath, fully exposed

MapLibre is a peer dependency: you install it next to the SDK. TomTomMap does not hide it. map.mapLibreMap is the MapLibre Map itself, and the mapLibre constructor option takes MapLibre's map options unchanged:

import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { TomTomMap } from '@tomtom-org/maps-sdk/map';
import { NavigationControl } from 'maplibre-gl';

TomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY' });

const map = new TomTomMap({ mapLibre: { container: 'map', pitch: 45 /* any MapLibre option */ } });

map.mapLibreMap.addControl(new NavigationControl(), 'top-right');
map.mapLibreMap.on('moveend', () => console.log('Viewport:', map.mapLibreMap.getBounds()));

What the SDK adds over raw MapLibre

Anything MapLibre can draw, the SDK's own features draw with less code and fewer ways to break:

When to use TomTom SDK vs direct MapLibre

Use the SDK feature wherever one covers what you need:

To… Use
Switch or load a style setStyle
Restyle the TomTom map: sizes, colours, features StylingModule knobs and setMapColors; styling.layers for a style layer no knob reaches
Show or hide base map, POI, traffic and terrain parts BaseMapModule, POIsModule, TrafficFlowModule, TrafficIncidentsModule, TerrainModule
Draw a POI category with an icon of your own POIsModule's icon.categoryIcons, the same list a PlacesModule takes
Show places, routes, geometries and reachable ranges PlacesModule, RoutingModule, GeometriesModule, ReachableRangesModule, each styled through its own config — its layers entries for any MapLibre property the rest doesn't cover (which modules take one)
Draw your own GeoJSON data, styled any way CustomGeoJSONModule
React to clicks and hovers, including on the empty map Module events, and BaseMapModule for the rest of the map

Your own data belongs in CustomGeoJSONModule too, even a single layer. It takes the same layer specs as MapLibre's addLayer, so you keep MapLibre's full styling and gain the restoration and events above.

Use map.mapLibreMap for what none of these covers:

Sources, layers and images you add through map.mapLibreMap are yours to restore after setStyle, and sit outside the SDK's event coordination.

Combining both

SDK modules and the MapLibre API share one map:

import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { PlacesModule, TomTomMap } from '@tomtom-org/maps-sdk/map';
import { discoverPlaces } from '@tomtom-org/maps-sdk/services';
import { Marker, Popup } from 'maplibre-gl';

TomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY' });
const map = new TomTomMap({ mapLibre: { container: 'map' } });

// SDK: places that survive style switches, with coordinated events
const restaurants = await discoverPlaces({ query: 'restaurants' });
const placesModule = await PlacesModule.create(map);
await placesModule.show(restaurants);
placesModule.events.on('click', (feature) => console.log('Place clicked:', feature.properties.title));

// MapLibre: a marker with a popup
new Marker({ color: '#ff0000' })
    .setLngLat([4.9, 52.3])
    .setPopup(new Popup().setText('Custom Location'))
    .addTo(map.mapLibreMap);

MapLibre CSS

The SDK applies the MapLibre CSS itself unless your page already has it, so you do not need to import anything.

The stylesheet ships with the SDK:

The bundled copy matches the MapLibre version the SDK was built with. To use the CSS of the MapLibre version you installed instead, import it in your JavaScript/TypeScript files:

import 'maplibre-gl/dist/maplibre-gl.css';

Prefer this import, which your bundler serves alongside your app, to a <link> to a public CDN such as unpkg.com: a CDN link sends every end user's IP address to that third party.

Related resources