From 1a9776cff92671828b6b6482465f1991bb41dac0 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 28 Mar 2012 12:17:22 +0100 Subject: [PATCH] moved utils into OSRM namespace --- WebContent/{utils.js => OSRM.Utils.js} | 30 +++++++++++++++++--------- WebContent/main.html | 2 +- WebContent/main.js | 6 +++--- WebContent/routing.js | 10 ++++----- 4 files changed, 29 insertions(+), 19 deletions(-) rename WebContent/{utils.js => OSRM.Utils.js} (80%) diff --git a/WebContent/utils.js b/WebContent/OSRM.Utils.js similarity index 80% rename from WebContent/utils.js rename to WebContent/OSRM.Utils.js index a0d609221..9c4decdc7 100644 --- a/WebContent/utils.js +++ b/WebContent/OSRM.Utils.js @@ -15,8 +15,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ +// OSRM utility functions +// [mixed functions] + + +OSRM.Utils = { + +// [human readabilty functions] + // human readable time -function secondsToTime(seconds){ +secondsToTime: function(seconds){ seconds = parseInt(seconds); minutes = parseInt(seconds/60); seconds = seconds%60; @@ -28,30 +36,32 @@ function secondsToTime(seconds){ else{ return hours + ' ' + 'h' + ' ' + minutes + ' ' + 'min'; } -} - -// human readable distance -function getDistanceWithUnit(distance){ +}, +//human readable distance +metersToDistance: function(distance){ distance = parseInt(distance); 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'; } -} +}, -//------------------------------------------------------ + +// [verification routines] // verify angles -function isLatitude(value) { +isLatitude: function(value) { if( value >=-90 && value <=90) return true; else return false; -} -function isLongitude(value) { +}, +isLongitude: function(value) { if( value >=-180 && value <=180) return true; else return false; } + +}; \ No newline at end of file diff --git a/WebContent/main.html b/WebContent/main.html index 14dd67d2c..c42a10374 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -59,7 +59,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + diff --git a/WebContent/main.js b/WebContent/main.js index 9be9ce245..dd97ca4eb 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -212,13 +212,13 @@ function checkURL(){ if(name_val[0] == 'loc') { var coordinates = unescape(name_val[1]).split(','); - if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) ) + if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) ) return; positions.push ( new L.LatLng( coordinates[0], coordinates[1]) ); } else if(name_val[0] == 'dest') { var coordinates = unescape(name_val[1]).split(','); - if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) ) + if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) ) return; destination = new L.LatLng( coordinates[0], coordinates[1]); } @@ -232,7 +232,7 @@ function checkURL(){ } else if(name_val[0] == 'center') { var coordinates = unescape(name_val[1]).split(','); - if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) ) + if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) ) return; center = new L.LatLng( coordinates[0], coordinates[1]); } diff --git a/WebContent/routing.js b/WebContent/routing.js index ca7b5f8fe..7a44fd013 100644 --- a/WebContent/routing.js +++ b/WebContent/routing.js @@ -177,7 +177,7 @@ function showRouteDescription(response) { route_desc += ''; if( i != response.route_instructions.length-1 ) - route_desc += ''+getDistanceWithUnit(response.route_instructions[i][2])+''; + route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; route_desc += ""; route_desc += ""; @@ -188,9 +188,9 @@ function showRouteDescription(response) { headline += OSRM.loc("ROUTE_DESCRIPTION")+":
"; headline += '
'; headline += "" - + OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance) + + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + "
" - + OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time) + + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + "
"; headline += '
'; headline += '
'+route_link+'
'+gpx_link+'
'; @@ -204,9 +204,9 @@ function showRouteDescription(response) { function showRouteDescriptionSimple(response) { headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; headline += "" - + OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance) + + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + "
" - + OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time) + + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + "
"; headline += '

';