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

Module lifecycle events

Module lifecycle events fire when a module changes, whatever caused it — not when a user interacts with the map, which user interaction events cover.

Both live on the module's own events, next to its user events, and never on a named scope: a module has one configuration and one stream of shown data.

config-change

The handler receives the module's whole configuration after the change, as getConfig() returns it, which can be undefined after resetConfig(). Use it to keep your UI in sync whichever code made the change:

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

const terrain = await TerrainModule.get(map);
const toggle = document.querySelector('#hillshade-toggle');

terrain.events.on('config-change', (config) => {
    toggle.checked = config?.hillshade?.visible ?? false;
});

toggle.addEventListener('change', () => terrain.setHillshadeVisible(toggle.checked));

What triggers config-change

Call Modules
applyConfig, updateConfig, resetConfig All
setKnob, resetKnob Every module with a knob catalogue
setVisible Every module with visible; BaseMapModule's with { layerGroups } too
setHillshadeVisible, setElevationVisible TerrainModule
setPalette, setColorStops, setHeight, setFilters TrafficAreaAnalyticsModule
get(map, config) on a module the map already has Style-owned modules
setStyle(style, { resetState: true }), which resets every module All

The configuration a module is created with fires nothing. To save what the handler receives and replay it later, see Saving and replaying a configuration.

shown-features

The handler receives the data a show method drew. A module with several show methods reports them all on one stream, and the payload says which ran:

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

const places = await PlacesModule.create(map);

places.events.on('shown-features', (features) => {
    if ('places' in features) {
        updateResultsPanel(features.places);
    } else {
        updateConnectionsPanel(features.connections);
    }
});
Module Triggered by Payload
PlacesModule show / showConnections { places } / { connections }
RoutingModule showRoutes / showWaypoints { routes } / { waypoints }
GeometriesModule, ReachableRangesModule show the PolygonFeatures given
CustomGeoJSONModule show(data, sourceName) { sourceName, data }, once per source when show names none
TrafficIncidentDetailsModule show the TrafficIncidentDetails given
TrafficAreaAnalyticsModule show the TrafficAreaAnalytics given

Cleanup

events.on returns a function that removes that handler alone; events.off(type) removes every handler of a type, user events included:

const unsubscribe = places.events.on('config-change', saveSettings);
unsubscribe(); // other config-change handlers keep firing

places.events.off('shown-features');
places.events.off('click');

Related guides