added waiting message to route reversal,

moved reversal logic to OSRM.Markers
This commit is contained in:
DennisSchiefer 2012-04-19 09:48:32 +01:00
parent 5a9a55544b
commit 2e60e92b31
2 changed files with 38 additions and 33 deletions

View File

@ -236,6 +236,38 @@ removeMarker: function(id) {
this.route[id].hide();
this.route.splice(id, 1);
},
reverseMarkers: function() {
var size = this.route.length;
// invert route, if a route is shown
if( size > 1 ) {
// switch positions in nodes
var temp_position = this.route[0].getPosition();
this.route[0].setPosition( this.route[size-1].getPosition() );
OSRM.G.markers.route[size-1].setPosition( temp_position );
// switch nodes in array
var temp_node = OSRM.G.markers.route[0];
OSRM.G.markers.route[0] = OSRM.G.markers.route[size-1];
OSRM.G.markers.route[size-1] = temp_node;
// reverse route
OSRM.G.markers.route.reverse();
// clear information (both delete markers stay visible)
document.getElementById('information-box').innerHTML = "";
document.getElementById('information-box-header').innerHTML = "";
// invert marker, if only one marker is shown (implicit clear of information / delete markers)
} else if( size > 0 ) {
var position = this.route[0].getPosition();
var label = this.route[0].label;
this.removeMarker(0);
if( label == OSRM.C.TARGET_LABEL )
this.setSource( position );
else if( label == OSRM.C.SOURCE_LABEL )
this.setTarget( position );
this.route[0].show();
}
},
hasSource: function() {
if( OSRM.G.markers.route[0] && OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL )
return true;

View File

@ -42,43 +42,16 @@ reverseRouting: function() {
var tmp = document.getElementById("gui-input-source").value;
document.getElementById("gui-input-source").value = document.getElementById("gui-input-target").value;
document.getElementById("gui-input-target").value = tmp;
// invert route, if a route is shown
// reverse markers
OSRM.G.markers.reverseMarkers();
// recompute route if needed
if( OSRM.G.route.isShown() ) {
// switch positions in nodes
var temp_position = OSRM.G.markers.route[0].getPosition();
OSRM.G.markers.route[0].setPosition( OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition() );
OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( temp_position );
// switch nodes in array
var temp_node = OSRM.G.markers.route[0];
OSRM.G.markers.route[0] = OSRM.G.markers.route[OSRM.G.markers.route.length-1];
OSRM.G.markers.route[OSRM.G.markers.route.length-1] = temp_node;
// reverse route
OSRM.G.markers.route.reverse();
// query new route
OSRM.Routing.getRoute();
OSRM.G.markers.highlight.hide();
// invert marker, if only one marker is shown
} else if( OSRM.G.markers.route.length > 0 ) {
// requery geocoder, if geocoding results were shown
if( 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 );
}
// switch single node
if( OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL ) {
OSRM.G.markers.setSource( OSRM.G.markers.route[0].getPosition() );
OSRM.G.markers.removeMarker(1);
OSRM.G.markers.route[0].show();
} else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
OSRM.G.markers.setTarget( OSRM.G.markers.route[0].getPosition() );
OSRM.G.markers.removeMarker(0);
OSRM.G.markers.route[0].show();
}
OSRM.RoutingDescription.showSimple( OSRM.G.response );
}
// otherwise do nothing
},
// click: button "show"