complete restructure of OSRM.Routing
This commit is contained in:
		
							parent
							
								
									2bb51717b9
								
							
						
					
					
						commit
						fd3cf02af4
					
				@ -60,7 +60,7 @@ _onclickResult: function(marker_id, lat, lon) {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	OSRM.G.markers.route[index].show();
 | 
						OSRM.G.markers.route[index].show();
 | 
				
			||||||
	OSRM.G.markers.route[index].centerView();	
 | 
						OSRM.G.markers.route[index].centerView();	
 | 
				
			||||||
	OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
 | 
						OSRM.Routing.getRoute();
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -122,7 +122,7 @@ init: function() {
 | 
				
			|||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// map event handlers
 | 
					// map event handlers
 | 
				
			||||||
zoomed: function(e) { OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); },
 | 
					zoomed: function(e) { OSRM.Routing.getRoute(); },
 | 
				
			||||||
contextmenu: function(e) {;},
 | 
					contextmenu: function(e) {;},
 | 
				
			||||||
mousemove: function(e) {;},
 | 
					mousemove: function(e) {;},
 | 
				
			||||||
click: function(e) {
 | 
					click: function(e) {
 | 
				
			||||||
@ -131,13 +131,13 @@ click: function(e) {
 | 
				
			|||||||
		OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
 | 
							OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
 | 
				
			||||||
		OSRM.G.markers.route[index].show();
 | 
							OSRM.G.markers.route[index].show();
 | 
				
			||||||
		OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
 | 
							OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
 | 
				
			||||||
		OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION );
 | 
							OSRM.Routing.getRoute();
 | 
				
			||||||
	} else if( !OSRM.G.markers.hasTarget() ) {
 | 
						} else if( !OSRM.G.markers.hasTarget() ) {
 | 
				
			||||||
		var index = OSRM.G.markers.setTarget( e.latlng );
 | 
							var index = OSRM.G.markers.setTarget( e.latlng );
 | 
				
			||||||
		OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
 | 
							OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
 | 
				
			||||||
		OSRM.G.markers.route[index].show();
 | 
							OSRM.G.markers.route[index].show();
 | 
				
			||||||
		OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
 | 
							OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
 | 
				
			||||||
		OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION );
 | 
							OSRM.Routing.getRoute();
 | 
				
			||||||
	}	
 | 
						}	
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -105,12 +105,13 @@ onClick: function(e) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
 | 
						OSRM.Routing.getRoute();
 | 
				
			||||||
	OSRM.G.markers.highlight.hide();
 | 
						OSRM.G.markers.highlight.hide();
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
onDrag: function(e) {
 | 
					onDrag: function(e) {
 | 
				
			||||||
	this.parent.setPosition( e.target.getLatLng() );
 | 
						this.parent.setPosition( e.target.getLatLng() );
 | 
				
			||||||
	OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION);
 | 
						if(OSRM.G.markers.route.length>1)
 | 
				
			||||||
 | 
							OSRM.Routing.getDragRoute();
 | 
				
			||||||
	OSRM.Geocoder.updateLocation( this.parent.label );
 | 
						OSRM.Geocoder.updateLocation( this.parent.label );
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
onDragStart: function(e) {
 | 
					onDragStart: function(e) {
 | 
				
			||||||
@ -130,7 +131,7 @@ onDragStart: function(e) {
 | 
				
			|||||||
onDragEnd: function(e) {
 | 
					onDragEnd: function(e) {
 | 
				
			||||||
	OSRM.G.dragging = false;
 | 
						OSRM.G.dragging = false;
 | 
				
			||||||
	this.parent.setPosition( e.target.getLatLng() );	
 | 
						this.parent.setPosition( e.target.getLatLng() );	
 | 
				
			||||||
	OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
 | 
						OSRM.Routing.getRoute();
 | 
				
			||||||
	if (OSRM.G.route.isShown()) {
 | 
						if (OSRM.G.route.isShown()) {
 | 
				
			||||||
		OSRM.G.route.hideOldRoute();
 | 
							OSRM.G.route.hideOldRoute();
 | 
				
			||||||
		OSRM.G.route.hideUnnamedRoute();
 | 
							OSRM.G.route.hideUnnamedRoute();
 | 
				
			||||||
 | 
				
			|||||||
@ -70,13 +70,13 @@ showRouteSimple: function(response) {
 | 
				
			|||||||
		OSRM.Routing.showRouteGeometry(response);
 | 
							OSRM.Routing.showRouteGeometry(response);
 | 
				
			||||||
		OSRM.Routing.showRouteDescriptionSimple(response);
 | 
							OSRM.Routing.showRouteDescriptionSimple(response);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	OSRM.Routing.updateHints(response);
 | 
						OSRM.Routing._updateHints(response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//	// TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
 | 
						// TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
 | 
				
			||||||
//	if(OSRM.G.pending) {
 | 
						if(OSRM.G.pending) {
 | 
				
			||||||
//		clearTimeout(OSRM.G.pendingTimer);
 | 
							//clearTimeout(OSRM.G.pendingTimer);
 | 
				
			||||||
//		OSRM.G.pendingTimer = setTimeout(OSRM.Routing.timeoutDrag,100);		
 | 
							OSRM.G.pendingTimer = setTimeout(OSRM.Routing.draggingTimeout,1);		
 | 
				
			||||||
//	}
 | 
						}
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
showRoute: function(response) {
 | 
					showRoute: function(response) {
 | 
				
			||||||
	if(!response)
 | 
						if(!response)
 | 
				
			||||||
@ -91,16 +91,16 @@ showRoute: function(response) {
 | 
				
			|||||||
		OSRM.Routing.showRouteGeometry(response);
 | 
							OSRM.Routing.showRouteGeometry(response);
 | 
				
			||||||
		OSRM.Routing.showRouteNonames(response);
 | 
							OSRM.Routing.showRouteNonames(response);
 | 
				
			||||||
		OSRM.Routing.showRouteDescription(response);
 | 
							OSRM.Routing.showRouteDescription(response);
 | 
				
			||||||
		OSRM.Routing.snapRoute();
 | 
							OSRM.Routing._snapRoute();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	OSRM.Routing.updateHints(response);
 | 
						OSRM.Routing._updateHints(response);
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// show route geometry
 | 
					// show route geometry
 | 
				
			||||||
showNoRouteGeometry: function() {
 | 
					showNoRouteGeometry: function() {
 | 
				
			||||||
	var positions = [];
 | 
						var positions = [];
 | 
				
			||||||
	for(var i=0; i<OSRM.G.markers.route.length;i++)
 | 
						for(var i=0, size=OSRM.G.markers.route.length; i<size; i++)
 | 
				
			||||||
			positions.push( OSRM.G.markers.route[i].getPosition() );
 | 
								positions.push( OSRM.G.markers.route[i].getPosition() );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
 | 
						OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
 | 
				
			||||||
@ -111,9 +111,9 @@ showRouteGeometry: function(response) {
 | 
				
			|||||||
	var geometry = OSRM.Routing.decodeRouteGeometry(response.route_geometry, 5);
 | 
						var geometry = OSRM.Routing.decodeRouteGeometry(response.route_geometry, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var points = [];
 | 
						var points = [];
 | 
				
			||||||
	for( var i=0; i < geometry.length; i++) {
 | 
						for( var i=0, size=geometry.length; i < size; i++)
 | 
				
			||||||
		points.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
 | 
							points.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
 | 
				
			||||||
	}
 | 
						
 | 
				
			||||||
	OSRM.G.route.showRoute(points, OSRM.Route.ROUTE);
 | 
						OSRM.G.route.showRoute(points, OSRM.Route.ROUTE);
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -273,6 +273,25 @@ showRouteNonames: function(response) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//-- main function --
 | 
					//-- main function --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//generate server calls to query routes
 | 
				
			||||||
 | 
					getDragRoute: function() {
 | 
				
			||||||
 | 
						// prepare JSONP call
 | 
				
			||||||
 | 
						var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
 | 
				
			||||||
 | 
						source += '?z=' + OSRM.G.map.getZoom() + '&output=json&geomformat=cmp&instructions=false';
 | 
				
			||||||
 | 
						if(OSRM.G.markers.checksum)
 | 
				
			||||||
 | 
							source += '&checksum=' + OSRM.G.markers.checksum;
 | 
				
			||||||
 | 
						for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
 | 
				
			||||||
 | 
							source += '&loc='  + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
 | 
				
			||||||
 | 
							if( OSRM.G.markers.route[i].hint)
 | 
				
			||||||
 | 
								source += '&hint=' + OSRM.G.markers.route[i].hint;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						OSRM.G.pending = !OSRM.JSONP.call(source, OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					draggingTimeout: function() {
 | 
				
			||||||
 | 
						OSRM.G.markers.route[OSRM.G.dragid].hint = null;
 | 
				
			||||||
 | 
						OSRM.Routing.getDragRoute();
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// generate server calls to query routes
 | 
					// generate server calls to query routes
 | 
				
			||||||
getRoute: function(do_description) {
 | 
					getRoute: function(do_description) {
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -365,7 +384,7 @@ decodeRouteGeometry: function(encoded, precision) {
 | 
				
			|||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// update hints of all markers
 | 
					// update hints of all markers
 | 
				
			||||||
updateHints: function(response) {
 | 
					_updateHints: function(response) {
 | 
				
			||||||
	var hint_locations = response.hint_data.locations;
 | 
						var hint_locations = response.hint_data.locations;
 | 
				
			||||||
	OSRM.G.markers.checksum = response.hint_data.checksum;
 | 
						OSRM.G.markers.checksum = response.hint_data.checksum;
 | 
				
			||||||
	for(var i=0; i<hint_locations.length; i++)
 | 
						for(var i=0; i<hint_locations.length; i++)
 | 
				
			||||||
@ -373,7 +392,7 @@ updateHints: function(response) {
 | 
				
			|||||||
},
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// snap all markers to the received route
 | 
					// snap all markers to the received route
 | 
				
			||||||
snapRoute: function() {
 | 
					_snapRoute: function() {
 | 
				
			||||||
	var positions = OSRM.G.route.getPositions();
 | 
						var positions = OSRM.G.route.getPositions();
 | 
				
			||||||
 	
 | 
					 	
 | 
				
			||||||
 	OSRM.G.markers.route[0].setPosition( positions[0] );
 | 
					 	OSRM.G.markers.route[0].setPosition( positions[0] );
 | 
				
			||||||
 | 
				
			|||||||
@ -63,7 +63,7 @@ findViaPosition: function( new_via_position ) {
 | 
				
			|||||||
	var index = OSRM.G.markers.setVia(new_via_index, new_via_position);
 | 
						var index = OSRM.G.markers.setVia(new_via_index, new_via_position);
 | 
				
			||||||
	OSRM.G.markers.route[index].show();
 | 
						OSRM.G.markers.route[index].show();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
 | 
						OSRM.Routing.getRoute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return new_via_index;
 | 
						return new_via_index;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -52,7 +52,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script src="OSRM.Map.js" type="text/javascript"></script>
 | 
					<script src="OSRM.Map.js" type="text/javascript"></script>
 | 
				
			||||||
<script src="OSRM.GUI.js" type="text/javascript"></script>
 | 
					<script src="OSRM.GUI.js" type="text/javascript"></script>
 | 
				
			||||||
<script src="OSRM.Routing.js" type="text/javascript"></script>
 | 
					<script src="routing/OSRM.Routing.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.RoutingGUI.js" type="text/javascript"></script>
 | 
				
			||||||
 | 
					<script src="routing/OSRM.RoutingNoNames.js" type="text/javascript"></script>
 | 
				
			||||||
<script src="OSRM.Via.js" type="text/javascript"></script>
 | 
					<script src="OSRM.Via.js" type="text/javascript"></script>
 | 
				
			||||||
<script src="OSRM.Geocoder.js" type="text/javascript"></script>
 | 
					<script src="OSRM.Geocoder.js" type="text/javascript"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -88,14 +92,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			|||||||
    <table class="full">
 | 
					    <table class="full">
 | 
				
			||||||
    <tr>
 | 
					    <tr>
 | 
				
			||||||
    <td id="gui-search-source-label">Start:</td>
 | 
					    <td id="gui-search-source-label">Start:</td>
 | 
				
			||||||
    <td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="OSRM.Routing.inputChanged(OSRM.C.SOURCE_LABEL);" /></td>
 | 
					    <td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="OSRM.RoutingGUI.inputChanged(OSRM.C.SOURCE_LABEL);" /></td>
 | 
				
			||||||
    <td class="right"><a class="button not-selectable" id="gui-search-source" onclick="OSRM.Routing.showMarker('source')">Zeigen</a></td>
 | 
					    <td class="right"><a class="button not-selectable" id="gui-search-source" onclick="OSRM.RoutingGUI.showMarker('source')">Zeigen</a></td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    <tr>
 | 
					    <tr>
 | 
				
			||||||
    <td id="gui-search-target-label">Ende:</td>
 | 
					    <td id="gui-search-target-label">Ende:</td>
 | 
				
			||||||
    <td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="OSRM.Routing.inputChanged(OSRM.C.TARGET_LABEL);" /></td>
 | 
					    <td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="OSRM.RoutingGUI.inputChanged(OSRM.C.TARGET_LABEL);" /></td>
 | 
				
			||||||
	<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="OSRM.Routing.showMarker('target');">Zeigen</a></td>	
 | 
						<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="OSRM.RoutingGUI.showMarker('target');">Zeigen</a></td>	
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
    </table>
 | 
					    </table>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -103,8 +107,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			|||||||
    <div class="vquad"></div>
 | 
					    <div class="vquad"></div>
 | 
				
			||||||
    <table style="width:100%">
 | 
					    <table style="width:100%">
 | 
				
			||||||
    <tr>
 | 
					    <tr>
 | 
				
			||||||
    <td>				<a class="button not-selectable" id="gui-reset" onclick="OSRM.Routing.resetRouting();">Reset</a></td>
 | 
					    <td>				<a class="button not-selectable" id="gui-reset" onclick="OSRM.RoutingGUI.resetRouting();">Reset</a></td>
 | 
				
			||||||
	<td class="right">	<a class="button not-selectable" id="gui-reverse" onclick="OSRM.Routing.reverseRouting();">Umdrehen</a></td>
 | 
						<td class="right">	<a class="button not-selectable" id="gui-reverse" onclick="OSRM.RoutingGUI.reverseRouting();">Umdrehen</a></td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
    </table>
 | 
					    </table>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -112,7 +116,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			|||||||
    <div class="vquad"></div>
 | 
					    <div class="vquad"></div>
 | 
				
			||||||
    <div class="main-options not-selectable" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Options</div>
 | 
					    <div class="main-options not-selectable" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Options</div>
 | 
				
			||||||
    <div class="main-options not-selectable" id="options-box">
 | 
					    <div class="main-options not-selectable" id="options-box">
 | 
				
			||||||
    <input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION)" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
 | 
					    <input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="OSRM.RoutingGUI.getRoute()" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -159,6 +159,6 @@ OSRM.checkURL = function(){
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		// compute route
 | 
							// compute route
 | 
				
			||||||
		OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
 | 
							OSRM.Routing.getRoute();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
							
								
								
									
										148
									
								
								WebContent/routing/OSRM.Routing.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								WebContent/routing/OSRM.Routing.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,148 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU AFFERO General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation; either version 3 of the License, or
 | 
				
			||||||
 | 
					any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					along with this program; if not, write to the Free Software
 | 
				
			||||||
 | 
					Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OSRM routing
 | 
				
			||||||
 | 
					// [management of routing requests and processing of responses]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// some variables
 | 
				
			||||||
 | 
					OSRM.GLOBALS.route = null;
 | 
				
			||||||
 | 
					OSRM.GLOBALS.markers = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.GLOBALS.dragging = null;
 | 
				
			||||||
 | 
					OSRM.GLOBALS.dragid = null;
 | 
				
			||||||
 | 
					OSRM.GLOBALS.pending = false;
 | 
				
			||||||
 | 
					OSRM.GLOBALS.pendingTimer = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.Routing = {
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					// init routing data structures
 | 
				
			||||||
 | 
					init: function() {
 | 
				
			||||||
 | 
						OSRM.G.route = new OSRM.Route();
 | 
				
			||||||
 | 
						OSRM.G.markers = new OSRM.Markers();
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// -- JSONP processing -- 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// process JSONP response of routing server
 | 
				
			||||||
 | 
					timeoutRouteSimple: function() {
 | 
				
			||||||
 | 
						OSRM.RoutingGeometry.showNA();
 | 
				
			||||||
 | 
						OSRM.RoutingDescription.showNA( OSRM.loc("TIMED_OUT") );
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					timeoutRoute: function() {
 | 
				
			||||||
 | 
						OSRM.RoutingGeometry.showNA();
 | 
				
			||||||
 | 
						OSRM.RoutingNoNames.showNA();
 | 
				
			||||||
 | 
						OSRM.RoutingDescription.showNA( OSRM.loc("TIMED_OUT") );
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					showRouteSimple: function(response) {
 | 
				
			||||||
 | 
					 	if(!response)
 | 
				
			||||||
 | 
					 		return;
 | 
				
			||||||
 | 
					 	if( !OSRM.G.dragging )		// prevent simple routing when no longer dragging
 | 
				
			||||||
 | 
					 		return;
 | 
				
			||||||
 | 
					 	
 | 
				
			||||||
 | 
						if( response.status == 207) {
 | 
				
			||||||
 | 
							OSRM.RoutingGeometry.showNA();
 | 
				
			||||||
 | 
							OSRM.RoutingDescription.showNA( OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED") );
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							OSRM.RoutingGeometry.show(response);
 | 
				
			||||||
 | 
							OSRM.RoutingDescription.showSimple(response);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						OSRM.Routing._updateHints(response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(OSRM.G.pending)
 | 
				
			||||||
 | 
							OSRM.G.pendingTimer = setTimeout(OSRM.Routing.draggingTimeout,1);		
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					showRoute: function(response) {
 | 
				
			||||||
 | 
						if(!response)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						OSRM.G.via_points = response.via_points.slice(0);
 | 
				
			||||||
 | 
						if(response.status == 207) {
 | 
				
			||||||
 | 
							OSRM.RoutingGeometry.showNA();
 | 
				
			||||||
 | 
							OSRM.RoutingNoNames.showNA();
 | 
				
			||||||
 | 
							OSRM.RoutingDescription.showNA( OSRM.loc("NO_ROUTE_FOUND") );
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							OSRM.RoutingGeometry.show(response);
 | 
				
			||||||
 | 
							OSRM.RoutingNoNames.show(response);
 | 
				
			||||||
 | 
							OSRM.RoutingDescription.show(response);
 | 
				
			||||||
 | 
							OSRM.Routing._snapRoute();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						OSRM.Routing._updateHints(response);
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//-- main function --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//generate server calls to query routes
 | 
				
			||||||
 | 
					getRoute: function() {
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// if source or target are not set -> hide route
 | 
				
			||||||
 | 
						if( OSRM.G.markers.route.length < 2 ) {
 | 
				
			||||||
 | 
							OSRM.G.route.hideRoute();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route');
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					getDragRoute: function() {
 | 
				
			||||||
 | 
						OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					draggingTimeout: function() {
 | 
				
			||||||
 | 
						OSRM.G.markers.route[OSRM.G.dragid].hint = null;
 | 
				
			||||||
 | 
						OSRM.Routing.getDragRoute();
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_buildCall: function() {
 | 
				
			||||||
 | 
						var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
 | 
				
			||||||
 | 
						source += '?z=' + OSRM.G.map.getZoom() + '&output=json&geomformat=cmp';	
 | 
				
			||||||
 | 
						if(OSRM.G.markers.checksum)
 | 
				
			||||||
 | 
							source += '&checksum=' + OSRM.G.markers.checksum;
 | 
				
			||||||
 | 
						for(var i=0,size=OSRM.G.markers.route.length; i<size; i++) {
 | 
				
			||||||
 | 
							source += '&loc='  + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
 | 
				
			||||||
 | 
							if( OSRM.G.markers.route[i].hint)
 | 
				
			||||||
 | 
								source += '&hint=' + OSRM.G.markers.route[i].hint;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return source;
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//-- helper functions --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// update hints of all markers
 | 
				
			||||||
 | 
					_updateHints: function(response) {
 | 
				
			||||||
 | 
						var hint_locations = response.hint_data.locations;
 | 
				
			||||||
 | 
						OSRM.G.markers.checksum = response.hint_data.checksum;
 | 
				
			||||||
 | 
						for(var i=0; i<hint_locations.length; i++)
 | 
				
			||||||
 | 
							OSRM.G.markers.route[i].hint = hint_locations[i];
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// snap all markers to the received route
 | 
				
			||||||
 | 
					_snapRoute: function() {
 | 
				
			||||||
 | 
						var positions = OSRM.G.route.getPositions();
 | 
				
			||||||
 | 
					 	
 | 
				
			||||||
 | 
					 	OSRM.G.markers.route[0].setPosition( positions[0] );
 | 
				
			||||||
 | 
					 	OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] );
 | 
				
			||||||
 | 
					 	for(var i=0; i<OSRM.G.via_points.length; i++)
 | 
				
			||||||
 | 
							OSRM.G.markers.route[i+1].setPosition( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 	OSRM.Geocoder.updateAddress(OSRM.C.SOURCE_LABEL);
 | 
				
			||||||
 | 
					 	OSRM.Geocoder.updateAddress(OSRM.C.TARGET_LABEL);
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										173
									
								
								WebContent/routing/OSRM.RoutingDescription.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								WebContent/routing/OSRM.RoutingDescription.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,173 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU AFFERO General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation; either version 3 of the License, or
 | 
				
			||||||
 | 
					any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					along with this program; if not, write to the Free Software
 | 
				
			||||||
 | 
					Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OSRM routing description
 | 
				
			||||||
 | 
					// [renders routing description and manages events]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.RoutingDescription = {
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					// route description events
 | 
				
			||||||
 | 
					onClickRouteDescription: function(geometry_index) {
 | 
				
			||||||
 | 
						var positions = OSRM.G.route.getPositions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						OSRM.G.markers.highlight.setPosition( positions[geometry_index] );
 | 
				
			||||||
 | 
						OSRM.G.markers.highlight.show();
 | 
				
			||||||
 | 
						OSRM.G.markers.highlight.centerView(OSRM.DEFAULTS.HIGHLIGHT_ZOOM_LEVEL);	
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					onClickCreateShortcut: function(src){
 | 
				
			||||||
 | 
						src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat + ',' + OSRM.G.map.getCenter().lng;
 | 
				
			||||||
 | 
						OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src, OSRM.RoutingDescription.showRouteLink, OSRM.RoutingDescription.showRouteLink_TimeOut, OSRM.DEFAULTS.JSONP_TIMEOUT, 'shortener');
 | 
				
			||||||
 | 
						document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("GENERATE_LINK_TO_ROUTE")+']';
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					showRouteLink: function(response){
 | 
				
			||||||
 | 
						document.getElementById('route-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]';
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					showRouteLink_TimeOut: function(){
 | 
				
			||||||
 | 
						document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']';
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handling of routing description
 | 
				
			||||||
 | 
					show: function(response) {
 | 
				
			||||||
 | 
						// compute query string
 | 
				
			||||||
 | 
						var query_string = '?rebuild=1';
 | 
				
			||||||
 | 
						for(var i=0; i<OSRM.G.markers.route.length; i++)
 | 
				
			||||||
 | 
							query_string += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng(); 
 | 
				
			||||||
 | 
					 						
 | 
				
			||||||
 | 
						// create link to the route
 | 
				
			||||||
 | 
						var route_link ='<span class="route-summary" id="route-prelink">[<a id="gpx-link" onclick="OSRM.RoutingDescription.onClickCreateShortcut(\'' + OSRM.DEFAULTS.WEBSITE_URL + query_string + '\')">'+OSRM.loc("GET_LINK_TO_ROUTE")+'</a>]</span>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// create GPX link
 | 
				
			||||||
 | 
						var gpx_link = '<span class="route-summary">[<a id="gpx-link" onClick="document.location.href=\'' + OSRM.DEFAULTS.HOST_ROUTING_URL + query_string + '&output=gpx\';">'+OSRM.loc("GPX_FILE")+'</a>]</span>';
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						// create route description
 | 
				
			||||||
 | 
						var route_desc = "";
 | 
				
			||||||
 | 
						route_desc += '<table class="results-table">';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for(var i=0; i < response.route_instructions.length; i++){
 | 
				
			||||||
 | 
							//odd or even ?
 | 
				
			||||||
 | 
							var rowstyle='results-odd';
 | 
				
			||||||
 | 
							if(i%2==0) { rowstyle='results-even'; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							route_desc += '<tr class="'+rowstyle+'">';
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							route_desc += '<td class="result-directions">';
 | 
				
			||||||
 | 
							route_desc += '<img width="18px" src="images/'+OSRM.RoutingDescription.getDirectionIcon(response.route_instructions[i][0])+'" alt="" />';
 | 
				
			||||||
 | 
							route_desc += "</td>";		
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							route_desc += '<td class="result-items">';
 | 
				
			||||||
 | 
							route_desc += '<span class="result-item" onclick="OSRM.RoutingDescription.onClickRouteDescription('+response.route_instructions[i][3]+')">';
 | 
				
			||||||
 | 
							route_desc += response.route_instructions[i][0];
 | 
				
			||||||
 | 
							if( i == 0 )
 | 
				
			||||||
 | 
								route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] );		
 | 
				
			||||||
 | 
							if( response.route_instructions[i][1] != "" ) {
 | 
				
			||||||
 | 
								route_desc += ' on ';
 | 
				
			||||||
 | 
								route_desc += '<b>' + response.route_instructions[i][1] + '</b>';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							//route_desc += ' for ';
 | 
				
			||||||
 | 
							route_desc += '</span>';
 | 
				
			||||||
 | 
							route_desc += "</td>";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							route_desc += '<td class="result-distance">';
 | 
				
			||||||
 | 
							if( i != response.route_instructions.length-1 )
 | 
				
			||||||
 | 
							route_desc += '<b>'+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+'</b>';
 | 
				
			||||||
 | 
							route_desc += "</td>";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							route_desc += "</tr>";
 | 
				
			||||||
 | 
						}	
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						route_desc += '</table>';		
 | 
				
			||||||
 | 
						headline = "";
 | 
				
			||||||
 | 
						headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
 | 
				
			||||||
 | 
						headline += '<div style="float:left;width:40%">';
 | 
				
			||||||
 | 
						headline += "<span class='route-summary'>"
 | 
				
			||||||
 | 
							+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
 | 
				
			||||||
 | 
							+ "<br>"
 | 
				
			||||||
 | 
							+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
 | 
				
			||||||
 | 
							+ "</span>";		
 | 
				
			||||||
 | 
						headline +=	'</div>';
 | 
				
			||||||
 | 
						headline += '<div style="float:left;text-align:right;width:60%;">'+route_link+'<br>'+gpx_link+'</div>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var output = "";
 | 
				
			||||||
 | 
						output += route_desc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						document.getElementById('information-box-headline').innerHTML = headline;
 | 
				
			||||||
 | 
						document.getElementById('information-box').innerHTML = output;
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// simple description
 | 
				
			||||||
 | 
					showSimple: function(response) {
 | 
				
			||||||
 | 
						headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
 | 
				
			||||||
 | 
						headline += "<span class='route-summary'>"
 | 
				
			||||||
 | 
								+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
 | 
				
			||||||
 | 
								+ "<br>"
 | 
				
			||||||
 | 
								+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
 | 
				
			||||||
 | 
								+ "</span>";
 | 
				
			||||||
 | 
						headline += '<br><br>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						document.getElementById('information-box-headline').innerHTML = headline;
 | 
				
			||||||
 | 
						document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";	
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// no description
 | 
				
			||||||
 | 
					showNA: function( display_text ) {
 | 
				
			||||||
 | 
						headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
 | 
				
			||||||
 | 
						headline += "<span class='route-summary'>"
 | 
				
			||||||
 | 
								+ OSRM.loc("DISTANCE")+": N/A"
 | 
				
			||||||
 | 
								+ "<br>"
 | 
				
			||||||
 | 
								+ OSRM.loc("DURATION")+": N/A"
 | 
				
			||||||
 | 
								+ "</span>";
 | 
				
			||||||
 | 
						headline += '<br><br>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						document.getElementById('information-box-headline').innerHTML = headline;
 | 
				
			||||||
 | 
						document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+display_text+".<p>";	
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// map driving instructions to icons
 | 
				
			||||||
 | 
					// [TODO: language-safe implementation]
 | 
				
			||||||
 | 
					getDirectionIcon: function(name) {
 | 
				
			||||||
 | 
						var directions = {
 | 
				
			||||||
 | 
							"Turn left":"turn-left.png",
 | 
				
			||||||
 | 
							"Turn right":"turn-right.png",
 | 
				
			||||||
 | 
							"U-Turn":"u-turn.png",
 | 
				
			||||||
 | 
							"Head":"continue.png",
 | 
				
			||||||
 | 
							"Continue":"continue.png",
 | 
				
			||||||
 | 
							"Turn slight left":"slight-left.png",
 | 
				
			||||||
 | 
							"Turn slight right":"slight-right.png",
 | 
				
			||||||
 | 
							"Turn sharp left":"sharp-left.png",
 | 
				
			||||||
 | 
							"Turn sharp right":"sharp-right.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at first exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at second exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at third exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at fourth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at fifth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at sixth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at seventh exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at eighth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at nineth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at tenth exit":"round-about.png",
 | 
				
			||||||
 | 
							"Enter roundabout and leave at one of the too many exit":"round-about.png",
 | 
				
			||||||
 | 
							"You have reached your destination":"target.png"
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if( directions[name] )
 | 
				
			||||||
 | 
							return directions[name];
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							return "default.png";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										94
									
								
								WebContent/routing/OSRM.RoutingGUI.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								WebContent/routing/OSRM.RoutingGUI.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,94 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU AFFERO General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation; either version 3 of the License, or
 | 
				
			||||||
 | 
					any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					along with this program; if not, write to the Free Software
 | 
				
			||||||
 | 
					Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OSRM routing
 | 
				
			||||||
 | 
					// [handles GUI events]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.RoutingGUI = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// click: button "reset"
 | 
				
			||||||
 | 
					resetRouting: function() {
 | 
				
			||||||
 | 
						document.getElementById('input-source-name').value = "";
 | 
				
			||||||
 | 
						document.getElementById('input-target-name').value = "";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						OSRM.G.route.hideAll();
 | 
				
			||||||
 | 
						OSRM.G.markers.removeAll();
 | 
				
			||||||
 | 
						OSRM.G.markers.highlight.hide();
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						document.getElementById('information-box').innerHTML = "";
 | 
				
			||||||
 | 
						document.getElementById('information-box-headline').innerHTML = "";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						OSRM.JSONP.reset();	
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// click: button "reverse"
 | 
				
			||||||
 | 
					reverseRouting: function() {
 | 
				
			||||||
 | 
						// invert input boxes
 | 
				
			||||||
 | 
						var tmp = document.getElementById("input-source-name").value;
 | 
				
			||||||
 | 
						document.getElementById("input-source-name").value = document.getElementById("input-target-name").value;
 | 
				
			||||||
 | 
						document.getElementById("input-target-name").value = tmp;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// invert route
 | 
				
			||||||
 | 
						OSRM.G.markers.route.reverse();
 | 
				
			||||||
 | 
						if(OSRM.G.markers.route.length == 1) {
 | 
				
			||||||
 | 
							if(OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL) {
 | 
				
			||||||
 | 
								OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
 | 
				
			||||||
 | 
								OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
 | 
				
			||||||
 | 
							} else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
 | 
				
			||||||
 | 
								OSRM.G.markers.route[0].label = OSRM.C.TARGET_LABEL;
 | 
				
			||||||
 | 
								OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else if(OSRM.G.markers.route.length > 1){
 | 
				
			||||||
 | 
							OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
 | 
				
			||||||
 | 
							OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.C.TARGET_LABEL;
 | 
				
			||||||
 | 
							OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );		
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// recompute route
 | 
				
			||||||
 | 
						if( OSRM.G.route.isShown() ) {
 | 
				
			||||||
 | 
							OSRM.Routing.getRoute();
 | 
				
			||||||
 | 
							OSRM.G.markers.highlight.hide();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							document.getElementById('information-box').innerHTML = "";
 | 
				
			||||||
 | 
							document.getElementById('information-box-headline').innerHTML = "";		
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// click: button "show"
 | 
				
			||||||
 | 
					showMarker: function(marker_id) {
 | 
				
			||||||
 | 
						if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] )
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
 | 
				
			||||||
 | 
							OSRM.G.markers.route[0].centerView();
 | 
				
			||||||
 | 
						else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
 | 
				
			||||||
 | 
							OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// changed: any inputbox (is called when return is pressed [after] or focus is lost [before])
 | 
				
			||||||
 | 
					inputChanged: function(marker_id) {
 | 
				
			||||||
 | 
						if( marker_id == OSRM.C.SOURCE_LABEL)	
 | 
				
			||||||
 | 
							OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('input-source-name').value);
 | 
				
			||||||
 | 
						else if( marker_id == OSRM.C.TARGET_LABEL)
 | 
				
			||||||
 | 
							OSRM.Geocoder.call(OSRM.C.TARGET_LABEL, document.getElementById('input-target-name').value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										71
									
								
								WebContent/routing/OSRM.RoutingGeometry.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								WebContent/routing/OSRM.RoutingGeometry.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU AFFERO General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation; either version 3 of the License, or
 | 
				
			||||||
 | 
					any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					along with this program; if not, write to the Free Software
 | 
				
			||||||
 | 
					Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OSRM routing geometry
 | 
				
			||||||
 | 
					// [renders routing geometry]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.RoutingGeometry = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// show route geometry - if there is a route
 | 
				
			||||||
 | 
					show: function(response) {
 | 
				
			||||||
 | 
						var geometry = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var positions = [];
 | 
				
			||||||
 | 
						for( var i=0, size=geometry.length; i < size; i++)
 | 
				
			||||||
 | 
							positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						OSRM.G.route.showRoute(positions, OSRM.Route.ROUTE);
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//show route geometry - if there is no route
 | 
				
			||||||
 | 
					showNA: function() {
 | 
				
			||||||
 | 
						var positions = [];
 | 
				
			||||||
 | 
						for(var i=0, size=OSRM.G.markers.route.length; i<size; i++)
 | 
				
			||||||
 | 
								positions.push( OSRM.G.markers.route[i].getPosition() );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//decode compressed route geometry
 | 
				
			||||||
 | 
					_decode: function(encoded, precision) {
 | 
				
			||||||
 | 
						precision = Math.pow(10, -precision);
 | 
				
			||||||
 | 
						var len = encoded.length, index=0, lat=0, lng = 0, array = [];
 | 
				
			||||||
 | 
						while (index < len) {
 | 
				
			||||||
 | 
							var b, shift = 0, result = 0;
 | 
				
			||||||
 | 
							do {
 | 
				
			||||||
 | 
								b = encoded.charCodeAt(index++) - 63;
 | 
				
			||||||
 | 
								result |= (b & 0x1f) << shift;
 | 
				
			||||||
 | 
								shift += 5;
 | 
				
			||||||
 | 
							} while (b >= 0x20);
 | 
				
			||||||
 | 
							var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
 | 
				
			||||||
 | 
							lat += dlat;
 | 
				
			||||||
 | 
							shift = 0;
 | 
				
			||||||
 | 
							result = 0;
 | 
				
			||||||
 | 
							do {
 | 
				
			||||||
 | 
								b = encoded.charCodeAt(index++) - 63;
 | 
				
			||||||
 | 
								result |= (b & 0x1f) << shift;
 | 
				
			||||||
 | 
								shift += 5;
 | 
				
			||||||
 | 
							} while (b >= 0x20);
 | 
				
			||||||
 | 
							var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
 | 
				
			||||||
 | 
							lng += dlng;
 | 
				
			||||||
 | 
							array.push([lat * precision, lng * precision]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return array;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										68
									
								
								WebContent/routing/OSRM.RoutingNoNames.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								WebContent/routing/OSRM.RoutingNoNames.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU AFFERO General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation; either version 3 of the License, or
 | 
				
			||||||
 | 
					any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					along with this program; if not, write to the Free Software
 | 
				
			||||||
 | 
					Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					or see http://www.gnu.org/licenses/agpl.txt.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OSRM routing
 | 
				
			||||||
 | 
					// [renders route segments that are unnamed streets]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OSRM.RoutingNoNames = {
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					// displays route segments that are unnamed streets
 | 
				
			||||||
 | 
					show: function(response) {
 | 
				
			||||||
 | 
						// do not display unnamed streets?
 | 
				
			||||||
 | 
						if( document.getElementById('option-highlight-nonames').checked == false) {
 | 
				
			||||||
 | 
							OSRM.G.route.hideUnnamedRoute();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						// mark geometry positions where unnamed/named streets switch
 | 
				
			||||||
 | 
						var named = [];
 | 
				
			||||||
 | 
						for (var i = 0; i < response.route_instructions.length; i++) {
 | 
				
			||||||
 | 
							if( response.route_instructions[i][1] == '' )
 | 
				
			||||||
 | 
								named[ response.route_instructions[i][3] ] = false;		// no street name
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								named[ response.route_instructions[i][3] ] = true;		// yes street name
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// aggregate geometry for unnamed streets
 | 
				
			||||||
 | 
						var geometry = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
 | 
				
			||||||
 | 
						var is_named = true;
 | 
				
			||||||
 | 
						var current_positions = [];
 | 
				
			||||||
 | 
						var all_positions = [];
 | 
				
			||||||
 | 
						for( var i=0; i < geometry.length; i++) {
 | 
				
			||||||
 | 
							current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// still named/unnamed?
 | 
				
			||||||
 | 
							if( (named[i] == is_named || named[i] == undefined) && i != geometry.length-1 )
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// switch between named/unnamed!
 | 
				
			||||||
 | 
							if(is_named == false)
 | 
				
			||||||
 | 
								all_positions.push( current_positions );
 | 
				
			||||||
 | 
							current_positions = [];
 | 
				
			||||||
 | 
							current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
 | 
				
			||||||
 | 
							is_named = named[i];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// display unnamed streets
 | 
				
			||||||
 | 
						OSRM.G.route.showUnnamedRoute(all_positions);
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					showNA: function() {
 | 
				
			||||||
 | 
						OSRM.G.route.hideUnnamedRoute();	
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user