Add periodic traffic refresh (every 5 min) with cache-busting

This commit is contained in:
Clawd
2026-02-11 20:45:28 +00:00
parent be5b469d7f
commit bb20e03bba

View File

@@ -64,6 +64,8 @@ Module.register("MMM-CombinedMap", {
this.currentRadarIndex = 0; this.currentRadarIndex = 0;
this.animationTimer = null; this.animationTimer = null;
this.availableTimestamps = []; this.availableTimestamps = [];
this.trafficFlowLayer = null;
this.trafficIncidentsLayer = null;
}, },
getDom: function() { getDom: function() {
@@ -153,25 +155,45 @@ Module.register("MMM-CombinedMap", {
}, },
addTrafficLayer: function() { addTrafficLayer: function() {
// TomTom Traffic Flow tiles this.refreshTrafficLayers();
const trafficLayer = L.tileLayer(
`https://api.tomtom.com/traffic/map/4/tile/flow/relative0/{z}/{x}/{y}.png?key=${this.config.tomtomApiKey}&tileSize=256`,
{
maxZoom: 18,
opacity: this.config.trafficOpacity
}
);
trafficLayer.addTo(this.map);
// Also add traffic incidents overlay // Set up periodic traffic refresh (every 5 minutes)
const incidentsLayer = L.tileLayer( setInterval(() => this.refreshTrafficLayers(), 5 * 60 * 1000);
`https://api.tomtom.com/traffic/map/4/tile/incidents/s3/{z}/{x}/{y}.png?key=${this.config.tomtomApiKey}&tileSize=256`, },
refreshTrafficLayers: function() {
// Remove existing traffic layers
if (this.trafficFlowLayer) {
this.map.removeLayer(this.trafficFlowLayer);
}
if (this.trafficIncidentsLayer) {
this.map.removeLayer(this.trafficIncidentsLayer);
}
// Cache-buster timestamp (rounded to minute for some caching benefit)
const cacheBust = Math.floor(Date.now() / 60000);
// TomTom Traffic Flow tiles
this.trafficFlowLayer = L.tileLayer(
`https://api.tomtom.com/traffic/map/4/tile/flow/relative0/{z}/{x}/{y}.png?key=${this.config.tomtomApiKey}&tileSize=256&t=${cacheBust}`,
{ {
maxZoom: 18, maxZoom: 18,
opacity: this.config.trafficOpacity opacity: this.config.trafficOpacity
} }
); );
incidentsLayer.addTo(this.map); this.trafficFlowLayer.addTo(this.map);
// Traffic incidents overlay
this.trafficIncidentsLayer = L.tileLayer(
`https://api.tomtom.com/traffic/map/4/tile/incidents/s3/{z}/{x}/{y}.png?key=${this.config.tomtomApiKey}&tileSize=256&t=${cacheBust}`,
{
maxZoom: 18,
opacity: this.config.trafficOpacity
}
);
this.trafficIncidentsLayer.addTo(this.map);
Log.info("MMM-CombinedMap: Traffic layers refreshed");
}, },
fetchRadarCapabilities: function() { fetchRadarCapabilities: function() {