added parameter to set meters/miles,
changed toHumanDistance functions so that conditions don't need to be checked all the time
This commit is contained in:
parent
7451cc3150
commit
826cbc9a24
@ -24,7 +24,7 @@ OSRM.GUI.extend( {
|
|||||||
// init
|
// init
|
||||||
init: function() {
|
init: function() {
|
||||||
// init variables
|
// init variables
|
||||||
OSRM.G.DISTANCE_FORMAT = OSRM.DEFAULTS.DISTANCE_FORMAT;
|
OSRM.Utils.setToHumanDistanceFunction(OSRM.DEFAULTS.DISTANCE_FORMAT);
|
||||||
|
|
||||||
// init events
|
// init events
|
||||||
document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);};
|
document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);};
|
||||||
|
@ -165,6 +165,12 @@ OSRM.parseParameters = function(){
|
|||||||
if(name_val[0] == 'hl') {
|
if(name_val[0] == 'hl') {
|
||||||
OSRM.Localization.setLanguage(name_val[1]);
|
OSRM.Localization.setLanguage(name_val[1]);
|
||||||
}
|
}
|
||||||
|
else if(name_val[0] == 'df') {
|
||||||
|
var type = parseInt(name_val[1]);
|
||||||
|
if(type != 0 && type != 1)
|
||||||
|
return;
|
||||||
|
OSRM.Utils.setToHumanDistanceFunction(type);
|
||||||
|
}
|
||||||
else if(name_val[0] == 'loc') {
|
else if(name_val[0] == 'loc') {
|
||||||
var coordinates = unescape(name_val[1]).split(',');
|
var coordinates = unescape(name_val[1]).split(',');
|
||||||
if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) )
|
if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) )
|
||||||
|
@ -31,6 +31,7 @@ onClickRouteDescription: function(geometry_index) {
|
|||||||
},
|
},
|
||||||
onClickCreateShortcut: function(src){
|
onClickCreateShortcut: function(src){
|
||||||
src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat.toFixed(6) + ',' + OSRM.G.map.getCenter().lng.toFixed(6);
|
src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat.toFixed(6) + ',' + OSRM.G.map.getCenter().lng.toFixed(6);
|
||||||
|
src += '&df=' + OSRM.G.DISTANCE_FORMAT;
|
||||||
|
|
||||||
var source = OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, OSRM.DEFAULTS.HOST_SHORTENER_URL+src);
|
var source = OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, OSRM.DEFAULTS.HOST_SHORTENER_URL+src);
|
||||||
|
|
||||||
|
@ -31,30 +31,39 @@ toHumanTime: function(seconds){
|
|||||||
hours = parseInt(minutes/60);
|
hours = parseInt(minutes/60);
|
||||||
minutes = minutes%60;
|
minutes = minutes%60;
|
||||||
if(hours==0){
|
if(hours==0){
|
||||||
return minutes + ' ' + 'min';
|
return minutes + ' ' + 'min';
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return hours + ' ' + 'h' + ' ' + minutes + ' ' + 'min';
|
return hours + ' ' + 'h' + ' ' + minutes + ' ' + 'min';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//human readable distance
|
//human readable distance
|
||||||
toHumanDistance: function(meters){
|
setToHumanDistanceFunction: function(type) {
|
||||||
|
OSRM.G.DISTANCE_FORMAT = type;
|
||||||
|
if( type == 1 )
|
||||||
|
OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMiles;
|
||||||
|
else
|
||||||
|
OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMeters;
|
||||||
|
},
|
||||||
|
toHumanDistanceMeters: function(meters){
|
||||||
var distance = parseInt(meters);
|
var distance = parseInt(meters);
|
||||||
|
|
||||||
if(OSRM.G.DISTANCE_FORMAT == 1) { // miles
|
distance = distance / 1000;
|
||||||
distance = distance / 1609.344;
|
if(distance >= 100){ return (distance).toFixed(0)+' ' + 'km'; }
|
||||||
if(distance >= 100){ return (distance).toFixed(0)+' ' + 'mi'; }
|
else if(distance >= 10){ return (distance).toFixed(1)+' ' + 'km'; }
|
||||||
else if(distance >= 10){ return (distance).toFixed(1)+' ' + 'mi'; }
|
else if(distance >= 0.1){ return (distance).toFixed(2)+' ' + 'km'; }
|
||||||
else if(distance >= 0.1){ return (distance).toFixed(2)+' ' + 'mi'; }
|
else{ return (distance*1000).toFixed(0)+' ' + 'm'; }
|
||||||
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'; }
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
toHumanDistanceMiles: function(meters){
|
||||||
|
var distance = parseInt(meters);
|
||||||
|
|
||||||
|
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'; }
|
||||||
|
},
|
||||||
|
toHumanDistance: null,
|
||||||
|
|
||||||
|
|
||||||
// [verification routines]
|
// [verification routines]
|
||||||
|
Loading…
Reference in New Issue
Block a user