Skip to content

Commit 6490385

Browse files
authored
Route description token (#108)
* adding screenshot, updated logic to grab first leg summary as route and updated readme * remove my custom css from screenshot * fixing readme
1 parent d542a8f commit 6490385

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

MMM-Traffic.js

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Module.register('MMM-Traffic', {
6161
.then(self.checkStatus)
6262
.then(json => {
6363
self.duration = Math.round(json.routes[0].duration / 60);
64+
self.route = json.routes[0].legs[0].summary;
6465
self.errorMessage = self.errorDescription = undefined;
6566
self.loading = false;
6667
self.updateDom();
@@ -141,7 +142,7 @@ Module.register('MMM-Traffic', {
141142
},
142143

143144
replaceTokens: function (text) {
144-
return text.replace(/{duration}/g, this.duration);
145+
return text.replace(/{duration}/g, this.duration).replace(/{route}/g, this.route);
145146
},
146147

147148
shouldHide: function () {
@@ -155,4 +156,4 @@ Module.register('MMM-Traffic', {
155156
}
156157
return hide;
157158
},
158-
});
159+
});

README.md

100644100755
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ in firstLine/secondLine._
100100
| Token | Value |
101101
| ------------ | --------------------------------------------- |
102102
| `{duration}` | The driving time returned from the mapbox API |
103+
| `{route}` | The summary of the route from the mapbox API |
103104

104105
### Per Day/Time Customization
105106

@@ -164,9 +165,26 @@ rate limited.
164165
}
165166
},
166167
```
167-
168168
![both lines custom screenshot](screenshots/03-both_lines.png)
169169

170+
### Use both lines with route
171+
172+
```js
173+
{
174+
module: "MMM-Traffic",
175+
position: "top_left",
176+
config: {
177+
accessToken: "your_key_here",
178+
originCoords: "-84.398848,33.755165",
179+
destinationCoords: "-84.504259,33.88210",
180+
firstLine: "{duration} mins",
181+
secondLine: "via {route}"
182+
}
183+
},
184+
```
185+
![both lines with route screenshot](screenshots/06-both_lines_route.png)
186+
187+
170188
### Multiple Routes
171189

172190
```js
7.45 KB
Loading

0 commit comments

Comments
 (0)