moved utils into OSRM namespace

This commit is contained in:
DennisSchiefer 2012-03-28 12:17:22 +01:00
parent 342a0d22bd
commit 1a9776cff9
4 changed files with 29 additions and 19 deletions

View File

@ -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;
}
};

View File

@ -59,7 +59,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
<script src="routing.js" type="text/javascript"></script>
<script src="OSRM.Via.js" type="text/javascript"></script>
<script src="utils.js" type="text/javascript"></script>
<script src="OSRM.Utils.js" type="text/javascript"></script>
</head>

View File

@ -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]);
}

View File

@ -177,7 +177,7 @@ function showRouteDescription(response) {
route_desc += '<td class="result-distance">';
if( i != response.route_instructions.length-1 )
route_desc += '<b>'+getDistanceWithUnit(response.route_instructions[i][2])+'</b>';
route_desc += '<b>'+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+'</b>';
route_desc += "</td>";
route_desc += "</tr>";
@ -188,9 +188,9 @@ function showRouteDescription(response) {
headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
headline += '<div style="float:left;width:40%">';
headline += "<span class='route-summary'>"
+ OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance)
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
+ "<br>"
+ OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time)
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
+ "</span>";
headline += '</div>';
headline += '<div style="float:left;text-align:right;width:60%;">'+route_link+'<br>'+gpx_link+'</div>';
@ -204,9 +204,9 @@ function showRouteDescription(response) {
function showRouteDescriptionSimple(response) {
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
headline += "<span class='route-summary'>"
+ OSRM.loc("DISTANCE")+": " + getDistanceWithUnit(response.route_summary.total_distance)
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
+ "<br>"
+ OSRM.loc("DURATION")+": " + secondsToTime(response.route_summary.total_time)
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
+ "</span>";
headline += '<br><br>';