added scale control
This commit is contained in:
		
							parent
							
								
									320bbcfb20
								
							
						
					
					
						commit
						71399daf00
					
				| @ -62,6 +62,12 @@ init: function() { | |||||||
|     // move zoom markers
 |     // move zoom markers
 | ||||||
| 	OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.G.main_handle.boxWidth()+10)+"px"; | 	OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.G.main_handle.boxWidth()+10)+"px"; | ||||||
| 	OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px"; | 	OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px"; | ||||||
|  | 	 | ||||||
|  | 	// add scale control
 | ||||||
|  | 	OSRM.G.map.scaleControl = new L.Control.Scale(); | ||||||
|  | 	OSRM.G.map.scaleControl.options.metric = (OSRM.G.DISTANCE_FORMAT != 1); | ||||||
|  | 	OSRM.G.map.scaleControl.options.imperial = (OSRM.G.DISTANCE_FORMAT == 1);	 | ||||||
|  | 	OSRM.G.map.scaleControl.addTo(OSRM.G.map); | ||||||
| 
 | 
 | ||||||
| 	// map events
 | 	// map events
 | ||||||
| 	OSRM.G.map.on('zoomend', OSRM.Map.zoomed ); | 	OSRM.G.map.on('zoomend', OSRM.Map.zoomed ); | ||||||
|  | |||||||
| @ -100,11 +100,30 @@ afterMainTransition: function() { | |||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| // toggle distance units
 | // toggle distance units
 | ||||||
| onUnitsChanged: function(value) { | onUnitsChanged: function(type) { | ||||||
| 	OSRM.Utils.setToHumanDistanceFunction(value); | 	OSRM.GUI.changeDistanceFormat(type); | ||||||
| 	OSRM.Routing.getRoute({keepAlternative:true}); | 	OSRM.Routing.getRoute({keepAlternative:true}); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
|  | // change distance format
 | ||||||
|  | changeDistanceFormat: function(type) { | ||||||
|  | 	OSRM.G.DISTANCE_FORMAT = type; | ||||||
|  | 	 | ||||||
|  | 	// change scale control
 | ||||||
|  | 	if(OSRM.G.map) { | ||||||
|  | 		OSRM.G.map.scaleControl.removeFrom(OSRM.G.map); | ||||||
|  | 		OSRM.G.map.scaleControl.options.metric = (type != 1); | ||||||
|  | 		OSRM.G.map.scaleControl.options.imperial = (type == 1); | ||||||
|  | 		OSRM.G.map.scaleControl.addTo(OSRM.G.map); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	// change converter
 | ||||||
|  | 	if( type == 1 ) | ||||||
|  | 		OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMiles; | ||||||
|  | 	else | ||||||
|  | 		OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMeters; | ||||||
|  | }, | ||||||
|  | 
 | ||||||
| // set timestamp of data
 | // set timestamp of data
 | ||||||
| setDataTimestamp: function(response) { | setDataTimestamp: function(response) { | ||||||
| 	if(!response) | 	if(!response) | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ OSRM.GUI.extend( { | |||||||
| // init
 | // init
 | ||||||
| init: function() { | init: function() { | ||||||
| 	// init variables
 | 	// init variables
 | ||||||
| 	OSRM.Utils.setToHumanDistanceFunction(OSRM.DEFAULTS.DISTANCE_FORMAT); | 	OSRM.GUI.changeDistanceFormat(OSRM.DEFAULTS.DISTANCE_FORMAT); | ||||||
| 	 | 	 | ||||||
| 	// init events
 | 	// init events
 | ||||||
| 	document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);}; | 	document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);}; | ||||||
|  | |||||||
| @ -29,19 +29,19 @@ OSRM.init = function() { | |||||||
| 	OSRM.Map.init(); | 	OSRM.Map.init(); | ||||||
| 	OSRM.Printing.init(); | 	OSRM.Printing.init(); | ||||||
| 	OSRM.Routing.init(); | 	OSRM.Routing.init(); | ||||||
| //	OSRM.RoutingAlternatives.init();
 | 	OSRM.RoutingAlternatives.init(); | ||||||
| 	OSRM.Localization.init();	 | 	OSRM.Localization.init();	 | ||||||
| 	 | 	 | ||||||
| 	// stop if in maintenance mode
 | 	// stop if in maintenance mode
 | ||||||
| 	if( OSRM.GUI.inMaintenance() == true ) | 	if( OSRM.GUI.inMaintenance() == true ) | ||||||
| 		return; | 		return; | ||||||
| 	 | 	 | ||||||
| // 	// check if the URL contains some GET parameter, e.g. for showing a route
 |  	// check if the URL contains some GET parameter, e.g. for showing a route
 | ||||||
| // 	OSRM.parseParameters();
 |  	OSRM.parseParameters(); | ||||||
| // 
 |   | ||||||
| // 	// only init default position / geolocation position if GET parameters do not specify a different one
 |  	// only init default position / geolocation position if GET parameters do not specify a different one
 | ||||||
| // 	if( OSRM.G.initial_position_override == false )
 |  	if( OSRM.G.initial_position_override == false ) | ||||||
| // 		OSRM.Map.initPosition();
 |  		OSRM.Map.initPosition(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -206,7 +206,7 @@ OSRM.parseParameters = function(){ | |||||||
| 			var type = parseInt(name_val[1]); | 			var type = parseInt(name_val[1]); | ||||||
| 			if(type != 0 && type != 1) | 			if(type != 0 && type != 1) | ||||||
| 				return; | 				return; | ||||||
| 			OSRM.Utils.setToHumanDistanceFunction(type); | 			OSRM.GUI.changeDistanceFormat(type); | ||||||
| 		}		 | 		}		 | ||||||
| 		else if(name_val[0] == 'loc') { | 		else if(name_val[0] == 'loc') { | ||||||
| 			var coordinates = unescape(name_val[1]).split(','); | 			var coordinates = unescape(name_val[1]).split(','); | ||||||
|  | |||||||
| @ -233,10 +233,13 @@ printWindowLoaded: function(){ | |||||||
| 	var stylesheet = OSRM.CSS.getStylesheet("printing.css", print_document); | 	var stylesheet = OSRM.CSS.getStylesheet("printing.css", print_document); | ||||||
| 	for(var i=0; i<css_list.length; i++) { | 	for(var i=0; i<css_list.length; i++) { | ||||||
| 		OSRM.CSS.insert( stylesheet, css_list[i].id, "background-image:url("+ OSRM.Printing.BASE_DIRECTORY + OSRM.G.images[css_list[i].image_id].getAttribute("src") + ");" ); | 		OSRM.CSS.insert( stylesheet, css_list[i].id, "background-image:url("+ OSRM.Printing.BASE_DIRECTORY + OSRM.G.images[css_list[i].image_id].getAttribute("src") + ");" ); | ||||||
| 	}	 | 	} | ||||||
|  | 	 | ||||||
|  | 	// scale control
 | ||||||
|  | 	print_window.OSRM.G.DISTANCE_FORMAT = OSRM.G.DISTANCE_FORMAT; | ||||||
| 	 | 	 | ||||||
| 	// localization 
 | 	// localization 
 | ||||||
| 	print_window.OSRM.Localization.culture = OSRM.loc("CULTURE");  | 	print_window.OSRM.G.Localization.culture = OSRM.loc("CULTURE");  | ||||||
| 	print_document.getElementById('description-label').innerHTML = OSRM.loc( "ROUTE_DESCRIPTION" ); | 	print_document.getElementById('description-label').innerHTML = OSRM.loc( "ROUTE_DESCRIPTION" ); | ||||||
| 	print_document.getElementById('overview-map-label').innerHTML = OSRM.loc( "OVERVIEW_MAP" );	 | 	print_document.getElementById('overview-map-label').innerHTML = OSRM.loc( "OVERVIEW_MAP" );	 | ||||||
| 	if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() ) {		// error message if no route available (can trigger if user refreshes print-window)
 | 	if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() ) {		// error message if no route available (can trigger if user refreshes print-window)
 | ||||||
|  | |||||||
| @ -20,7 +20,8 @@ or see http://www.gnu.org/licenses/agpl.txt. | |||||||
| 
 | 
 | ||||||
| OSRM = {}; | OSRM = {}; | ||||||
| OSRM.GLOBALS = { main_handle:{boxVisible:function(){return false;}} };	// needed for fitBoundsUI to work
 | OSRM.GLOBALS = { main_handle:{boxVisible:function(){return false;}} };	// needed for fitBoundsUI to work
 | ||||||
| OSRM.Localization = { culture:"en-US" };								// needed for localized map tiles
 | OSRM.GLOBALS.Localization = { culture:"en-US" };						// needed for localized map tiles
 | ||||||
|  | OSRM.GLOBALS.DISTANCE_FORMAT = 0;										// needed for scale control
 | ||||||
| OSRM.G = OSRM.GLOBALS; | OSRM.G = OSRM.GLOBALS; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -60,7 +61,7 @@ OSRM.drawMap = function(tile_server, bounds) { | |||||||
| 	var tile_layer; | 	var tile_layer; | ||||||
| 	if( tile_server.bing )	tile_layer = new L.BingLayer(tile_server.apikey, tile_server.options); | 	if( tile_server.bing )	tile_layer = new L.BingLayer(tile_server.apikey, tile_server.options); | ||||||
| 	else 					tile_layer = new L.TileLayer(tile_server.url, tile_server.options); | 	else 					tile_layer = new L.TileLayer(tile_server.url, tile_server.options); | ||||||
| 	tile_layer.options.culture = OSRM.Localization.culture; | 	tile_layer.options.culture = OSRM.G.Localization.culture; | ||||||
| 	OSRM.G.map = new OSRM.MapView("overview-map", { | 	OSRM.G.map = new OSRM.MapView("overview-map", { | ||||||
|     	center: new L.LatLng(48.84, 10.10), |     	center: new L.LatLng(48.84, 10.10), | ||||||
| 	    zoom: 13, | 	    zoom: 13, | ||||||
| @ -75,6 +76,12 @@ OSRM.drawMap = function(tile_server, bounds) { | |||||||
| 	    doubleClickZoom:false | 	    doubleClickZoom:false | ||||||
| 	}); | 	}); | ||||||
| 	 | 	 | ||||||
|  | 	// add scale control
 | ||||||
|  | 	OSRM.G.map.scaleControl = new L.Control.Scale(); | ||||||
|  | 	OSRM.G.map.scaleControl.options.metric = (OSRM.G.DISTANCE_FORMAT != 1); | ||||||
|  | 	OSRM.G.map.scaleControl.options.imperial = (OSRM.G.DISTANCE_FORMAT == 1);	 | ||||||
|  | 	OSRM.G.map.scaleControl.addTo(OSRM.G.map);	 | ||||||
|  | 	 | ||||||
| 	// need to rebuild objects for instanceof to work correctly
 | 	// need to rebuild objects for instanceof to work correctly
 | ||||||
|     var converted_bounds = new L.LatLngBounds([bounds.getSouthWest().lat, bounds.getSouthWest().lng], [bounds.getNorthEast().lat, bounds.getNorthEast().lng]); |     var converted_bounds = new L.LatLngBounds([bounds.getSouthWest().lat, bounds.getSouthWest().lng], [bounds.getNorthEast().lat, bounds.getNorthEast().lng]); | ||||||
|      |      | ||||||
|  | |||||||
| @ -35,13 +35,6 @@ toHumanTime: function(seconds){ | |||||||
|    else{ return hours + ' ' + 'h' + ' ' + minutes + ' ' + 'min';} |    else{ return hours + ' ' + 'h' + ' ' + minutes + ' ' + 'min';} | ||||||
| }, | }, | ||||||
| //human readable distance
 | //human readable distance
 | ||||||
| setToHumanDistanceFunction: function(type) { |  | ||||||
| 	OSRM.G.DISTANCE_FORMAT = type; |  | ||||||
| 	if( type == 1 ) |  | ||||||
| 		OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMiles; |  | ||||||
| 	else |  | ||||||
| 		OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMeters;	 |  | ||||||
| }, |  | ||||||
| toHumanDistanceMeters: function(meters){ | toHumanDistanceMeters: function(meters){ | ||||||
| 	var distance = parseInt(meters); | 	var distance = parseInt(meters); | ||||||
| 	 | 	 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user