Read the statement by Michael Teeuw here.
Dynamic travel time
-
@darrene It’s available in the develop branch now. Happy coding!
-
Woo! Excellent stuff. Thank you @MichMich - I’ll give it a test-drive over the weekend and feed anything constructive back
-
So having realised the simplest approach to a week/weekend commute display would simply be to code the date information into MM-Traffic’s MMM-Traffic.js file, I’ve added the following logic to the getParams function;
getParams: function() { var params = '?';
-> var d = new Date();
-> var n = d.getDay();params += 'mode=' + this.config.mode; params += '&origin=' + this.config.origin;
-> if (n < 6) {params += ‘&destination=’ + “Cheltenham”;}
-> else {params += ‘&destination=’ + “Gloucester”;}params += '&key=' + this.config.api_key; params += '&traffic_model=' + this.config.traffic_model; params += '&language=' + this.config.language; return params; },
Which works like a dream :) My first bit of javascript. I’m so excited!
I’d like to round it off by adjusting the
‘current commute is’
and
'origin to destination displays to be along the lines of ‘Work Commute’/‘Town Commute’ and ‘Home to Work’/‘Home to town’ but I’m struggling to find how to inject the logic.I can see the current commute is in the defaults and symbols section. Ideally I want to change the defaults section.
The other is in the //routename section, but again I can’t work out how to make the alteration.
-
Solved! I don’t think my code-hacking is going to win any awards for elegance but it works - I get a different message and journey time depending on whether it’s the week or the weekend! :)
-
@darrene said in Dynamic travel time:
Solved! I don’t think my code-hacking is going to win any awards for elegance but it works - I get a different message and journey time depending on whether it’s the week or the weekend! :)
Hi darrene,
So you just changed the MMM-Traffic.js? Could you upload it for us?
I like to display the Journey time “home to work” in the morning (for me) and the time “work to home” in the evening (for my family).