From 3ef8024b1d33f0de6227a26967ba78ef85672a94 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sat, 8 Mar 2014 16:14:14 +0000 Subject: [PATCH] Add distance/time summary --- app/assets/javascripts/routing.js.erb | 14 +++++++++++++- .../javascripts/routing_engines/graphhopper.js | 2 +- app/assets/javascripts/routing_engines/mapquest.js | 4 ++-- app/assets/javascripts/routing_engines/osrm.js | 2 +- app/assets/stylesheets/common.css.scss | 4 ++++ config/locales/en.yml | 2 ++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index c774928b9..42373ef9d 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -194,7 +194,10 @@ OSM.Routing=function(map,name,jqSearch) { $('#sidebar_content').empty(); var html=('

' + '' + I18n.t('javascripts.directions.directions') + - '

').replace(/~/g,"'"); + '

' + + I18n.t('javascripts.directions.distance') + ': ' + r.formatDistance(data.distance)+ '. ' + + I18n.t('javascripts.directions.time' ) + ': ' + r.formatTime(data.time) + '.

' + + '
').replace(/~/g,"'"); $('#sidebar_content').html(html); // Add each row var cumulative=0; @@ -224,6 +227,15 @@ OSM.Routing=function(map,name,jqSearch) { r.clickTurn=function(num,latlng) { r.popup=L.popup().setLatLng(latlng).setContent("

"+(num+1)+"

").openOn(r.map); }; + r.formatDistance=function(m) { + if (m < 1000 ) { return Math.round(m) + "m"; } + else if (m < 10000) { return (m/1000.0).toFixed(1) + "km"; } + else { return Math.round(m / 1000) + "km"; } + }; + r.formatTime=function(s) { + var d=new Date(s*1000); var h=d.getHours(); var m=d.getMinutes(); + return h+":"+(m<10 ? '0' : '')+m; + }; // Close all routing UI diff --git a/app/assets/javascripts/routing_engines/graphhopper.js b/app/assets/javascripts/routing_engines/graphhopper.js index 9762c0fe4..5c10433c2 100644 --- a/app/assets/javascripts/routing_engines/graphhopper.js +++ b/app/assets/javascripts/routing_engines/graphhopper.js @@ -44,7 +44,7 @@ GraphHopperEngine.prototype.createConfig = function() { var distInMeter = instr.distances[i]; steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]); } - router.setItinerary({steps: steps}); + router.setItinerary({ steps: steps, distance: data.route.distance, time: data.route['time']/1000 }); return true; }, GH_INSTR_MAP: { diff --git a/app/assets/javascripts/routing_engines/mapquest.js b/app/assets/javascripts/routing_engines/mapquest.js index bd580da3e..3e6e0c3fc 100644 --- a/app/assets/javascripts/routing_engines/mapquest.js +++ b/app/assets/javascripts/routing_engines/mapquest.js @@ -47,7 +47,7 @@ MapQuestEngine.prototype.createConfig = function() { url+="&"+that.vehicleParam; //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de" url+="&manMaps=false"; - url+="&shapeFormat=raw&generalize=0"; + url+="&shapeFormat=raw&generalize=0&unit=k"; this.requestCORS(url); }, gotRoute: function(router,data) { @@ -69,7 +69,7 @@ MapQuestEngine.prototype.createConfig = function() { var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType]; steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]); } - router.setItinerary( { steps: steps }); + router.setItinerary( { steps: steps, distance: data.route.distance*1000, time: data.route['time'] }); return true; } }; diff --git a/app/assets/javascripts/routing_engines/osrm.js b/app/assets/javascripts/routing_engines/osrm.js index fde871019..041f456f0 100644 --- a/app/assets/javascripts/routing_engines/osrm.js +++ b/app/assets/javascripts/routing_engines/osrm.js @@ -46,7 +46,7 @@ OSRMEngine.prototype.createConfig = function() { if (instCodes[0]!=15) { instText+=s[1] ? ""+s[1]+"" : I18n.t('javascripts.directions.instructions.unnamed'); } steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]); } - if (steps.length) router.setItinerary({ steps: steps }); + if (steps.length) router.setItinerary({ steps: steps, distance: data.route_summary.total_distance, time: data.route_summary.total_time }); return true; } }; diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index a8fba1943..4eefddbe7 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -639,6 +639,10 @@ nav.secondary { font-size: 13px; } + p { + padding: 0 $lineheight $lineheight/4; + } + .icon.close { float: right; cursor: pointer; diff --git a/config/locales/en.yml b/config/locales/en.yml index e5bb7f3f0..bb3f542b7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2127,6 +2127,7 @@ en: mapquest_foot: "Foot (MapQuest)" osrm_car: "Car (OSRM)" directions: "Directions" + distance: "Distance" errors: no_route: "Couldn't find a route between those two places." no_place: "Sorry - couldn't find that place." @@ -2149,6 +2150,7 @@ en: against_oneway: "Go against one-way on " end_oneway: "End of one-way on " unnamed: "(unnamed)" + time: "Time" redaction: edit: description: "Description" -- 2.39.5