How the SDK works
The SDK is one npm package, @tomtom-org/maps-sdk, with three entry points. Map draws the map, Services calls TomTom’s location APIs, and Core holds what both share. Use each alone or together.
The playground below uses only the Map bundle, with a TomTomMap configured once through Core.
The three bundles
| Bundle | Import path | Runs in | Holds | Start with |
|---|---|---|---|---|
| Map | @tomtom-org/maps-sdk/map | Browser | TomTomMap and its modules | Map introduction |
| Services | @tomtom-org/maps-sdk/services | Browser, Node.js, React Native | One async function per TomTom API | Services quickstart |
| Core | @tomtom-org/maps-sdk/core | Anywhere | TomTomConfig, shared types, utilities | Core quickstart |
- Map and Services never depend on each other. Both depend on Core, so Services runs on a server with no map, and Map draws your own data with no service.
- They meet through Core’s GeoJSON types. A map module shows what a service returns unchanged, with no adapter in between.
- Everything is tree-shakable. Your bundle carries only the modules and services you import.
Data flow
import { TomTomConfig } from '@tomtom-org/maps-sdk/core';import { discoverPlaces } from '@tomtom-org/maps-sdk/services';import { PlacesModule, TomTomMap } from '@tomtom-org/maps-sdk/map';
TomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY', language: 'en-GB' });
const map = new TomTomMap({ mapLibre: { container: 'map', center: [4.9, 52.37], zoom: 13 } });
const places = await PlacesModule.create(map);await places.show(await discoverPlaces({ query: 'coffee', geoBias: { position: [4.9, 52.37] } }));TomTomConfigholds the API key and language once, for the map and every service call.discoverPlacesmerges its own parameters over that configuration, calls the API and resolves to a GeoJSONFeatureCollectionofPlacefeatures.PlacesModule.showtakes that collection as it is and draws it on its own sources and layers.
Map
TomTomMapwraps a MapLibreMap. It loads a TomTom style, applies the global configuration and exposes the MapLibre instance asmap.mapLibreMap(when to use the SDK or MapLibre).- Modules add everything else, each covering one area of the map. There are two kinds:
- Style-owned modules, from
get(map), cover what the style already draws, such as the base map, POIs, traffic and terrain. A map has one of each. - Data-owned modules, from
create(map), show your data, such as places, routes, geometries and your own GeoJSON. Create as many as you need.
- Style-owned modules, from
- Modules survive style switches.
await map.setStyle(…)restores every module’s data and settings on the new style (Map styles). - Every setting is data. Each module’s configuration has stable knob ids, set the same way on every module (Every setting as data). Map styling restyles the map at runtime.
- Events are typed per module. A click on a place pin gives you the
Placeyou showed (User events).
Services
- Each API has one async function. Places covers search and geocoding. Routing covers route calculation and reachable ranges, and Traffic covers incident details and area analytics.
- The global configuration is the baseline. A call’s own parameters win for that call only (Global configuration).
- Results are typed GeoJSON for places, routes, reachable ranges, geometries and traffic. The POI category and search-suggestion services return plain objects.
- Every call takes the same request options: validation, an
AbortSignaland typed errors (Request options and errors).
Core
- Global configuration:
TomTomConfig.instance.put({ apiKey, language, … }), called once and read by the map and every service. - Shared types:
Place,Routeand the traffic types, the shape both bundles agree on. - Utilities that need no map: bounding boxes, coordinates, formatting and route progress.
Next steps
- Map only, with your own data: see the Map quickstart.
- Services only, in Node.js, a browser or React Native: see the Services quickstart.
- Both: see the examples gallery, where most apps combine them.