work on history routes
This commit is contained in:
		
							parent
							
								
									47b2268504
								
							
						
					
					
						commit
						85ea79701c
					
				| @ -30,6 +30,8 @@ OSRM.Route = function() { | |||||||
| 	this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10}; | 	this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10}; | ||||||
| 	this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10}; | 	this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10}; | ||||||
| 	 | 	 | ||||||
|  | 	this._noroute = OSRM.Route.ROUTE;	 | ||||||
|  | 	 | ||||||
| 	this._route_history_styles = [{dashed:false, color:'#FF0000', weight:5}, | 	this._route_history_styles = [{dashed:false, color:'#FF0000', weight:5}, | ||||||
| 	                              {dashed:false, color:'#00FF00', weight:5}, | 	                              {dashed:false, color:'#00FF00', weight:5}, | ||||||
| 	                              {dashed:false, color:'#0000FF', weight:5}, | 	                              {dashed:false, color:'#0000FF', weight:5}, | ||||||
| @ -41,31 +43,16 @@ OSRM.Route = function() { | |||||||
| 	                              {dashed:false, color:'#770077', weight:5}, | 	                              {dashed:false, color:'#770077', weight:5}, | ||||||
| 	                              {dashed:false, color:'#007777', weight:5}	                               | 	                              {dashed:false, color:'#007777', weight:5}	                               | ||||||
| 	                              ]; | 	                              ]; | ||||||
| 	this._route_history = [ new OSRM.SimpleRoute("current" , {dashed:false} ), | 	this._route_history = []; | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), | 	for(var i=0, size=this._route_history_styles.length; i<size; i++) | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), | 		this._route_history.push( new OSRM.SimpleRoute("current" , {dashed:false} ) ); | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ), |  | ||||||
| 	                        new OSRM.SimpleRoute("current" , {dashed:false} ) ]; |  | ||||||
| 	this._route_history_count = 0; |  | ||||||
| 	 |  | ||||||
| 	this._noroute = OSRM.Route.ROUTE; |  | ||||||
| }; | }; | ||||||
| OSRM.Route.NOROUTE = true; | OSRM.Route.NOROUTE = true; | ||||||
| OSRM.Route.ROUTE = false; | OSRM.Route.ROUTE = false; | ||||||
| OSRM.extend( OSRM.Route,{ | OSRM.extend( OSRM.Route,{ | ||||||
| 	 | 	 | ||||||
| 	showRoute: function(positions, noroute) { | 	showRoute: function(positions, noroute) { | ||||||
| 		if( document.getElementById('option-show-previous-routes').checked == true) { | 		this.showHistoryRoutes(); | ||||||
| 			for(var i=0,size=this._route_history.length; i<size; i++) { |  | ||||||
| 				this._route_history[i].setStyle( this._route_history_styles[i] ); |  | ||||||
| 				this._route_history[i].show(); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		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 ) | ||||||
| @ -74,22 +61,9 @@ OSRM.extend( OSRM.Route,{ | |||||||
| 			this._current_route.setStyle( this._current_route_style ); | 			this._current_route.setStyle( this._current_route_style ); | ||||||
| 		this._current_route.show(); | 		this._current_route.show(); | ||||||
| 		//this._raiseUnnamedRoute();
 | 		//this._raiseUnnamedRoute();
 | ||||||
| 		 |  | ||||||
| //		if( document.getElementById('option-show-previous-routes').checked == true) {
 |  | ||||||
| //			if(this._noroute != OSRM.Route.NOROUTE) {
 |  | ||||||
| //				for(var i=4; i>0; i--)
 |  | ||||||
| //					this._route_history[i].setPositions( this._route_history[i-1].getPositions() );
 |  | ||||||
| //				this._route_history[0].setPositions( this._current_route.getPositions() );
 |  | ||||||
| //			}
 |  | ||||||
| //		}
 |  | ||||||
| 	}, | 	}, | ||||||
| 	hideRoute: function() { | 	hideRoute: function() { | ||||||
| 		if( document.getElementById('option-show-previous-routes').checked == true) { | 		this.showHistoryRoutes();		 | ||||||
| 			for(var i=0,size=this._route_history.length; i<size; i++) { |  | ||||||
| 				this._route_history[i].setStyle( this._route_history_styles[i] ); |  | ||||||
| 				this._route_history[i].show(); |  | ||||||
| 			} |  | ||||||
| 		}		 |  | ||||||
| 		this._current_route.hide(); | 		this._current_route.hide(); | ||||||
| 		this._unnamed_route.hide(); | 		this._unnamed_route.hide(); | ||||||
| 		// deactivate printing
 | 		// deactivate printing
 | ||||||
| @ -101,11 +75,6 @@ OSRM.extend( OSRM.Route,{ | |||||||
| 		this._noroute = OSRM.Route.ROUTE; | 		this._noroute = OSRM.Route.ROUTE; | ||||||
| 		this.clearHistoryRoutes(); | 		this.clearHistoryRoutes(); | ||||||
| 	}, | 	}, | ||||||
| 	clearHistoryRoutes: function() { |  | ||||||
| 		for(var i=0,size=this._route_history.length; i<size; i++) |  | ||||||
| 			this._route_history[i].hide(); |  | ||||||
| 		this._route_history = []; |  | ||||||
| 	}, |  | ||||||
| 	 | 	 | ||||||
| 	showUnnamedRoute: function(positions) { | 	showUnnamedRoute: function(positions) { | ||||||
| 		this._unnamed_route.clearRoutes(); | 		this._unnamed_route.clearRoutes(); | ||||||
| @ -157,5 +126,30 @@ OSRM.extend( OSRM.Route,{ | |||||||
| 	}, | 	}, | ||||||
| 	centerView: function() { | 	centerView: function() { | ||||||
| 		this._current_route.centerView(); | 		this._current_route.centerView(); | ||||||
|  | 	}, | ||||||
|  | 	 | ||||||
|  | 	// history route handling
 | ||||||
|  | 	storeHistoryRoute: function() { | ||||||
|  | 		if( document.getElementById('option-show-previous-routes').checked == false) | ||||||
|  | 			return; | ||||||
|  | 		if(this.isShown() && this.isRoute()) { | ||||||
|  | 			for(var i=this._route_history.length-1; i>0; i--) | ||||||
|  | 				this._route_history[i].setPositions( this._route_history[i-1].getPositions() ); | ||||||
|  | 			this._route_history[0].setPositions( this._current_route.getPositions() ); | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | 	showHistoryRoutes: function() { | ||||||
|  | 		if( document.getElementById('option-show-previous-routes').checked == false) | ||||||
|  | 			return; | ||||||
|  | 		for(var i=1,size=this._route_history.length; i<size; i++) { | ||||||
|  | 			this._route_history[i].setStyle( this._route_history_styles[i] ); | ||||||
|  | 			this._route_history[i].show(); | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | 	clearHistoryRoutes: function() { | ||||||
|  | 		for(var i=0,size=this._route_history.length; i<size; i++) { | ||||||
|  | 			this._route_history[i].hide(); | ||||||
|  | 			this._route_history[i].setPositions( [] ); | ||||||
|  | 		} | ||||||
| 	}	 | 	}	 | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -65,16 +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(); | ||||||
| 		// store history route
 |  | ||||||
| 		var route = OSRM.G.route; |  | ||||||
| 		if( document.getElementById('option-show-previous-routes').checked == true) { |  | ||||||
| 			if(route._noroute != OSRM.Route.NOROUTE) { |  | ||||||
| 				for(var i=route._route_history.length-1; i>0; i--) |  | ||||||
| 					route._route_history[i].setPositions( route._route_history[i-1].getPositions() ); |  | ||||||
| 				route._route_history[0].setPositions( route._current_route.getPositions() ); |  | ||||||
| 			} |  | ||||||
| 		}		 |  | ||||||
| 	} | 	} | ||||||
| 	OSRM.Routing._updateHints(response); | 	OSRM.Routing._updateHints(response); | ||||||
| 
 | 
 | ||||||
| @ -97,6 +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.Routing._updateHints(response); | 	OSRM.Routing._updateHints(response); | ||||||
| }, | }, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user