more alternative stuff
This commit is contained in:
parent
59775a9864
commit
badd48f166
@ -19,7 +19,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
// [has to be loaded directly after OSRM.base]
|
// [has to be loaded directly after OSRM.base]
|
||||||
|
|
||||||
OSRM.DEFAULTS = {
|
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_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
|
||||||
HOST_TIMESTAMP_URL: 'http://router.project-osrm.org/timestamp',
|
HOST_TIMESTAMP_URL: 'http://router.project-osrm.org/timestamp',
|
||||||
HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
|
HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
|
||||||
|
@ -539,7 +539,7 @@ html, body {
|
|||||||
border-radius:5px;
|
border-radius:5px;
|
||||||
-moz-border-radius:5px;
|
-moz-border-radius:5px;
|
||||||
-webkit-border-radius:5px;
|
-webkit-border-radius:5px;
|
||||||
background-color:#DDDDDD;
|
background-color:#AAAAAA;
|
||||||
border:1px solid #999999;
|
border:1px solid #999999;
|
||||||
color:#000000;
|
color:#000000;
|
||||||
text-decoration:none;
|
text-decoration:none;
|
||||||
|
@ -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.Selector.js" type="text/javascript"></script>
|
||||||
<script src="gui/OSRM.MainGUI.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.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.RoutingDescription.js" type="text/javascript"></script>
|
||||||
<script src="routing/OSRM.RoutingGeometry.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>
|
<script src="gui/OSRM.RoutingGUI.js" type="text/javascript"></script>
|
||||||
|
@ -23,19 +23,32 @@ OSRM.RoutingAlternatives = {
|
|||||||
|
|
||||||
// remaining problems: how to handle PRINTING (do it internally), LINKS (add parameter to JSONP call)
|
// remaining problems: how to handle PRINTING (do it internally), LINKS (add parameter to JSONP call)
|
||||||
|
|
||||||
// name of gui buttons to choose alternatives
|
// data of gui buttons for alternativess
|
||||||
_buttons: ["gui_a", "gui_b"],
|
_buttons: [
|
||||||
|
{id:"gui-a", label:"A"},
|
||||||
// prepare response
|
{id:"gui-b", label:"B"},
|
||||||
|
{id:"gui-c", label:"C"},
|
||||||
|
{id:"gui-d", label:"D"}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
// prepare using alternatives
|
||||||
prepare: function(response) {
|
prepare: function(response) {
|
||||||
var original = {};
|
// store basic information
|
||||||
original.route_geometry = response.route_geometry;
|
OSRM.G.alternative_count = response.alternative_geometries.length;
|
||||||
original.route_instructions = response.route_instructions;
|
OSRM.G.alternative_active = 0;
|
||||||
original.route_summary = response.route_summary;
|
|
||||||
OSRM.G.response.alternatives.push( original );
|
|
||||||
|
|
||||||
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();
|
OSRM.RoutingAlternatives._addGUI();
|
||||||
},
|
},
|
||||||
prepare_Redraw: function(response) {
|
prepare_Redraw: function(response) {
|
||||||
@ -51,57 +64,65 @@ prepare_Redraw: function(response) {
|
|||||||
|
|
||||||
// press one of the buttons
|
// press one of the buttons
|
||||||
press: function(button_id) {
|
press: function(button_id) {
|
||||||
|
// switch active alternative
|
||||||
|
OSRM.G.alternative_active = button_id;
|
||||||
|
|
||||||
|
// redraw buttons
|
||||||
var buttons = OSRM.RoutingAlternatives._buttons;
|
var buttons = OSRM.RoutingAlternatives._buttons;
|
||||||
for(var i=0, size=buttons; i<size; i++) {
|
for(var i=0, size=OSRM.G.alternative_count; i<size; i++) {
|
||||||
if(button_id == i)
|
document.getElementById( buttons[i].id ).className = (button_id == i) ? "button-pressed top-right-button" : "button top-right-button";
|
||||||
document.getElementById( buttons[i] ).className = "button-pressed top-right-button";
|
|
||||||
else
|
|
||||||
document.getElementById( buttons[i] ).className = "button top-right-button";
|
|
||||||
}
|
}
|
||||||
OSRM.G.response.active_alternative = button_id;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// mouse events on buttons
|
// mouse events on buttons
|
||||||
_click: function(button_id) {
|
_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;
|
return;
|
||||||
OSRM.RoutingAlternatives.press(button_id);
|
OSRM.RoutingAlternatives.press(button_id);
|
||||||
OSRM.G.route.hideAlternativeRoute();
|
OSRM.G.route.hideAlternativeRoute();
|
||||||
|
|
||||||
// switch data
|
// switch data
|
||||||
//OSRM.Routing.showRoute(OSRM.G.response);
|
var the_response = OSRM.G.response;
|
||||||
console.log("click "+button_id);
|
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) {
|
_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;
|
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);
|
OSRM.G.route.showAlternativeRoute(geometry);
|
||||||
console.log("over "+button_id);
|
|
||||||
},
|
},
|
||||||
_mouseout: function(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;
|
return;
|
||||||
|
|
||||||
OSRM.G.route.hideAlternativeRoute();
|
OSRM.G.route.hideAlternativeRoute();
|
||||||
console.log("out "+button_id);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// add alternatives
|
// add alternatives
|
||||||
_addGUI: function() {
|
_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;
|
var buttons = OSRM.RoutingAlternatives._buttons;
|
||||||
for(var i=0, size=buttons; i<size; i++) {
|
for(var i=0, size=OSRM.G.alternative_count; i<size; i++) {
|
||||||
document.getElementById(buttons[i]).onclick = function () { OSRM.RoutingAlternatives._click(i); };
|
var distance = OSRM.Utils.toHumanDistance(OSRM.G.response.alternative_summaries[i].total_distance);
|
||||||
document.getElementById(buttons[i]).onmouseover = function () { OSRM.RoutingAlternatives._mouseover(i); };
|
var time = OSRM.Utils.toHumanTime(OSRM.G.response.alternative_summaries[i].total_time);
|
||||||
document.getElementById(buttons[i]).onmouseout = function () { OSRM.RoutingAlternatives._mouseout(i); };
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user