more alternative stuff

This commit is contained in:
shiin 2012-06-20 22:08:25 +02:00
parent 59775a9864
commit badd48f166
4 changed files with 61 additions and 39 deletions

View File

@ -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',

View File

@ -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;

View File

@ -65,6 +65,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
<script src="gui/OSRM.Selector.js" type="text/javascript"></script>
<script src="gui/OSRM.MainGUI.js" type="text/javascript"></script>
<script src="routing/OSRM.Routing.js" type="text/javascript"></script>
<script src="routing/OSRM.RoutingAlternatives.js" type="text/javascript"></script>
<script src="routing/OSRM.RoutingDescription.js" type="text/javascript"></script>
<script src="routing/OSRM.RoutingGeometry.js" type="text/javascript"></script>
<script src="gui/OSRM.RoutingGUI.js" type="text/javascript"></script>

View File

@ -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; i<size; i++) {
if(button_id == i)
document.getElementById( buttons[i] ).className = "button-pressed top-right-button";
else
document.getElementById( buttons[i] ).className = "button top-right-button";
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";
}
OSRM.G.response.active_alternative = button_id;
},
// mouse events on buttons
_click: function(button_id) {
if( OSRM.G.response.active_alternative == button_id )
console.log("click "+button_id);
if( OSRM.G.alternative_active == button_id )
return;
OSRM.RoutingAlternatives.press(button_id);
OSRM.G.route.hideAlternativeRoute();
// switch data
//OSRM.Routing.showRoute(OSRM.G.response);
console.log("click "+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];
// show alternative
OSRM.RoutingGeometry.show(the_response);
OSRM.RoutingNoNames.show(the_response);
OSRM.RoutingDescription.show(the_response);
},
_mouseover: function(button_id) {
if( OSRM.G.response.active_alternative == button_id )
console.log("over "+button_id);
if( OSRM.G.alternative_active == button_id )
return;
var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5);
var geometry = OSRM.RoutingGeometry._decode( OSRM.G.response.alternative_geometries[button_id], 5);
OSRM.G.route.showAlternativeRoute(geometry);
console.log("over "+button_id);
},
_mouseout: function(button_id) {
if( OSRM.G.response.active_alternative == button_id )
console.log("out "+button_id);
if( OSRM.G.alternative_active == button_id )
return;
OSRM.G.route.hideAlternativeRoute();
console.log("out "+button_id);
OSRM.G.route.hideAlternativeRoute();
},
// add alternatives
_addGUI: function() {
var data =
'<a class="button top-right-button" id="gui-b">B</a>' +
'<a class="button top-right-button" id="gui-a">A</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<size; i++) {
document.getElementById(buttons[i]).onclick = function () { OSRM.RoutingAlternatives._click(i); };
document.getElementById(buttons[i]).onmouseover = function () { OSRM.RoutingAlternatives._mouseover(i); };
document.getElementById(buttons[i]).onmouseout = function () { OSRM.RoutingAlternatives._mouseout(i); };
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 data = '<a class="button top-right-button" id="'+buttons[i].id+'" title="'+tooltip+'">'+buttons[i].label+'</a>';
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 );
}
};