From 537b9b0623d4d2f4651ef568378f75dcdc57afb2 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Tue, 3 Jul 2012 14:39:29 +0100 Subject: [PATCH] added stuff to alternatives --- WebContent/OSRM.config.js | 2 +- WebContent/main.js | 11 +++- .../routing/OSRM.RoutingAlternatives.js | 56 ++++++++++--------- WebContent/routing/OSRM.RoutingDescription.js | 1 + 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index 5952c401b..fe30e41e1 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://i10pc68.ira.uka.de:5000/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/main.js b/WebContent/main.js index 94f69826d..100f615f4 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -216,7 +216,13 @@ OSRM.parseParameters = function(){ if(coordinates.length!=2 || !OSRM.Utils.isLatitude(coordinates[0]) || !OSRM.Utils.isLongitude(coordinates[1]) ) return; params.center = new L.LatLng( coordinates[0], coordinates[1]); - } + } + else if(name_val[0] == 'alt') { + var active_alternative = Number(name_val[1]); + if( active_alternative<0 || active_alternative>OSRM.RoutingAlternatives>10) // using 10 as arbitrary upper limit + return; + params.active_alternative = active_alternative; + } } // case 1: destination given @@ -255,6 +261,9 @@ OSRM.parseParameters = function(){ } else { OSRM.G.map.setView(params.center, params.zoom); } + + // 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; // compute route OSRM.Routing.getRoute(); diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 3dd3a00ac..ea1e5eff7 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -26,9 +26,7 @@ OSRM.RoutingAlternatives = { // data of gui buttons for alternativess _buttons: [ {id:"gui-a", label:"A"}, - {id:"gui-b", label:"B"}, - {id:"gui-c", label:"C"}, - {id:"gui-d", label:"D"} + {id:"gui-b", label:"B"} ], @@ -36,21 +34,20 @@ _buttons: [ prepare: function(response) { // store basic information OSRM.G.alternative_count = response.alternative_geometries.length + 1; - OSRM.G.alternative_active = 0; + OSRM.G.active_alternative = 0; // do nothing if there is no alternative - if( OSRM.G.alternative_count == 1 ) - return; +// if( OSRM.G.alternative_count == 1 ) +// return; // move best route to alternative array - console.log("prepare"); var the_response = OSRM.G.response; the_response.alternative_geometries.unshift( response.route_geometry ); the_response.alternative_instructions.unshift( response.route_instructions ); the_response.alternative_summaries.unshift( response.route_summary ); // add alternative GUI - OSRM.RoutingAlternatives._addGUI(); + OSRM.RoutingAlternatives._drawGUI(); }, prepare_Redraw: function(response) { // do nothing if there is no alternative @@ -68,29 +65,29 @@ prepare_Redraw: function(response) { the_response.alternative_summaries.unshift( response.route_summary ); // switch data - the_response.route_geometry = the_response.alternative_geometries[OSRM.G.alternative_active]; - the_response.route_instructions = the_response.alternative_instructions[OSRM.G.alternative_active]; - the_response.route_summary = the_response.alternative_summaries[OSRM.G.alternative_active]; + the_response.route_geometry = the_response.alternative_geometries[OSRM.G.active_alternative]; + the_response.route_instructions = the_response.alternative_instructions[OSRM.G.active_alternative]; + the_response.route_summary = the_response.alternative_summaries[OSRM.G.active_alternative]; }, -// press one of the buttons -press: function(button_id) { +// switch active alternative and redraw buttons accordingly +setActive: function(button_id) { // switch active alternative - OSRM.G.alternative_active = button_id; + OSRM.G.active_alternative = button_id; - // redraw buttons + // redraw clickable buttons var buttons = OSRM.RoutingAlternatives._buttons; for(var i=0, size=OSRM.G.alternative_count; i'+buttons[i].label+''; + var buttonClass = (i == OSRM.G.active_alternative) ? "button-pressed" : "button"; + var data = ''+buttons[i].label+''; document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; } + // draw non-clickable buttons + for(var i=OSRM.G.alternative_count, size=buttons.length; i'+buttons[i].label+''; + document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; + } + // add events for(var i=0, size=OSRM.G.alternative_count; i