added scale control

This commit is contained in:
DennisSchiefer 2012-08-14 16:51:24 +01:00
parent 320bbcfb20
commit 71399daf00
7 changed files with 50 additions and 22 deletions

View File

@ -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 );

View File

@ -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)

View File

@ -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);};

View File

@ -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(',');

View File

@ -233,10 +233,13 @@ printWindowLoaded: function(){
var stylesheet = OSRM.CSS.getStylesheet("printing.css", print_document);
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") + ");" );
}
}
// scale control
print_window.OSRM.G.DISTANCE_FORMAT = OSRM.G.DISTANCE_FORMAT;
// 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('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)

View File

@ -20,7 +20,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM = {};
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;
@ -60,7 +61,7 @@ OSRM.drawMap = function(tile_server, bounds) {
var tile_layer;
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);
tile_layer.options.culture = OSRM.Localization.culture;
tile_layer.options.culture = OSRM.G.Localization.culture;
OSRM.G.map = new OSRM.MapView("overview-map", {
center: new L.LatLng(48.84, 10.10),
zoom: 13,
@ -75,6 +76,12 @@ OSRM.drawMap = function(tile_server, bounds) {
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
var converted_bounds = new L.LatLngBounds([bounds.getSouthWest().lat, bounds.getSouthWest().lng], [bounds.getNorthEast().lat, bounds.getNorthEast().lng]);

View File

@ -35,13 +35,6 @@ toHumanTime: function(seconds){
else{ return hours + '&nbsp;' + 'h' + '&nbsp;' + minutes + '&nbsp;' + 'min';}
},
//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){
var distance = parseInt(meters);