Merge branch 'trial/alternatives' into develop
Conflicts: WebContent/routing/OSRM.Routing.js
This commit is contained in:
@@ -57,6 +57,8 @@ timeoutRoute_Reversed: function() {
|
||||
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,9 +67,10 @@ showRoute: function(response, parameters) {
|
||||
OSRM.RoutingDescription.showNA( OSRM.loc("NO_ROUTE_FOUND") );
|
||||
OSRM.Routing._snapRoute();
|
||||
} else {
|
||||
OSRM.RoutingGeometry.show(response);
|
||||
OSRM.RoutingNoNames.show(response);
|
||||
OSRM.RoutingDescription.show(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.Routing._snapRoute();
|
||||
}
|
||||
OSRM.Routing._updateHints(response);
|
||||
@@ -95,14 +98,17 @@ 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.RoutingGeometry.show(response);
|
||||
OSRM.RoutingNoNames.show(response);
|
||||
OSRM.RoutingAlternatives.prepare(OSRM.G.response);
|
||||
OSRM.RoutingGeometry.show(OSRM.G.response);
|
||||
OSRM.RoutingNoNames.show(OSRM.G.response);
|
||||
}
|
||||
OSRM.Routing._updateHints(response);
|
||||
},
|
||||
@@ -132,13 +138,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');;
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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 = {
|
||||
|
||||
// data of gui buttons for alternativess
|
||||
_buttons: [
|
||||
{id:"gui-a", label:"A"},
|
||||
{id:"gui-b", label:"B"}
|
||||
],
|
||||
|
||||
// initialize required values
|
||||
init: function() {
|
||||
OSRM.G.active_alternative = 0;
|
||||
OSRM.G.alternative_count = 0;
|
||||
},
|
||||
|
||||
// restructure response data
|
||||
prepare: function(response) {
|
||||
// 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 );
|
||||
|
||||
// update basic information
|
||||
OSRM.G.alternative_count = response.alternative_geometries.length;
|
||||
if( OSRM.G.active_alternative >= OSRM.G.alternative_count ) // reset if the selected alternative cannot be found
|
||||
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];
|
||||
},
|
||||
|
||||
// switch active alternative and redraw buttons accordingly
|
||||
setActive: function(button_id) {
|
||||
// switch active alternative
|
||||
OSRM.G.active_alternative = button_id;
|
||||
|
||||
// redraw clickable buttons
|
||||
var buttons = OSRM.RoutingAlternatives._buttons;
|
||||
for(var i=0, size=OSRM.G.alternative_count; i<size; i++) {
|
||||
document.getElementById( buttons[i].id ).className = (button_id == i) ? "button-pressed top-right-button" : "button top-right-button";
|
||||
}
|
||||
// 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<size; i++) {
|
||||
var distance = OSRM.Utils.toHumanDistance(OSRM.G.response.alternative_summaries[i].total_distance);
|
||||
var time = OSRM.Utils.toHumanTime(OSRM.G.response.alternative_summaries[i].total_time);
|
||||
var tooltip = OSRM.loc("DISTANCE")+":"+distance+" "+OSRM.loc("DURATION")+":"+time;
|
||||
var buttonClass = (i == OSRM.G.active_alternative) ? "button-pressed" : "button";
|
||||
data = '<a class="'+buttonClass+' top-right-button" id="'+buttons[i].id+'" title="'+tooltip+'">'+buttons[i].label+'</a>' + data;
|
||||
}
|
||||
// draw non-clickable buttons
|
||||
for(var i=OSRM.G.alternative_count, size=buttons.length; i<size; ++i) {
|
||||
data = '<a class="button-inactive top-right-button" id="'+buttons[i].id+'">'+buttons[i].label+'</a>' + 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<size; i++) {
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
// mouse events on buttons
|
||||
_click: function(button_id) {
|
||||
if( OSRM.G.active_alternative == button_id )
|
||||
return;
|
||||
OSRM.RoutingAlternatives.setActive(button_id);
|
||||
OSRM.G.route.hideAlternativeRoute();
|
||||
|
||||
// switch data
|
||||
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.route_summary = the_response.alternative_summaries[button_id];
|
||||
|
||||
// redraw route & data
|
||||
OSRM.RoutingGeometry.show(the_response);
|
||||
OSRM.RoutingNoNames.show(the_response);
|
||||
OSRM.RoutingDescription.show(the_response);
|
||||
},
|
||||
_mouseover: function(button_id) {
|
||||
if( OSRM.G.active_alternative == button_id )
|
||||
return;
|
||||
|
||||
var geometry = OSRM.RoutingGeometry._decode( OSRM.G.response.alternative_geometries[button_id], 5);
|
||||
OSRM.G.route.showAlternativeRoute(geometry);
|
||||
},
|
||||
_mouseout: function(button_id) {
|
||||
if( OSRM.G.active_alternative == button_id )
|
||||
return;
|
||||
|
||||
OSRM.G.route.hideAlternativeRoute();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -29,6 +29,7 @@ onClickRouteDescription: function(lat, lng) {
|
||||
},
|
||||
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;
|
||||
|
||||
var source = OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, OSRM.DEFAULTS.HOST_SHORTENER_URL+src);
|
||||
@@ -100,11 +101,14 @@ show: function(response) {
|
||||
body += '</table>';
|
||||
|
||||
// build header
|
||||
header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.toHumanDistance(response.route_summary.total_distance), OSRM.Utils.toHumanTime(response.route_summary.total_time), route_link, gpx_link);
|
||||
header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.toHumanDistance(response.route_summary.total_distance), OSRM.Utils.toHumanTime(response.route_summary.total_time), route_link, gpx_link);
|
||||
|
||||
// update DOM
|
||||
document.getElementById('information-box-header').innerHTML = header;
|
||||
document.getElementById('information-box').innerHTML = body;
|
||||
|
||||
// add alternative GUI (has to be done last since DOM has to be updated before events are registered)
|
||||
OSRM.RoutingAlternatives.show();
|
||||
},
|
||||
|
||||
// simple description
|
||||
|
||||
Reference in New Issue
Block a user