Skip to content

Commit

Permalink
Route description token (#108)
Browse files Browse the repository at this point in the history
* adding screenshot, updated logic to grab first leg summary as route and updated readme

* remove my custom css from screenshot

* fixing readme
  • Loading branch information
rstokes authored Feb 8, 2025
1 parent d542a8f commit 6490385
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions MMM-Traffic.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Module.register('MMM-Traffic', {
.then(self.checkStatus)
.then(json => {
self.duration = Math.round(json.routes[0].duration / 60);
self.route = json.routes[0].legs[0].summary;
self.errorMessage = self.errorDescription = undefined;
self.loading = false;
self.updateDom();
Expand Down Expand Up @@ -141,7 +142,7 @@ Module.register('MMM-Traffic', {
},

replaceTokens: function (text) {
return text.replace(/{duration}/g, this.duration);
return text.replace(/{duration}/g, this.duration).replace(/{route}/g, this.route);
},

shouldHide: function () {
Expand All @@ -155,4 +156,4 @@ Module.register('MMM-Traffic', {
}
return hide;
},
});
});
20 changes: 19 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ in firstLine/secondLine._
| Token | Value |
| ------------ | --------------------------------------------- |
| `{duration}` | The driving time returned from the mapbox API |
| `{route}` | The summary of the route from the mapbox API |

### Per Day/Time Customization

Expand Down Expand Up @@ -164,9 +165,26 @@ rate limited.
}
},
```

![both lines custom screenshot](screenshots/03-both_lines.png)

### Use both lines with route

```js
{
module: "MMM-Traffic",
position: "top_left",
config: {
accessToken: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "via {route}"
}
},
```
![both lines with route screenshot](screenshots/06-both_lines_route.png)


### Multiple Routes

```js
Expand Down
Binary file added screenshots/06-both_lines_route.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6490385

Please sign in to comment.