From 7d826619271e58661dbd1667ffa0887977b9c1d6 Mon Sep 17 00:00:00 2001 From: shiin Date: Sun, 17 Jun 2012 09:07:32 +0200 Subject: [PATCH 01/10] first code for managing alternatives --- WebContent/base/OSRM.Routes.js | 18 +++- WebContent/main.css | 15 +++ WebContent/routing/OSRM.Routing.js | 1 + .../routing/OSRM.RoutingAlternatives.js | 92 +++++++++++++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 WebContent/routing/OSRM.RoutingAlternatives.js diff --git a/WebContent/base/OSRM.Routes.js b/WebContent/base/OSRM.Routes.js index e03d8fe75..48acba14d 100644 --- a/WebContent/base/OSRM.Routes.js +++ b/WebContent/base/OSRM.Routes.js @@ -20,9 +20,10 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.Route = function() { - this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} ); - this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} ); - this._unnamed_route = new OSRM.MultiRoute("unnamed"); + this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} ); + this._alternative_route = new OSRM.SimpleRoute("alternative" , {dashed:false} ); + this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} ); + this._unnamed_route = new OSRM.MultiRoute("unnamed"); this._current_route_style = {dashed:false,color:'#0033FF', weight:5}; this._current_noroute_style = {dashed:true, color:'#222222', weight:2}; @@ -30,6 +31,7 @@ OSRM.Route = function() { this._old_noroute_style = {dashed:true, color:'#000000', weight:2}; this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10}; this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10}; + this._alternative_route_style = {dashed:false,color:'#FF3300', weight:5}; this._noroute = OSRM.Route.ROUTE; this._history = new OSRM.HistoryRoute(); @@ -99,6 +101,16 @@ OSRM.extend( OSRM.Route,{ this._old_route.hide(); }, + // show/hide alternative route + showAlternativeRoute: function(positions) { + this._alternative_route.setPositions( positions ); + this._alternative_route.setStyle( this._alternative_route_style ); + this._alternative_route.show(); + }, + hideAlternativeRoute: function() { + this._alternative_route.hide(); + }, + // query routines isShown: function() { return this._current_route.isShown(); diff --git a/WebContent/main.css b/WebContent/main.css index 2b61e5071..219dcd911 100644 --- a/WebContent/main.css +++ b/WebContent/main.css @@ -532,6 +532,21 @@ html, body { outline-style:none; vertical-align:1px; } +.button-pressed +{ + cursor:pointer; + padding:2px 10px 2px 10px; + border-radius:5px; + -moz-border-radius:5px; + -webkit-border-radius:5px; + background-color:#DDDDDD; + border:1px solid #999999; + color:#000000; + text-decoration:none; + font-size:9px; + outline-style:none; + vertical-align:1px; +} /* iconic buttons */ diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index 8dccb7f63..e11be5906 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -68,6 +68,7 @@ showRoute: function(response) { OSRM.RoutingGeometry.show(response); OSRM.RoutingNoNames.show(response); OSRM.RoutingDescription.show(response); + OSRM.RoutingAlternatives.prepare(response); OSRM.Routing._snapRoute(); } OSRM.Routing._updateHints(response); diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js new file mode 100644 index 000000000..23f88dcee --- /dev/null +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -0,0 +1,92 @@ +/* +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. +*/ + +// OSRM routing alternatives +// [everything about handling alternatives] + + +OSRM.RoutingAlternatives = { + +// prepare response +prepare: function() { + OSRM.RoutingAlternatives._buildAlternatives(); +}, + +// add alternatives +_buildAlternatives: function() { + var data = + 'B' + + 'A'; + document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; + OSRM.G.response.active = 0; + + document.getElementById("gui-a").onclick = function () { + if( OSRM.G.response.active == 0 ) + return; + document.getElementById("gui-a").className = "button-pressed top-right-button"; + document.getElementById("gui-b").className = "button top-right-button"; + OSRM.G.route.hideAlternativeRoute(); + OSRM.G.response.active = 0; + // switch data + //OSRM.Routing.showRoute(OSRM.G.response); + console.log("click a"); + }; + document.getElementById("gui-a").onmouseover = function () { + if( OSRM.G.response.active == 0 ) + return; + + var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5); + OSRM.G.route.showAlternativeRoute(geometry); + console.log("over a"); + }; + document.getElementById("gui-a").onmouseout = function () { + if( OSRM.G.response.active == 0 ) + return; + + OSRM.G.route.hideAlternativeRoute(); + console.log("out a"); + }; + + document.getElementById("gui-b").onclick = function () { + if( OSRM.G.response.active == 1 ) + return; + document.getElementById("gui-a").className = "button top-right-button"; + document.getElementById("gui-b").className = "button-pressed top-right-button"; + OSRM.G.route.hideAlternativeRoute(); + OSRM.G.response.active = 1; + // switch data + //OSRM.Routing.showRoute(OSRM.G.response); + console.log("click b"); + }; + document.getElementById("gui-b").onmouseover = function () { + if( OSRM.G.response.active == 1 ) + return; + + var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5); + OSRM.G.route.showAlternativeRoute(geometry); + console.log("over b"); + }; + document.getElementById("gui-b").onmouseout = function () { + if( OSRM.G.response.active == 1 ) + return; + + OSRM.G.route.hideAlternativeRoute(); + console.log("out b"); + }; +} + +}; \ No newline at end of file From 7b94a3092f54592af9c627eafc6e734fde259f6b Mon Sep 17 00:00:00 2001 From: shiin Date: Sun, 17 Jun 2012 11:04:27 +0200 Subject: [PATCH 02/10] preparation for zooming --- WebContent/routing/OSRM.Routing.js | 1 + 1 file changed, 1 insertion(+) diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index e11be5906..169c53dcd 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -97,6 +97,7 @@ showRoute_Redraw: function(response) { return; //OSRM.G.response = response; // not needed, even harmful as important information is not stored! + //OSRM.RoutingAlternatives.prepare_Redraw(response); if(response.status != 207) { OSRM.RoutingGeometry.show(response); OSRM.RoutingNoNames.show(response); From 59775a9864aaa5b4d49fda1a9b49064adbd8a24c Mon Sep 17 00:00:00 2001 From: shiin Date: Sun, 17 Jun 2012 18:23:57 +0200 Subject: [PATCH 03/10] more towards alternatives --- .../routing/OSRM.RoutingAlternatives.js | 129 ++++++++++-------- 1 file changed, 72 insertions(+), 57 deletions(-) diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 23f88dcee..6e46bca95 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -21,72 +21,87 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.RoutingAlternatives = { +// remaining problems: how to handle PRINTING (do it internally), LINKS (add parameter to JSONP call) + +// name of gui buttons to choose alternatives +_buttons: ["gui_a", "gui_b"], + // prepare response -prepare: function() { - OSRM.RoutingAlternatives._buildAlternatives(); +prepare: function(response) { + var original = {}; + original.route_geometry = response.route_geometry; + original.route_instructions = response.route_instructions; + original.route_summary = response.route_summary; + OSRM.G.response.alternatives.push( original ); + + OSRM.G.response.active_alternative = 0; + + OSRM.RoutingAlternatives._addGUI(); +}, +prepare_Redraw: function(response) { + var original = {}; + original.route_geometry = response.route_geometry; + original.route_instructions = response.route_instructions; + original.route_summary = response.route_summary; + OSRM.G.response.alternatives = response.alternatives; + OSRM.G.response.alternatives.push( original ); + + OSRM.RoutingAlternatives._addGUI(); +}, + +// press one of the buttons +press: function(button_id) { + var buttons = OSRM.RoutingAlternatives._buttons; + for(var i=0, size=buttons; iA'; + 'A'; document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; - OSRM.G.response.active = 0; - document.getElementById("gui-a").onclick = function () { - if( OSRM.G.response.active == 0 ) - return; - document.getElementById("gui-a").className = "button-pressed top-right-button"; - document.getElementById("gui-b").className = "button top-right-button"; - OSRM.G.route.hideAlternativeRoute(); - OSRM.G.response.active = 0; - // switch data - //OSRM.Routing.showRoute(OSRM.G.response); - console.log("click a"); - }; - document.getElementById("gui-a").onmouseover = function () { - if( OSRM.G.response.active == 0 ) - return; + OSRM.RoutingAlternatives.press( OSRM.G.response.active_alternative ); - var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5); - OSRM.G.route.showAlternativeRoute(geometry); - console.log("over a"); - }; - document.getElementById("gui-a").onmouseout = function () { - if( OSRM.G.response.active == 0 ) - return; - - OSRM.G.route.hideAlternativeRoute(); - console.log("out a"); - }; - - document.getElementById("gui-b").onclick = function () { - if( OSRM.G.response.active == 1 ) - return; - document.getElementById("gui-a").className = "button top-right-button"; - document.getElementById("gui-b").className = "button-pressed top-right-button"; - OSRM.G.route.hideAlternativeRoute(); - OSRM.G.response.active = 1; - // switch data - //OSRM.Routing.showRoute(OSRM.G.response); - console.log("click b"); - }; - document.getElementById("gui-b").onmouseover = function () { - if( OSRM.G.response.active == 1 ) - return; - - var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5); - OSRM.G.route.showAlternativeRoute(geometry); - console.log("over b"); - }; - document.getElementById("gui-b").onmouseout = function () { - if( OSRM.G.response.active == 1 ) - return; - - OSRM.G.route.hideAlternativeRoute(); - console.log("out b"); - }; + var buttons = OSRM.RoutingAlternatives._buttons; + for(var i=0, size=buttons; i Date: Wed, 20 Jun 2012 22:08:25 +0200 Subject: [PATCH 04/10] more alternative stuff --- WebContent/OSRM.config.js | 2 +- WebContent/main.css | 2 +- WebContent/main.html | 1 + .../routing/OSRM.RoutingAlternatives.js | 95 +++++++++++-------- 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index fe30e41e1..5952c401b 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://i10pc68.ira.uka.de:5000/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.css b/WebContent/main.css index 219dcd911..aea366930 100644 --- a/WebContent/main.css +++ b/WebContent/main.css @@ -539,7 +539,7 @@ html, body { border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; - background-color:#DDDDDD; + background-color:#AAAAAA; border:1px solid #999999; color:#000000; text-decoration:none; diff --git a/WebContent/main.html b/WebContent/main.html index 4dadffd95..ca9fa97e1 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -65,6 +65,7 @@ or see http://www.gnu.org/licenses/agpl.txt. + diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 6e46bca95..64ab47fd8 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -23,19 +23,32 @@ OSRM.RoutingAlternatives = { // remaining problems: how to handle PRINTING (do it internally), LINKS (add parameter to JSONP call) -// name of gui buttons to choose alternatives -_buttons: ["gui_a", "gui_b"], - -// prepare response +// 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"} +], + + +// prepare using alternatives prepare: function(response) { - var original = {}; - original.route_geometry = response.route_geometry; - original.route_instructions = response.route_instructions; - original.route_summary = response.route_summary; - OSRM.G.response.alternatives.push( original ); + // store basic information + OSRM.G.alternative_count = response.alternative_geometries.length; + OSRM.G.alternative_active = 0; - OSRM.G.response.active_alternative = 0; + // do nothing if there is no alternative + if( OSRM.G.alternative_count == 0 ) + return; + + // move best route to alternative array + 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(); }, prepare_Redraw: function(response) { @@ -51,57 +64,65 @@ prepare_Redraw: function(response) { // press one of the buttons press: function(button_id) { + // switch active alternative + OSRM.G.alternative_active = button_id; + + // redraw buttons var buttons = OSRM.RoutingAlternatives._buttons; - for(var i=0, size=buttons; iB' + - 'A'; - document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; - - OSRM.RoutingAlternatives.press( OSRM.G.response.active_alternative ); - var buttons = OSRM.RoutingAlternatives._buttons; - for(var i=0, size=buttons; i'+buttons[i].label+''; + document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; + document.getElementById(buttons[i].id).onclick = function (button_id) { return function() {OSRM.RoutingAlternatives._click(button_id); }; }(i) ; + document.getElementById(buttons[i].id).onmouseover = function (button_id) { return function() {OSRM.RoutingAlternatives._mouseover(button_id); }; } (i); + document.getElementById(buttons[i].id).onmouseout = function (button_id) { return function() {OSRM.RoutingAlternatives._mouseout(button_id); }; } (i); } + OSRM.RoutingAlternatives.press( OSRM.G.alternative_active ); } }; \ No newline at end of file From 90c48abeafcc4519038927f42e13daea5c4bdaaa Mon Sep 17 00:00:00 2001 From: shiin Date: Wed, 20 Jun 2012 23:52:43 +0200 Subject: [PATCH 05/10] more alternative stuff --- WebContent/routing/OSRM.RoutingAlternatives.js | 10 +++++++--- WebContent/utils/OSRM.Utils.js | 9 +++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 64ab47fd8..68f5db5e2 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -35,14 +35,15 @@ _buttons: [ // prepare using alternatives prepare: function(response) { // store basic information - OSRM.G.alternative_count = response.alternative_geometries.length; + OSRM.G.alternative_count = response.alternative_geometries.length + 1; OSRM.G.alternative_active = 0; // do nothing if there is no alternative - if( OSRM.G.alternative_count == 0 ) + 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 ); @@ -86,12 +87,13 @@ _click: function(button_id) { var the_response = OSRM.G.response; the_response.route_geometry = the_response.alternative_geometries[button_id]; the_response.route_instructions = the_response.alternative_instructions[button_id]; - the_response.alternative_summaries = the_response.alternative_summaries[button_id]; + the_response.route_summary = the_response.alternative_summaries[button_id]; // show alternative OSRM.RoutingGeometry.show(the_response); OSRM.RoutingNoNames.show(the_response); OSRM.RoutingDescription.show(the_response); + OSRM.RoutingAlternatives._addGUI(); }, _mouseover: function(button_id) { console.log("over "+button_id); @@ -118,6 +120,8 @@ _addGUI: function() { var tooltip = OSRM.loc("DISTANCE")+":"+distance+" "+OSRM.loc("DURATION")+":"+time; var data = ''+buttons[i].label+''; document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; + } + for(var i=0, size=OSRM.G.alternative_count; i Date: Thu, 21 Jun 2012 08:26:57 +0100 Subject: [PATCH 06/10] alternatives work with zooming now --- WebContent/routing/OSRM.Routing.js | 5 ++-- .../routing/OSRM.RoutingAlternatives.js | 24 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index 169c53dcd..f004bd4cc 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -99,8 +99,9 @@ showRoute_Redraw: function(response) { //OSRM.G.response = response; // not needed, even harmful as important information is not stored! //OSRM.RoutingAlternatives.prepare_Redraw(response); if(response.status != 207) { - OSRM.RoutingGeometry.show(response); - OSRM.RoutingNoNames.show(response); + OSRM.RoutingAlternatives.prepare_Redraw(response); + OSRM.RoutingGeometry.show(OSRM.G.response); + OSRM.RoutingNoNames.show(OSRM.Gresponse); } OSRM.Routing._updateHints(response); }, diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 68f5db5e2..3dd3a00ac 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -53,14 +53,24 @@ prepare: function(response) { OSRM.RoutingAlternatives._addGUI(); }, prepare_Redraw: function(response) { - var original = {}; - original.route_geometry = response.route_geometry; - original.route_instructions = response.route_instructions; - original.route_summary = response.route_summary; - OSRM.G.response.alternatives = response.alternatives; - OSRM.G.response.alternatives.push( original ); + // do nothing if there is no alternative + if( OSRM.G.alternative_count == 1 ) + return; - OSRM.RoutingAlternatives._addGUI(); + // move results + var the_response = OSRM.G.response; + the_response.alternative_geometries = response.alternative_geometries; + the_response.alternative_instructions = response.alternative_instructions; + the_response.alternative_summaries = response.alternative_summaries; + + the_response.alternative_geometries.unshift( response.route_geometry ); + the_response.alternative_instructions.unshift( response.route_instructions ); + 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]; }, // press one of the buttons From 537b9b0623d4d2f4651ef568378f75dcdc57afb2 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Tue, 3 Jul 2012 14:39:29 +0100 Subject: [PATCH 07/10] 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 Date: Tue, 3 Jul 2012 15:17:29 +0100 Subject: [PATCH 08/10] printing and alternatives works! --- WebContent/printing/OSRM.Printing.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index 081f1b8bf..c71c167f7 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -187,13 +187,15 @@ show: function(response) { // draw route & query for better geometry print_window.OSRM.drawRoute( positions ); OSRM.JSONP.call(OSRM.Routing._buildCall()+'&z='+zoom+'&instructions=false', OSRM.Printing.drawRoute, OSRM.Printing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'print'); - // NOTE: simply appended correct zoom level as second zoom parameter to JSONP call -> OSRM API only considers the last one! + // NOTE: correct zoom level was appended as second zoom parameter to JSONP call -> OSRM API only considers the last one! }, timeoutRoute: function() {}, drawRoute: function(response) { if(!response) return; - var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5); + + response.alternative_geometries.unshift( response.route_geometry ); + positions = OSRM.RoutingGeometry._decode( response.alternative_geometries[ OSRM.G.active_alternative ], 5 ); OSRM.G.printwindow.OSRM.drawRoute( positions ); }, From 74154ab0a65b3ca03564a6f5c4b10f491fda94df Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 4 Jul 2012 07:42:49 +0100 Subject: [PATCH 09/10] alternatives work - sort of --- WebContent/base/osrm/OSRM.Marker.js | 4 +++ WebContent/gui/OSRM.RoutingGUI.js | 8 ++++++ WebContent/routing/OSRM.Routing.js | 16 +++++------ .../routing/OSRM.RoutingAlternatives.js | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/WebContent/base/osrm/OSRM.Marker.js b/WebContent/base/osrm/OSRM.Marker.js index 7b6d402e7..79664f9f6 100644 --- a/WebContent/base/osrm/OSRM.Marker.js +++ b/WebContent/base/osrm/OSRM.Marker.js @@ -81,6 +81,8 @@ OSRM.RouteMarker = function ( label, style, position ) { OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.extend( OSRM.RouteMarker, { onClick: function(e) { + OSRM.RoutingAlternatives.reset(); + for( var i=0; i OSRM.G.alternative_count - 1 ) + OSRM.G.active_alternative = 0; + + // switch data + 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]; +}, + // prepare using alternatives prepare: function(response) { // store basic information From ba46d77d1d7cb657342d3e4c592e0a5470903efd Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Thu, 5 Jul 2012 09:24:27 +0100 Subject: [PATCH 10/10] finalized alternative integration --- WebContent/base/OSRM.Map.js | 2 +- WebContent/base/OSRM.Routes.js | 2 +- WebContent/base/osrm/OSRM.Marker.js | 4 - WebContent/gui/OSRM.MainGUI.js | 2 +- WebContent/gui/OSRM.RoutingGUI.js | 15 +-- WebContent/localization/OSRM.Localization.js | 2 +- WebContent/main.js | 3 +- WebContent/printing/OSRM.Printing.js | 2 + WebContent/routing/OSRM.Routing.js | 23 ++-- .../routing/OSRM.RoutingAlternatives.js | 108 ++++++------------ WebContent/routing/OSRM.RoutingDescription.js | 5 +- 11 files changed, 63 insertions(+), 105 deletions(-) diff --git a/WebContent/base/OSRM.Map.js b/WebContent/base/OSRM.Map.js index 414f8a01a..6deb3fd28 100644 --- a/WebContent/base/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -81,7 +81,7 @@ zoomed: function(e) { if(OSRM.G.dragging) OSRM.Routing.getRoute_Dragging(); else - OSRM.Routing.getRoute_Redraw(); + OSRM.Routing.getRoute_Redraw({keepAlternative:true}); }, contextmenu: function(e) {;}, mousemove: function(e) { OSRM.Via.drawDragMarker(e); }, diff --git a/WebContent/base/OSRM.Routes.js b/WebContent/base/OSRM.Routes.js index 48acba14d..527d0e304 100644 --- a/WebContent/base/OSRM.Routes.js +++ b/WebContent/base/OSRM.Routes.js @@ -31,7 +31,7 @@ OSRM.Route = function() { this._old_noroute_style = {dashed:true, color:'#000000', weight:2}; this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10}; this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10}; - this._alternative_route_style = {dashed:false,color:'#FF3300', weight:5}; + this._alternative_route_style = {dashed:false,color:'#770033', weight:5, opacity:0.6}; this._noroute = OSRM.Route.ROUTE; this._history = new OSRM.HistoryRoute(); diff --git a/WebContent/base/osrm/OSRM.Marker.js b/WebContent/base/osrm/OSRM.Marker.js index 79664f9f6..7b6d402e7 100644 --- a/WebContent/base/osrm/OSRM.Marker.js +++ b/WebContent/base/osrm/OSRM.Marker.js @@ -81,8 +81,6 @@ OSRM.RouteMarker = function ( label, style, position ) { OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.extend( OSRM.RouteMarker, { onClick: function(e) { - OSRM.RoutingAlternatives.reset(); - for( var i=0; i 1) - OSRM.Routing.getRoute(); + OSRM.Routing.getRoute({keepAlternative:true}); else if(OSRM.G.markers.route.length > 0 && document.getElementById('information-box').innerHTML != "" ) { OSRM.Geocoder.call( OSRM.C.SOURCE_LABEL, document.getElementById("gui-input-source").value ); OSRM.Geocoder.call( OSRM.C.TARGET_LABEL, document.getElementById("gui-input-target").value ); diff --git a/WebContent/main.js b/WebContent/main.js index 100f615f4..dc4a1ffd5 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -29,6 +29,7 @@ OSRM.init = function() { OSRM.Map.init(); OSRM.Printing.init(); OSRM.Routing.init(); + OSRM.RoutingAlternatives.init(); OSRM.Localization.init(); // stop if in maintenance mode @@ -266,7 +267,7 @@ OSRM.parseParameters = function(){ OSRM.G.active_alternative = params.active_alternative; // compute route - OSRM.Routing.getRoute(); + OSRM.Routing.getRoute({keepAlternative:true}); OSRM.G.initial_position_override = true; return; } diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index c71c167f7..212a7ea20 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -195,6 +195,8 @@ drawRoute: function(response) { return; response.alternative_geometries.unshift( response.route_geometry ); + if( OSRM.G.active_alternative >= response.alternative_geometries.length ) // no redraw if the selected alternative cannot be found + return; positions = OSRM.RoutingGeometry._decode( response.alternative_geometries[ OSRM.G.active_alternative ], 5 ); OSRM.G.printwindow.OSRM.drawRoute( positions ); }, diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index 46eb4be06..7c6014e79 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -54,9 +54,11 @@ timeoutRoute_Reversed: function() { OSRM.G.markers.reverseMarkers(); OSRM.Routing.timeoutRoute(); }, -showRoute: function(response) { +showRoute: function(response, parameters) { if(!response) return; + if(!parameters || parameters.keepAlternative == false) + OSRM.G.active_alternative = 0; OSRM.G.response = response; // needed for printing & history routes! if(response.status == 207) { @@ -65,11 +67,10 @@ showRoute: function(response) { OSRM.RoutingDescription.showNA( OSRM.loc("NO_ROUTE_FOUND") ); OSRM.Routing._snapRoute(); } else { - OSRM.RoutingAlternatives.init(OSRM.G.response); + OSRM.RoutingAlternatives.prepare(OSRM.G.response); OSRM.RoutingGeometry.show(OSRM.G.response); OSRM.RoutingNoNames.show(OSRM.G.response); OSRM.RoutingDescription.show(OSRM.G.response); - OSRM.RoutingAlternatives._drawGUI(); OSRM.Routing._snapRoute(); } OSRM.Routing._updateHints(response); @@ -93,13 +94,15 @@ showRoute_Dragging: function(response) { if(OSRM.G.pending) setTimeout(OSRM.Routing.draggingTimeout,1); }, -showRoute_Redraw: function(response) { +showRoute_Redraw: function(response, parameters) { if(!response) return; + if(!parameters || parameters.keepAlternative == false) + OSRM.G.active_alternative = 0; - OSRM.G.response = response; // not needed, even harmful as important information is not stored! ???? + OSRM.G.response = response; // not needed, even harmful as important information is not stored! ==> really ???? if(response.status != 207) { - OSRM.RoutingAlternatives.init(OSRM.G.response); + OSRM.RoutingAlternatives.prepare(OSRM.G.response); OSRM.RoutingGeometry.show(OSRM.G.response); OSRM.RoutingNoNames.show(OSRM.G.response); } @@ -110,7 +113,7 @@ showRoute_Redraw: function(response) { //-- main function -- //generate server calls to query routes -getRoute: function() { +getRoute: function(parameters) { // if source or target are not set -> hide route if( OSRM.G.markers.route.length < 2 ) { @@ -120,7 +123,7 @@ getRoute: function() { OSRM.JSONP.clear('dragging'); OSRM.JSONP.clear('redraw'); OSRM.JSONP.clear('route'); - OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route'); + OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route',parameters); }, getRoute_Reversed: function() { if( OSRM.G.markers.route.length < 2 ) @@ -131,13 +134,13 @@ getRoute_Reversed: function() { OSRM.JSONP.clear('route'); OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute_Reversed, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route'); }, -getRoute_Redraw: function() { +getRoute_Redraw: function(parameters) { if( OSRM.G.markers.route.length < 2 ) return; OSRM.JSONP.clear('dragging'); OSRM.JSONP.clear('redraw'); - OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute_Redraw, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'redraw'); + OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute_Redraw, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'redraw',parameters); }, getRoute_Dragging: function() { OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRoute_Dragging, OSRM.Routing.timeoutRoute_Dragging, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');; diff --git a/WebContent/routing/OSRM.RoutingAlternatives.js b/WebContent/routing/OSRM.RoutingAlternatives.js index 584734fa7..c608f6831 100644 --- a/WebContent/routing/OSRM.RoutingAlternatives.js +++ b/WebContent/routing/OSRM.RoutingAlternatives.js @@ -21,23 +21,20 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.RoutingAlternatives = { -// remaining problems: how to handle PRINTING (do it internally), LINKS (add parameter to JSONP call) - // data of gui buttons for alternativess _buttons: [ {id:"gui-a", label:"A"}, {id:"gui-b", label:"B"} ], - -// reset stored values -reset: function() { +// initialize required values +init: function() { OSRM.G.active_alternative = 0; OSRM.G.alternative_count = 0; }, // restructure response data -init: function(response) { +prepare: function(response) { // move best route to alternative array var the_response = OSRM.G.response; the_response.alternative_geometries.unshift( response.route_geometry ); @@ -46,9 +43,7 @@ init: function(response) { // update basic information OSRM.G.alternative_count = response.alternative_geometries.length; - if( OSRM.G.active_alternative == undefined ) - OSRM.G.active_alternative = 0; - if( OSRM.G.active_alternative > OSRM.G.alternative_count - 1 ) + if( OSRM.G.active_alternative >= OSRM.G.alternative_count ) // reset if the selected alternative cannot be found OSRM.G.active_alternative = 0; // switch data @@ -57,46 +52,6 @@ init: function(response) { the_response.route_summary = the_response.alternative_summaries[OSRM.G.active_alternative]; }, -// prepare using alternatives -prepare: function(response) { - // store basic information - OSRM.G.alternative_count = response.alternative_geometries.length + 1; - OSRM.G.active_alternative = 0; - - // do nothing if there is no alternative -// if( OSRM.G.alternative_count == 1 ) -// return; - - // move best route to alternative array - 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._drawGUI(); -}, -prepare_Redraw: function(response) { - // do nothing if there is no alternative - if( OSRM.G.alternative_count == 1 ) - return; - - // move results - var the_response = OSRM.G.response; - the_response.alternative_geometries = response.alternative_geometries; - the_response.alternative_instructions = response.alternative_instructions; - the_response.alternative_summaries = response.alternative_summaries; - - the_response.alternative_geometries.unshift( response.route_geometry ); - the_response.alternative_instructions.unshift( response.route_instructions ); - the_response.alternative_summaries.unshift( response.route_summary ); - - // switch data - 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]; -}, - // switch active alternative and redraw buttons accordingly setActive: function(button_id) { // switch active alternative @@ -110,6 +65,33 @@ setActive: function(button_id) { // do nothing for non-clickable buttons }, +//draw GUI and register click events +show: function() { + var buttons = OSRM.RoutingAlternatives._buttons; + var data = ""; + // draw clickable buttons + for(var i=0, size=OSRM.G.alternative_count; i'+buttons[i].label+'' + data; + } + // draw non-clickable buttons + for(var i=OSRM.G.alternative_count, size=buttons.length; i'+buttons[i].label+'' + data; + } + // add buttons to DOM + 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'+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