Add distance/time summary

This commit is contained in:
Richard Fairhurst 2014-03-08 16:14:14 +00:00
parent 9a05a7ba49
commit 3ef8024b1d
6 changed files with 23 additions and 5 deletions

View file

@ -194,7 +194,10 @@ OSM.Routing=function(map,name,jqSearch) {
$('#sidebar_content').empty(); $('#sidebar_content').empty();
var html=('<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;">' + var html=('<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;">' +
'<span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') + '<span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') +
'</h2><table id="turnbyturn" />').replace(/~/g,"'"); '</h2><p id="routing_summary">' +
I18n.t('javascripts.directions.distance') + ': ' + r.formatDistance(data.distance)+ '. ' +
I18n.t('javascripts.directions.time' ) + ': ' + r.formatTime(data.time) + '.</p>' +
'<table id="turnbyturn" />').replace(/~/g,"'");
$('#sidebar_content').html(html); $('#sidebar_content').html(html);
// Add each row // Add each row
var cumulative=0; var cumulative=0;
@ -224,6 +227,15 @@ OSM.Routing=function(map,name,jqSearch) {
r.clickTurn=function(num,latlng) { r.clickTurn=function(num,latlng) {
r.popup=L.popup().setLatLng(latlng).setContent("<p>"+(num+1)+"</p>").openOn(r.map); r.popup=L.popup().setLatLng(latlng).setContent("<p>"+(num+1)+"</p>").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 // Close all routing UI

View file

@ -44,7 +44,7 @@ GraphHopperEngine.prototype.createConfig = function() {
var distInMeter = instr.distances[i]; var distInMeter = instr.distances[i];
steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]); 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; return true;
}, },
GH_INSTR_MAP: { GH_INSTR_MAP: {

View file

@ -47,7 +47,7 @@ MapQuestEngine.prototype.createConfig = function() {
url+="&"+that.vehicleParam; 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+="&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+="&manMaps=false";
url+="&shapeFormat=raw&generalize=0"; url+="&shapeFormat=raw&generalize=0&unit=k";
this.requestCORS(url); this.requestCORS(url);
}, },
gotRoute: function(router,data) { 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]; 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]); 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; return true;
} }
}; };

View file

@ -46,7 +46,7 @@ OSRMEngine.prototype.createConfig = function() {
if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); } if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); }
steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]); 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; return true;
} }
}; };

View file

@ -639,6 +639,10 @@ nav.secondary {
font-size: 13px; font-size: 13px;
} }
p {
padding: 0 $lineheight $lineheight/4;
}
.icon.close { .icon.close {
float: right; float: right;
cursor: pointer; cursor: pointer;

View file

@ -2127,6 +2127,7 @@ en:
mapquest_foot: "Foot (MapQuest)" mapquest_foot: "Foot (MapQuest)"
osrm_car: "Car (OSRM)" osrm_car: "Car (OSRM)"
directions: "Directions" directions: "Directions"
distance: "Distance"
errors: errors:
no_route: "Couldn't find a route between those two places." no_route: "Couldn't find a route between those two places."
no_place: "Sorry - couldn't find that place." no_place: "Sorry - couldn't find that place."
@ -2149,6 +2150,7 @@ en:
against_oneway: "Go against one-way on " against_oneway: "Go against one-way on "
end_oneway: "End of one-way on " end_oneway: "End of one-way on "
unnamed: "(unnamed)" unnamed: "(unnamed)"
time: "Time"
redaction: redaction:
edit: edit:
description: "Description" description: "Description"