diff --git a/WebContent/base/OSRM.Map.js b/WebContent/base/OSRM.Map.js index 1e1f47158..1b6b0154b 100644 --- a/WebContent/base/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -62,6 +62,12 @@ init: function() { // 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.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 OSRM.G.map.on('zoomend', OSRM.Map.zoomed ); diff --git a/WebContent/gui/OSRM.MainGUI.js b/WebContent/gui/OSRM.MainGUI.js index 405b1b44b..ba7544e4d 100644 --- a/WebContent/gui/OSRM.MainGUI.js +++ b/WebContent/gui/OSRM.MainGUI.js @@ -100,11 +100,30 @@ afterMainTransition: function() { }, // toggle distance units -onUnitsChanged: function(value) { - OSRM.Utils.setToHumanDistanceFunction(value); +onUnitsChanged: function(type) { + OSRM.GUI.changeDistanceFormat(type); 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 setDataTimestamp: function(response) { if(!response) diff --git a/WebContent/gui/OSRM.RoutingGUI.js b/WebContent/gui/OSRM.RoutingGUI.js index 736d8a86d..0e4f6dd2f 100644 --- a/WebContent/gui/OSRM.RoutingGUI.js +++ b/WebContent/gui/OSRM.RoutingGUI.js @@ -24,7 +24,7 @@ OSRM.GUI.extend( { // init init: function() { // init variables - OSRM.Utils.setToHumanDistanceFunction(OSRM.DEFAULTS.DISTANCE_FORMAT); + OSRM.GUI.changeDistanceFormat(OSRM.DEFAULTS.DISTANCE_FORMAT); // init events document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);}; diff --git a/WebContent/main.js b/WebContent/main.js index 7b37c3f0a..e1cc52f1c 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -29,19 +29,19 @@ OSRM.init = function() { OSRM.Map.init(); OSRM.Printing.init(); OSRM.Routing.init(); -// OSRM.RoutingAlternatives.init(); + OSRM.RoutingAlternatives.init(); OSRM.Localization.init(); // stop if in maintenance mode if( OSRM.GUI.inMaintenance() == true ) return; -// // check if the URL contains some GET parameter, e.g. for showing a route -// OSRM.parseParameters(); -// -// // only init default position / geolocation position if GET parameters do not specify a different one -// if( OSRM.G.initial_position_override == false ) -// OSRM.Map.initPosition(); + // check if the URL contains some GET parameter, e.g. for showing a route + OSRM.parseParameters(); + + // only init default position / geolocation position if GET parameters do not specify a different one + if( OSRM.G.initial_position_override == false ) + OSRM.Map.initPosition(); }; @@ -206,7 +206,7 @@ OSRM.parseParameters = function(){ var type = parseInt(name_val[1]); if(type != 0 && type != 1) return; - OSRM.Utils.setToHumanDistanceFunction(type); + OSRM.GUI.changeDistanceFormat(type); } else if(name_val[0] == 'loc') { var coordinates = unescape(name_val[1]).split(','); diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index a84ef381e..7a8f95fba 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -233,10 +233,13 @@ printWindowLoaded: function(){ var stylesheet = OSRM.CSS.getStylesheet("printing.css", print_document); for(var i=0; i