diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index 730aa4115..5829ec679 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -32,6 +32,7 @@ OSRM.DEFAULTS = { ONLOAD_SOURCE: "", ONLOAD_TARGET: "", HIGHLIGHT_ZOOM_LEVEL: 16, + DISTANCE_FORMAT: 0, // 0: km, 1: miles GEOCODER_BOUNDS: '', // the world is not enough! //GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0', // bounds for Europe diff --git a/WebContent/gui/OSRM.RoutingGUI.js b/WebContent/gui/OSRM.RoutingGUI.js index 808081692..f8674bbb9 100644 --- a/WebContent/gui/OSRM.RoutingGUI.js +++ b/WebContent/gui/OSRM.RoutingGUI.js @@ -23,6 +23,9 @@ OSRM.GUI.extend( { // init init: function() { + // init variables + OSRM.G.DISTANCE_FORMAT = OSRM.DEFAULTS.DISTANCE_FORMAT; + // init events document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);}; document.getElementById("gui-delete-source").onclick = function() {OSRM.GUI.deleteMarker(OSRM.C.SOURCE_LABEL);}; diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index e00aaf855..5907af799 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -85,11 +85,11 @@ show: function(response) { '
' + '
' + '
' + OSRM.loc("DISTANCE")+':
' + - '
' + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + + '
' + OSRM.Utils.toHumanDistance(response.route_summary.total_distance) + '
' + '
' + '
' + '
' + OSRM.loc("DURATION")+':
' + - '
' + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + + '
' + OSRM.Utils.toHumanTime(response.route_summary.total_time) + '
' + '
' + '
' + '' + @@ -123,7 +123,7 @@ show: function(response) { body += ''; if( i != response.route_instructions.length-1 ) - body += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + body += ''+OSRM.Utils.toHumanDistance(response.route_instructions[i][2])+''; body += ""; body += ""; diff --git a/WebContent/routing/OSRM.RoutingDescription.js b/WebContent/routing/OSRM.RoutingDescription.js index 54ad48a4c..5cfd4c779 100644 --- a/WebContent/routing/OSRM.RoutingDescription.js +++ b/WebContent/routing/OSRM.RoutingDescription.js @@ -92,7 +92,7 @@ show: function(response) { body += ''; if( i != response.route_instructions.length-1 ) - body += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + body += ''+OSRM.Utils.toHumanDistance(response.route_instructions[i][2])+''; body += ""; body += ""; @@ -100,7 +100,7 @@ show: function(response) { body += ''; // build header - header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.metersToDistance(response.route_summary.total_distance), OSRM.Utils.secondsToTime(response.route_summary.total_time), route_link, gpx_link); + header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.toHumanDistance(response.route_summary.total_distance), OSRM.Utils.toHumanTime(response.route_summary.total_time), route_link, gpx_link); // update DOM document.getElementById('information-box-header').innerHTML = header; @@ -110,7 +110,7 @@ show: function(response) { // simple description showSimple: function(response) { // build header - header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.metersToDistance(response.route_summary.total_distance), OSRM.Utils.secondsToTime(response.route_summary.total_time), "", ""); + header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.toHumanDistance(response.route_summary.total_distance), OSRM.Utils.toHumanTime(response.route_summary.total_time), "", ""); // update DOM document.getElementById('information-box-header').innerHTML = header; diff --git a/WebContent/utils/OSRM.Utils.js b/WebContent/utils/OSRM.Utils.js index 9c4decdc7..b1147c259 100644 --- a/WebContent/utils/OSRM.Utils.js +++ b/WebContent/utils/OSRM.Utils.js @@ -24,7 +24,7 @@ OSRM.Utils = { // [human readabilty functions] // human readable time -secondsToTime: function(seconds){ +toHumanTime: function(seconds){ seconds = parseInt(seconds); minutes = parseInt(seconds/60); seconds = seconds%60; @@ -38,13 +38,22 @@ secondsToTime: function(seconds){ } }, //human readable distance -metersToDistance: function(distance){ - distance = parseInt(distance); +toHumanDistance: function(meters){ + var distance = parseInt(meters); - if(distance >= 100000){ return (parseInt(distance/1000))+' ' + 'km'; } - else if(distance >= 10000){ return (parseInt(distance/1000).toFixed(1))+' ' + 'km'; } - else if(distance >= 1000){ return (parseFloat(distance/1000).toFixed(2))+' ' + 'km'; } - else{ return distance+' ' + 'm'; } + if(OSRM.G.DISTANCE_FORMAT == 1) { // miles + distance = distance / 1609.344; + if(distance >= 100){ return (distance).toFixed(0)+' ' + 'mi'; } + else if(distance >= 10){ return (distance).toFixed(1)+' ' + 'mi'; } + else if(distance >= 0.1){ return (distance).toFixed(2)+' ' + 'mi'; } + else{ return (distance*5280).toFixed(0)+' ' + 'ft'; } + } else { // default to km, m + distance = distance / 1000; + if(distance >= 100){ return (distance).toFixed(0)+' ' + 'km'; } + else if(distance >= 10){ return (distance).toFixed(1)+' ' + 'km'; } + else if(distance >= 0.1){ return (distance).toFixed(2)+' ' + 'km'; } + else{ return (distance*1000).toFixed(0)+' ' + 'm'; } + } },