Add periodic traffic refresh (every 5 min) with cache-busting
This commit is contained in:
@@ -64,6 +64,8 @@ Module.register("MMM-CombinedMap", {
|
||||
this.currentRadarIndex = 0;
|
||||
this.animationTimer = null;
|
||||
this.availableTimestamps = [];
|
||||
this.trafficFlowLayer = null;
|
||||
this.trafficIncidentsLayer = null;
|
||||
},
|
||||
|
||||
getDom: function() {
|
||||
@@ -153,25 +155,45 @@ Module.register("MMM-CombinedMap", {
|
||||
},
|
||||
|
||||
addTrafficLayer: function() {
|
||||
// TomTom Traffic Flow tiles
|
||||
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);
|
||||
this.refreshTrafficLayers();
|
||||
|
||||
// Also add traffic incidents overlay
|
||||
const incidentsLayer = L.tileLayer(
|
||||
`https://api.tomtom.com/traffic/map/4/tile/incidents/s3/{z}/{x}/{y}.png?key=${this.config.tomtomApiKey}&tileSize=256`,
|
||||
// Set up periodic traffic refresh (every 5 minutes)
|
||||
setInterval(() => this.refreshTrafficLayers(), 5 * 60 * 1000);
|
||||
},
|
||||
|
||||
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,
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user