Event interface for the hexgrid and square layers.
Supports feature-interaction events (hover, click, contextmenu, long-hover) as well
as module lifecycle events (config-change, shown-features) — all through the same
events.on(type, handler) surface.
module.events.on('hover', (feature, lngLat) => {
console.log(feature.properties.congestionLevel);
});
const unsub = module.events.on('config-change', (config) => {
console.log('Config updated:', config);
});
module.events.on('shown-features', (data) => {
console.log('Analytics data shown:', data);
});
Gets the source and layer identifiers for all sources managed by this module.
This property provides access to the MapLibre source and layer IDs that were created and are managed by this module. These IDs can be used to interact directly with MapLibre's API or to identify which layers belong to this module.
A record mapping each source name to its corresponding source ID and layer IDs. Each entry contains the MapLibre source identifier and an array of layer identifiers associated with that source.
The returned IDs are useful when you need to:
const ids = myModule.sourceAndLayerIDs;
console.log(ids);
// {
// mySource: {
// sourceID: 'my-source-id',
// layerIDs: ['layer-1', 'layer-2']
// }
// }
// Use with MapLibre API
const map = myModule.mapLibreMap;
ids.mySource.layerIDs.forEach(layerId => {
map.setLayoutProperty(layerId, 'visibility', 'visible');
});
Applies a configuration to this module.
This method updates the module's behavior and appearance based on the provided configuration. The configuration is stored internally and will be automatically reapplied if the map style changes.
The configuration object to apply to the module. Pass undefined to reset
the configuration to default values.
When a configuration is applied, the module updates its visual representation and behavior accordingly. The configuration persists across map style changes, ensuring consistent module behavior even when the map's base style is modified.
// Apply a new configuration
myModule.applyConfig({ visible: true, opacity: 0.8 });
// Reset to default configuration
myModule.applyConfig(undefined);
Removes all area analytics data from the map.
Clears any active tile filter for one or more metrics.
Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]Optional list of metrics to clear. When omitted, clears filters for all metrics.
Filters visible tiles by value range for one or more metrics.
Optionalfilter: AreaAnalyticsMetricFilterFilter config. Pass undefined to clear.
Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]Optional list of metrics to target. When omitted, the filter is applied to all metrics.
Retrieves a copy of the current module configuration.
This method returns a shallow copy of the configuration object that is currently
applied to the module. If no configuration has been applied, it returns undefined.
A shallow copy of the current configuration object, or undefined if no
configuration is currently applied. The returned object is a copy to prevent
unintended modifications to the internal state.
The returned configuration object is a shallow copy, which means that while the top-level properties are copied, any nested objects or arrays are still referenced from the original configuration. This is sufficient for most use cases but should be kept in mind when dealing with complex configurations.
// Apply a configuration
myModule.applyConfig({ visible: true, opacity: 0.8 });
// Later, retrieve the current configuration
const currentConfig = myModule.getConfig();
console.log(currentConfig); // { visible: true, opacity: 0.8 }
// When no config is applied
myModule.resetConfig();
console.log(myModule.getConfig()); // undefined
Returns the currently displayed data for all visualisation modes.
Whether any area analytics (data) layer is currently visible.
Repositions analytics layers independently by layer type.
Only the properties present in layerConfig are repositioned; omitted layer types are left in place.
Per-layer-type positioning config. Each value is 'top' or a MapStyleLayerID.
Resets the configuration of this module to its default values.
This is a convenience method that clears any previously applied configuration
and restores the module to its initial state. This is equivalent to calling
applyConfig(undefined).
After calling this method, the module will behave as if no configuration was ever applied. Any custom settings, styling, or behavior modifications will be removed and replaced with default values.
// Apply some configuration
myModule.applyConfig({ visible: true, opacity: 0.5 });
// Later, reset to defaults
myModule.resetConfig();
Sets the color for one or more metrics.
Pass a preset theme name or a custom color-stops configuration.
Pass undefined to clear the color override for the targeted metrics.
A preset theme, an AreaAnalyticsColorStopsConfig, or undefined to clear.
Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]Optional list of metrics to target. When omitted, the color is applied to all metrics.
// Apply a theme to all metrics
module.setColor('heat');
// Apply a theme to specific metrics only
module.setColor('heat', ['speed', 'freeFlowSpeed']);
// Apply custom stops to a single metric
module.setColor(
{ valueType: 'raw', stops: [{ value: 0, color: '#2dc653' }, { value: 100, color: '#e03030' }] },
['congestionLevel'],
);
// Clear color override for all metrics
module.setColor(undefined);
// Clear color override for a specific metric
module.setColor(undefined, ['speed']);
Configures extrusion height behaviour for one or more metrics.
Height configuration.
Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]Optional list of metrics to target. When omitted, the height config is applied to all metrics.
Changes the active metric that drives colour and height.
Updates activeMetric in the config to the given metric key.
One of 'congestionLevel', 'speed', 'travelTime', 'freeFlowSpeed', or 'networkLength'.
Switches the visualisation mode.
One of 'heatmap', 'hexgrid-3d', 'hexgrid-2d', 'square-3d', 'square-2d'.
Shows or hides all area analytics layers.
Displays area analytics data on the map.
Accepts the raw response from trafficAreaAnalytics(). Tile data is
transformed internally to point features (heatmap), hexagonal polygons
(hexgrid modes), and square polygons (square modes).
The region boundary geometry is also displayed.
The raw TrafficAreaAnalytics service response.
ProtectedwaitStaticgetCreates and initialises a new Traffic Area Analytics module.
All configuration properties are optional. When config is omitted (or only
partially supplied), built-in defaults are applied for every missing field.
After get() resolves, TrafficAreaAnalyticsModule.getConfig always returns a
fully-populated configuration — there is no need to reference any default
values yourself.
The TomTomMap instance.
Optionalconfig: TrafficAreaAnalyticsConfigOptional initial configuration. Omit to use all defaults.
A promise that resolves with the initialised module.
// No config needed — defaults are applied automatically.
const module = await TrafficAreaAnalyticsModule.get(map);
await module.show(analytics);
// Or override specific properties while keeping everything else at default:
const module = await TrafficAreaAnalyticsModule.get(map, {
displayMode: 'heatmap',
metricConfig: {
congestionLevel: { color: 'heat' },
},
});
Traffic Area Analytics visualization module.
Renders area-analytics data on the map in one of five modes:
The actual region boundary is always rendered alongside the analytics cells.
Remarks
Quick start: