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