From 8ecae7ef97b07484dab19c797f4ecafcc300fbc0 Mon Sep 17 00:00:00 2001 From: shiin Date: Mon, 30 Jul 2012 15:06:15 +0200 Subject: [PATCH] support for multiple routing servers --- WebContent/OSRM.config.js | 2 +- WebContent/base/OSRM.HistoryRoutes.js | 2 +- WebContent/main.js | 9 +++++++++ WebContent/routing/OSRM.Routing.js | 3 ++- WebContent/routing/OSRM.RoutingDescription.js | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index 4d4f67b7a..dfcc746bb 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -19,7 +19,7 @@ or see http://www.gnu.org/licenses/agpl.txt. // [has to be loaded directly after OSRM.base] OSRM.DEFAULTS = { - HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute', + HOST_ROUTING_URL: ['http://router.project-osrm.org/viaroute'], HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', HOST_TIMESTAMP_URL: 'http://router.project-osrm.org/timestamp', HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search', diff --git a/WebContent/base/OSRM.HistoryRoutes.js b/WebContent/base/OSRM.HistoryRoutes.js index f2a00610c..1e96c3b96 100644 --- a/WebContent/base/OSRM.HistoryRoutes.js +++ b/WebContent/base/OSRM.HistoryRoutes.js @@ -169,7 +169,7 @@ OSRM.extend( OSRM.HistoryRoute,{ } }, _buildCall: function(history_id) { - var source = OSRM.DEFAULTS.HOST_ROUTING_URL; + var source = OSRM.DEFAULTS.HOST_ROUTING_URL[OSRM.G.active_routing_server]; source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp'; if(this._history[history_id].checksum) diff --git a/WebContent/main.js b/WebContent/main.js index 01917d8a4..254842fdf 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -238,6 +238,12 @@ OSRM.parseParameters = function(){ return; params.active_alternative = active_alternative; } + else if(name_val[0] == 'rs') { + var active_routing_server = Number(name_val[1]); + if( active_routing_server<0 || active_routing_server>=OSRM.DEFAULTS.HOST_ROUTING_URL.length) + return; + params.active_routing_server = active_routing_server; + } } // case 1: destination given @@ -279,6 +285,9 @@ OSRM.parseParameters = function(){ // set active alternative (if via points are set or alternative does not exists: automatic fallback to shortest route) OSRM.G.active_alternative = params.active_alternative || 0; + + // set routing server + OSRM.G.active_routing_server = params.active_routing_server || 0; // compute route OSRM.Routing.getRoute({keepAlternative:true}); diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index 88b363bf4..4cf924fbb 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -31,6 +31,7 @@ OSRM.Routing = { // init routing data structures init: function() { + OSRM.G.active_routing_server = 0; OSRM.G.markers = new OSRM.Markers(); OSRM.G.route = new OSRM.Route(); OSRM.G.response = { via_points:[] }; @@ -159,7 +160,7 @@ draggingTimeout: function() { }, _buildCall: function() { - var source = OSRM.DEFAULTS.HOST_ROUTING_URL; + var source = OSRM.DEFAULTS.HOST_ROUTING_URL[OSRM.G.active_routing_server]; source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp'; if(OSRM.G.markers.checksum) source += '&checksum=' + OSRM.G.markers.checksum; diff --git a/WebContent/routing/OSRM.RoutingDescription.js b/WebContent/routing/OSRM.RoutingDescription.js index 84f6ce1ce..553adb597 100644 --- a/WebContent/routing/OSRM.RoutingDescription.js +++ b/WebContent/routing/OSRM.RoutingDescription.js @@ -31,6 +31,7 @@ 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 += '&alt='+OSRM.G.active_alternative; src += '&df=' + OSRM.G.DISTANCE_FORMAT; + src += '&rs=' + OSRM.G.active_routing_server; var source = OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, OSRM.DEFAULTS.HOST_SHORTENER_URL+src); @@ -61,7 +62,7 @@ show: function(response) { var route_link ='['+OSRM.loc("GET_LINK_TO_ROUTE")+']'; // create GPX link - var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; + var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; // create route description var positions = OSRM.G.route.getPositions();