history routes work now (i hope)

This commit is contained in:
DennisSchiefer 2012-05-11 16:25:06 +01:00
parent e7b3590352
commit 14ca66459a
3 changed files with 26 additions and 13 deletions

View File

@ -57,7 +57,9 @@ OSRM.Route.ROUTE = false;
OSRM.extend( OSRM.Route,{ OSRM.extend( OSRM.Route,{
showRoute: function(positions, noroute) { showRoute: function(positions, noroute) {
// this.showHistoryRoutes(); this.fetchHistoryRoute();
this.showHistoryRoutes();
this._noroute = noroute; this._noroute = noroute;
this._current_route.setPositions( positions ); this._current_route.setPositions( positions );
if ( this._noroute == OSRM.Route.NOROUTE ) if ( this._noroute == OSRM.Route.NOROUTE )
@ -68,10 +70,11 @@ OSRM.extend( OSRM.Route,{
//this._raiseUnnamedRoute(); //this._raiseUnnamedRoute();
}, },
hideRoute: function() { hideRoute: function() {
// this.fetchHistoryRoute();
// this.showHistoryRoutes();
this._current_route.hide(); this._current_route.hide();
this._unnamed_route.hide(); this._unnamed_route.hide();
this.fetchHistoryRoute();
this.showHistoryRoutes();
// deactivate printing // deactivate printing
OSRM.Printing.deactivate(); OSRM.Printing.deactivate();
}, },
@ -79,7 +82,7 @@ OSRM.extend( OSRM.Route,{
this.hideRoute(); this.hideRoute();
this._old_route.hide(); this._old_route.hide();
this._noroute = OSRM.Route.ROUTE; this._noroute = OSRM.Route.ROUTE;
// this.clearHistoryRoutes(); this.clearHistoryRoutes();
}, },
showUnnamedRoute: function(positions) { showUnnamedRoute: function(positions) {
@ -138,9 +141,8 @@ OSRM.extend( OSRM.Route,{
storeHistoryRoute: function() { storeHistoryRoute: function() {
if( document.getElementById('option-show-previous-routes').checked == false) if( document.getElementById('option-show-previous-routes').checked == false)
return; return;
console.log("store");
this.fetchHistoryRoute();
if(this.isShown() && this.isRoute()) { if(this.isShown() && this.isRoute()) {
console.log("store");
// store new route and positions in staging spot // store new route and positions in staging spot
this._history_route[0].setPositions( this._current_route.getPositions() ); this._history_route[0].setPositions( this._current_route.getPositions() );
this._history_data[0] = []; this._history_data[0] = [];
@ -176,6 +178,8 @@ OSRM.extend( OSRM.Route,{
return; return;
if( this._history_data[0].length == 0) if( this._history_data[0].length == 0)
return; return;
if( this._equalRoute() )
return;
console.log("fetch"); console.log("fetch");
// move route and positions // move route and positions
for(var i=this._history_routes-1; i>0; i--) { for(var i=this._history_routes-1; i>0; i--) {
@ -185,5 +189,14 @@ OSRM.extend( OSRM.Route,{
// reset staging spot // reset staging spot
this._history_route[0].setPositions( [] ); this._history_route[0].setPositions( [] );
this._history_data[0] = []; this._history_data[0] = [];
},
_equalRoute: function() {
var lhs = OSRM.G.markers.route;
var rhs = this._history_data[0];
for(var i=0,size=Math.min(rhs.length,lhs.length); i<size; i++) {
if( lhs[i].getLat() != rhs[i].lat || lhs[i].getLng() != rhs[i].lng)
return false;
}
return true;
} }
}); });

View File

@ -140,10 +140,10 @@ deleteMarker: function(marker_id) {
//click: checkbox "show previous routes" //click: checkbox "show previous routes"
showPreviousRoutes: function(value) { showPreviousRoutes: function(value) {
// if( document.getElementById('option-show-previous-routes').checked == false) if( document.getElementById('option-show-previous-routes').checked == false)
// OSRM.G.route.clearHistoryRoutes(); OSRM.G.route.clearHistoryRoutes();
// else else
// OSRM.G.route.storeHistoryRoute(); OSRM.G.route.storeHistoryRoute();
} }
}); });

View File

@ -65,7 +65,7 @@ showRouteSimple: function(response) {
} else { } else {
OSRM.RoutingGeometry.show(response); OSRM.RoutingGeometry.show(response);
OSRM.RoutingDescription.showSimple(response); OSRM.RoutingDescription.showSimple(response);
// OSRM.G.route.storeHistoryRoute(); OSRM.G.route.storeHistoryRoute();
} }
OSRM.Routing._updateHints(response); OSRM.Routing._updateHints(response);
@ -88,7 +88,7 @@ showRoute: function(response) {
OSRM.RoutingNoNames.show(response); OSRM.RoutingNoNames.show(response);
OSRM.RoutingDescription.show(response); OSRM.RoutingDescription.show(response);
OSRM.Routing._snapRoute(); OSRM.Routing._snapRoute();
// OSRM.G.route.storeHistoryRoute(); OSRM.G.route.storeHistoryRoute();
} }
OSRM.Routing._updateHints(response); OSRM.Routing._updateHints(response);
}, },