alternatives work - sort of

This commit is contained in:
DennisSchiefer 2012-07-04 07:42:49 +01:00
parent c33dbe67d8
commit 74154ab0a6
4 changed files with 47 additions and 8 deletions

View File

@ -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.markers.route.length; i++) {
if( OSRM.G.markers.route[i].marker === this ) {
OSRM.G.markers.removeMarker( i );
@ -102,6 +104,8 @@ onDragStart: function(e) {
OSRM.G.dragging = true;
this.switchIcon(this.options.dragicon);
OSRM.RoutingAlternatives.reset();
// store id of dragged marker
for( var i=0; i<OSRM.G.markers.route.length; i++)
if( OSRM.G.markers.route[i].marker === this ) {

View File

@ -59,6 +59,8 @@ resetRouting: function() {
document.getElementById('gui-input-source').value = "";
document.getElementById('gui-input-target').value = "";
OSRM.RoutingAlternatives.reset();
OSRM.G.route.reset();
OSRM.G.markers.reset();
@ -75,6 +77,8 @@ reverseRouting: function() {
document.getElementById("gui-input-source").value = document.getElementById("gui-input-target").value;
document.getElementById("gui-input-target").value = tmp;
OSRM.RoutingAlternatives.reset();
// recompute route if needed
if( OSRM.G.route.isShown() ) {
OSRM.G.markers.route.reverse();
@ -102,6 +106,8 @@ showMarker: function(marker_id) {
// changed: any inputbox (is called when enter is pressed [after] or focus is lost [before])
inputChanged: function(marker_id) {
OSRM.RoutingAlternatives.reset();
if( marker_id == OSRM.C.SOURCE_LABEL)
OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('gui-input-source').value);
else if( marker_id == OSRM.C.TARGET_LABEL)
@ -144,6 +150,8 @@ deleteMarker: function(marker_id) {
if( id == null)
return;
OSRM.RoutingAlternatives.reset();
OSRM.G.markers.removeMarker( id );
OSRM.Routing.getRoute();
OSRM.G.markers.highlight.hide();

View File

@ -65,10 +65,11 @@ showRoute: function(response) {
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(response);
OSRM.RoutingAlternatives.init(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);
@ -96,12 +97,11 @@ showRoute_Redraw: function(response) {
if(!response)
return;
//OSRM.G.response = response; // not needed, even harmful as important information is not stored!
//OSRM.RoutingAlternatives.prepare_Redraw(response);
OSRM.G.response = response; // not needed, even harmful as important information is not stored! ????
if(response.status != 207) {
OSRM.RoutingAlternatives.prepare_Redraw(response);
OSRM.RoutingAlternatives.init(OSRM.G.response);
OSRM.RoutingGeometry.show(OSRM.G.response);
OSRM.RoutingNoNames.show(OSRM.Gresponse);
OSRM.RoutingNoNames.show(OSRM.G.response);
}
OSRM.Routing._updateHints(response);
},

View File

@ -30,6 +30,33 @@ _buttons: [
],
// reset stored values
reset: function() {
OSRM.G.active_alternative = 0;
OSRM.G.alternative_count = 0;
},
// restructure response data
init: 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 == undefined )
OSRM.G.active_alternative = 0;
if( OSRM.G.active_alternative > 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