diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/OSRM.Geocoder.js index fef263524..bc1a6f14e 100644 --- a/WebContent/OSRM.Geocoder.js +++ b/WebContent/OSRM.Geocoder.js @@ -60,7 +60,7 @@ _onclickResult: function(marker_id, lat, lon) { OSRM.G.markers.route[index].show(); OSRM.G.markers.route[index].centerView(); - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); }, diff --git a/WebContent/OSRM.JSONP.js b/WebContent/OSRM.JSONP.js index 3a337bd57..430fc8beb 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/OSRM.JSONP.js @@ -26,6 +26,7 @@ OSRM.JSONP = { callbacks: {}, timeouts: {}, timers: {}, + durations: {}, // default callback routines @@ -50,7 +51,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } -// OSRM.debug.log("[jsonp] timout handling: "+id); + OSRM.debug.log("[jsonp] timout handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); }; // wrap callback function @@ -66,7 +67,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } -// OSRM.debug.log("[jsonp] response handling: "+id); + OSRM.debug.log("[jsonp] response handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); }; // clean DOM (unfortunately, script elements cannot be reused by all browsers) @@ -83,6 +84,7 @@ OSRM.JSONP = { // start timeout timer OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); + OSRM.JSONP.durations[id] = new Date(); // OSRM.debug.log("[jsonp] init: "+id); return true; @@ -94,5 +96,6 @@ OSRM.JSONP = { OSRM.JSONP.callbacks = {}; OSRM.JSONP.timeouts = {}; OSRM.JSONP.timers = {}; + OSRM.JSONP.durations = {}; } }; \ No newline at end of file diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 801b2359e..e8fb8256a 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -114,12 +114,12 @@ onClick: function(e) { } } - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); OSRM.G.markers.highlight.hide(); }, onDrag: function(e) { this.parent.setPosition( e.target.getLatLng() ); - getRoute(OSRM.C.NO_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION); OSRM.Geocoder.updateLocation( this.parent.label ); }, onDragStart: function(e) { @@ -139,7 +139,7 @@ onDragStart: function(e) { onDragEnd: function(e) { OSRM.G.dragging = false; this.parent.setPosition( e.target.getLatLng() ); - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); if (OSRM.G.route.isShown()) { OSRM.G.route.hideOldRoute(); OSRM.G.route.hideUnnamedRoute(); diff --git a/WebContent/OSRM.Via.js b/WebContent/OSRM.Via.js index d072b9797..e8ab0ee32 100644 --- a/WebContent/OSRM.Via.js +++ b/WebContent/OSRM.Via.js @@ -63,7 +63,7 @@ findViaPosition: function( new_via_position ) { var index = OSRM.G.markers.setVia(new_via_index, new_via_position); OSRM.G.markers.route[index].show(); - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); return new_via_index; } diff --git a/WebContent/main.html b/WebContent/main.html index c42a10374..696a25d5f 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -44,7 +44,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + @@ -88,14 +88,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
| Start: | -- | Zeigen | ++ | Zeigen |
| Ende: | -- | Zeigen | ++ | Zeigen |
| Reset | -Umdrehen | +Reset | +Umdrehen |
"+OSRM.loc("TIMED_OUT")+".
";
-}
-function timeoutRoute() {
- showNoRouteGeometry();
+},
+timeoutRoute: function() {
+ OSRM.Routing.showNoRouteGeometry();
OSRM.G.route.hideUnnamedRoute();
- showNoRouteDescription();
+ OSRM.Routing.showNoRouteDescription();
document.getElementById('information-box').innerHTML = "
"+OSRM.loc("TIMED_OUT")+".
";
-}
-function showRouteSimple(response) {
+},
+showRouteSimple: function(response) {
if(!response)
return;
@@ -61,88 +63,88 @@ function showRouteSimple(response) {
return;
if( response.status == 207) {
- showNoRouteGeometry();
- showNoRouteDescription();
+ OSRM.Routing.showNoRouteGeometry();
+ OSRM.Routing.showNoRouteDescription();
document.getElementById('information-box').innerHTML = "
"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".
";
} else {
- showRouteGeometry(response);
- showRouteDescriptionSimple(response);
+ OSRM.Routing.showRouteGeometry(response);
+ OSRM.Routing.showRouteDescriptionSimple(response);
}
- updateHints(response);
+ OSRM.Routing.updateHints(response);
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
// if(OSRM.G.pending) {
// clearTimeout(OSRM.G.pendingTimer);
-// OSRM.G.pendingTimer = setTimeout(timeoutDrag,100);
+// OSRM.G.pendingTimer = setTimeout(OSRM.Routing.timeoutDrag,100);
// }
-}
-function showRoute(response) {
+},
+showRoute: function(response) {
if(!response)
return;
if(response.status == 207) {
- showNoRouteGeometry();
+ OSRM.Routing.showNoRouteGeometry();
OSRM.G.route.hideUnnamedRoute();
- showNoRouteDescription();
+ OSRM.Routing.showNoRouteDescription();
document.getElementById('information-box').innerHTML = "
"+OSRM.loc("NO_ROUTE_FOUND")+".
";
} else {
- showRouteGeometry(response);
- showRouteNonames(response);
- showRouteDescription(response);
- snapRoute();
+ OSRM.Routing.showRouteGeometry(response);
+ OSRM.Routing.showRouteNonames(response);
+ OSRM.Routing.showRouteDescription(response);
+ OSRM.Routing.snapRoute();
}
- updateHints(response);
-}
+ OSRM.Routing.updateHints(response);
+},
// show route geometry
-function showNoRouteGeometry() {
+showNoRouteGeometry: function() {
var positions = [];
for(var i=0; i "+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+". ";
-}
-function showNoRouteDescription() {
+},
+showNoRouteDescription: function() {
headline = OSRM.loc("ROUTE_DESCRIPTION")+": "+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+". ";
-}
+},
// unnamed streets display
-function showRouteNonames(response) {
+showRouteNonames: function(response) {
// do not display unnamed streets?
if( document.getElementById('option-highlight-nonames').checked == false) {
OSRM.G.route.hideUnnamedRoute();
@@ -245,7 +247,7 @@ function showRouteNonames(response) {
}
// aggregate geometry for unnamed streets
- var geometry = decodeRouteGeometry(response.route_geometry, 5);
+ var geometry = OSRM.Routing.decodeRouteGeometry(response.route_geometry, 5);
var is_named = true;
var current_positions = [];
var all_positions = [];
@@ -266,13 +268,13 @@ function showRouteNonames(response) {
// display unnamed streets
OSRM.G.route.showUnnamedRoute(all_positions);
-}
+},
//-- main function --
// generate server calls to query routes
-function getRoute(do_description) {
+getRoute: function(do_description) {
// if source or target are not set -> hide route
if( OSRM.G.markers.route.length < 2 ) {
@@ -297,13 +299,13 @@ function getRoute(do_description) {
// decide whether it is a dragging call or a normal one
if (do_description) {
- callback = showRoute;
- timeout = timeoutRoute;
+ callback = OSRM.Routing.showRoute;
+ timeout = OSRM.Routing.timeoutRoute;
source +='&instructions=true';
type = 'route';
} else {
- callback = showRouteSimple;
- timeout = timeoutRouteSimple;
+ callback = OSRM.Routing.showRouteSimple;
+ timeout = OSRM.Routing.timeoutRouteSimple;
source +='&instructions=false';
type = 'dragging';
}
@@ -314,7 +316,7 @@ function getRoute(do_description) {
// TODO: hack to process final drag event, if it was fenced, but we are still dragging
if(called == false && !do_description) {
clearTimeout(OSRM.G.pendingTimer);
- OSRM.G.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
+ OSRM.G.pendingTimer = setTimeout(OSRM.Routing.timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
}
else {
clearTimeout(OSRM.G.pendingTimer);
@@ -326,17 +328,17 @@ function getRoute(do_description) {
// clearTimeout(OSRM.G.pendingTimer);
// OSRM.G.pending = false;
// }
-}
-function timeoutDrag() {
+},
+timeoutDrag: function() {
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
- getRoute(OSRM.C.NO_DESCRIPTION);
-}
+ OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION);
+},
//-- helper functions --
//decode compressed route geometry
-function decodeRouteGeometry(encoded, precision) {
+decodeRouteGeometry: function(encoded, precision) {
precision = Math.pow(10, -precision);
var len = encoded.length, index=0, lat=0, lng = 0, array = [];
while (index < len) {
@@ -360,18 +362,18 @@ function decodeRouteGeometry(encoded, precision) {
array.push([lat * precision, lng * precision]);
}
return array;
-}
+},
// update hints of all markers
-function updateHints(response) {
+updateHints: function(response) {
var hint_locations = response.hint_data.locations;
OSRM.G.markers.checksum = response.hint_data.checksum;
for(var i=0; i';
route_desc += ' ';
- route_desc += ' ";
route_desc += '';
+ route_desc += '
';
route_desc += "
';
- route_desc += '';
+ route_desc += '';
route_desc += response.route_instructions[i][0];
if( i == 0 )
route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] );
@@ -200,8 +202,8 @@ function showRouteDescription(response) {
document.getElementById('information-box-headline').innerHTML = headline;
document.getElementById('information-box').innerHTML = output;
-}
-function showRouteDescriptionSimple(response) {
+},
+showRouteDescriptionSimple: function(response) {
headline = OSRM.loc("ROUTE_DESCRIPTION")+":
";
headline += ""
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
@@ -212,8 +214,8 @@ function showRouteDescriptionSimple(response) {
document.getElementById('information-box-headline').innerHTML = headline;
document.getElementById('information-box').innerHTML = "
";
headline += ""
+ OSRM.loc("DISTANCE")+": N/A"
@@ -224,11 +226,11 @@ function showNoRouteDescription() {
document.getElementById('information-box-headline').innerHTML = headline;
document.getElementById('information-box').innerHTML = "