diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index b4324060b..fa1ab43ec 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -19,26 +19,44 @@ or see http://www.gnu.org/licenses/agpl.txt. // [has to be loaded directly after OSRM.base] OSRM.DEFAULTS = { - HOST_ROUTING_URL: ['http://router.project-osrm.org/viaroute'], - HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', - HOST_TIMESTAMP_URL: 'http://router.project-osrm.org/timestamp', + ROUTING_ENGINES: [ + { url: 'http://router.project-osrm.org/viaroute', + timestamp: 'http://router.project-osrm.org/timestamp', + metric: 0, + label: 'ENGINE_0', + }, + { url: 'http://mapa.ump.waw.pl/ump-www/viaroute', + timestamp: 'http://mapa.ump.waw.pl/ump-www/timestamp', + metric: 0, + label: 'ENGINE_1', + }, + { url: 'http://mapa.ump.waw.pl/ump-www/rower/viaroute', + timestamp: 'http://mapa.ump.waw.pl/ump-www/rower/timestamp', + metric: 0, + label: 'ENGINE_2', + } + ], + + WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing # HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search', HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse', - WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing # - JSONP_TIMEOUT: 10000, + HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', + + SHORTENER_PARAMETERS: '%url&jsonp=%jsonp', + SHORTENER_REPLY_PARAMETER: 'ShortURL', + + ROUTING_ENGINE: 0, + DISTANCE_FORMAT: 0, // 0: km, 1: miles + GEOCODER_BOUNDS: '', ZOOM_LEVEL: 14, + HIGHLIGHT_ZOOM_LEVEL: 16, + JSONP_TIMEOUT: 10000, + ONLOAD_ZOOM_LEVEL: 5, ONLOAD_LATITUDE: 48.84, ONLOAD_LONGITUDE: 10.10, ONLOAD_SOURCE: "", ONLOAD_TARGET: "", - HIGHLIGHT_ZOOM_LEVEL: 16, - DISTANCE_FORMAT: 0, // 0: km, 1: miles - GEOCODER_BOUNDS: '', // the world is not enough! - //GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0', // bounds for Europe - - SHORTENER_PARAMETERS: '%url&jsonp=%jsonp', - SHORTENER_REPLY_PARAMETER: 'ShortURL', LANGUAGE: "en", LANUGAGE_ONDEMAND_RELOADING: true, @@ -97,7 +115,6 @@ OSRM.DEFAULTS = { DRAGGING: 120000, // 2min MAINTENANCE: false }, - - OVERRIDE_MAINTENANCE_HEADER: undefined, - OVERRIDE_MAINTENANCE_BODY: undefined + OVERRIDE_MAINTENANCE_NOTIFICATION_HEADER: undefined, + OVERRIDE_MAINTENANCE_NOTIFICATION_BODY: undefined }; diff --git a/WebContent/gui/OSRM.MainGUI.js b/WebContent/gui/OSRM.MainGUI.js index 8a740fe65..1eaab3c99 100644 --- a/WebContent/gui/OSRM.MainGUI.js +++ b/WebContent/gui/OSRM.MainGUI.js @@ -41,20 +41,15 @@ init: function() { document.getElementById('gui-input-source').value = OSRM.DEFAULTS.ONLOAD_SOURCE; document.getElementById('gui-input-target').value = OSRM.DEFAULTS.ONLOAD_TARGET; - // init units selector - OSRM.GUI.selectorInit( "gui-units-toggle", [{display:"Kilometers",value:0},{display:"Miles",value:1}], 0, OSRM.GUI.onUnitsChanged ); - - // query last update of data - OSRM.G.data_timestamp = "n/a"; - OSRM.JSONP.call(OSRM.DEFAULTS.HOST_TIMESTAMP_URL+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp'); + //init units selector + OSRM.GUI.initDistanceFormatsSelector(); }, // set language dependent labels setLabels: function() { document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM"); - document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS"); + document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS"); document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET"); - document.getElementById("gui-zoom").innerHTML = OSRM.loc("GUI_ZOOM_ON_ROUTE"); document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE"); document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS"); document.getElementById("gui-option-show-previous-routes-label").innerHTML = OSRM.loc("GUI_SHOW_PREVIOUS_ROUTES"); @@ -72,15 +67,12 @@ setLabels: function() { document.getElementById('gui-data-timestamp-label').innerHTML = OSRM.loc("GUI_DATA_TIMESTAMP"); document.getElementById('gui-data-timestamp').innerHTML = OSRM.G.data_timestamp; document.getElementById('gui-timestamp-label').innerHTML = OSRM.loc("GUI_VERSION"); - document.getElementById('gui-timestamp').innerHTML = OSRM.DATE+"; v"+OSRM.VERSION; + document.getElementById('gui-timestamp').innerHTML = OSRM.DATE+"; v"+OSRM.VERSION; document.getElementById('config-handle-icon').title = OSRM.loc("GUI_CONFIGURATION"); document.getElementById('mapping-handle-icon').title = OSRM.loc("GUI_MAPPING_TOOLS"); document.getElementById('main-handle-icon').title = OSRM.loc("GUI_MAIN_WINDOW"); - - document.getElementById("gui-units-toggle").getElementsByTagName("option")[0].innerHTML = OSRM.loc("GUI_KILOMETERS"); - document.getElementById("gui-units-toggle").getElementsByTagName("option")[1].innerHTML = OSRM.loc("GUI_MILES"); - OSRM.GUI.selectorOnChange( document.getElementById("gui-units-toggle") ); - OSRM.GUI.updateNotifications(); + OSRM.GUI.setDistanceFormatsLanguage(); + OSRM.GUI.setRoutingEnginesLanguage(); }, // clear output area @@ -95,7 +87,6 @@ beforeMainTransition: function() { if( zoom_controls.length > 0) zoom_controls[0].style.visibility="hidden"; }, - // show zoom controls after main box animation afterMainTransition: function() { var zoom_controls = OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom'); @@ -105,15 +96,15 @@ afterMainTransition: function() { } }, -// toggle distance units -onUnitsChanged: function(type) { - OSRM.GUI.changeDistanceFormat(type); - OSRM.Routing.getRoute({keepAlternative:true}); +// distance format routines +initDistanceFormatsSelector: function() { + var options = OSRM.GUI.getDistanceFormats(); + OSRM.GUI.selectorInit( "gui-units-toggle", options, OSRM.DEFAULTS.DISTANCE_FORMAT, OSRM.GUI._onDistanceFormatChanged ); }, - -// change distance format -changeDistanceFormat: function(type) { - OSRM.G.DISTANCE_FORMAT = type; +setDistanceFormat: function(type) { + if( OSRM.G.active_distance_format == type ) + return; + OSRM.active_distance_format = type; // change scale control if(OSRM.G.map) { @@ -129,12 +120,27 @@ changeDistanceFormat: function(type) { else OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMeters; }, +_onDistanceFormatChanged: function(type) { + OSRM.GUI.setDistanceFormat(type); + OSRM.Routing.getRoute({keepAlternative:true}); +}, +setDistanceFormatsLanguage: function() { + var options = OSRM.GUI.getDistanceFormats(); + OSRM.GUI.selectorRenameOptions("gui-units-toggle", options ); +}, +getDistanceFormats: function() { + return [{display:OSRM.loc("GUI_KILOMETERS"),value:0},{display:OSRM.loc("GUI_MILES"),value:1}]; +}, -// set timestamp of data +// data timestamp routines +queryDataTimestamp: function() { + OSRM.G.data_timestamp = "n/a"; + OSRM.JSONP.call( OSRM.G.active_routing_timestamp_url+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp'); +}, setDataTimestamp: function(response) { if(!response) return; - + OSRM.G.data_timestamp = response.timestamp.slice(0,25).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags document.getElementById('gui-data-timestamp').innerHTML = OSRM.G.data_timestamp; } diff --git a/WebContent/gui/OSRM.Notifications.js b/WebContent/gui/OSRM.Notifications.js index cb2a0681e..c5901673b 100644 --- a/WebContent/gui/OSRM.Notifications.js +++ b/WebContent/gui/OSRM.Notifications.js @@ -36,8 +36,8 @@ init: function() { // exclusive notifications var config = OSRM.DEFAULTS.NOTIFICATIONS; if( config["MAINTENANCE"] == true ) { - var header = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_HEADER || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER"); - var body = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_BODY || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY"); + var header = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_NOTIFICATION_HEADER || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER"); + var body = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_NOTIFICATION_BODY || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY"); OSRM.GUI.exclusiveNotify( header, body, false); OSRM.GUI.activeExclusive = "MAINTENANCE"; return; diff --git a/WebContent/gui/OSRM.RoutingEngineGUI.js b/WebContent/gui/OSRM.RoutingEngineGUI.js new file mode 100644 index 000000000..2a9af0dcb --- /dev/null +++ b/WebContent/gui/OSRM.RoutingEngineGUI.js @@ -0,0 +1,80 @@ +/* +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 RoutingEngineGUI +// [handles all GUI aspects that deals with switching the routing engine] + + +OSRM.GUI.extend( { + +// init +init: function() { + // gather routing engines + var options = OSRM.GUI.getRoutingEngines(); + + // generate selectors + OSRM.GUI.selectorInit("gui-engine-toggle", options, OSRM.DEFAULTS.ROUTING_ENGINE, OSRM.GUI._onRoutingEngineChanged); +}, + +// change active routing engine +setRoutingEngine: function(engine) { + if( engine == OSRM.G.active_routing_engine ) + return; + + OSRM.GUI.selectorChange( 'gui-engine-toggle', engine ); + + OSRM.G.active_routing_engine = engine; + OSRM.G.active_routing_metric = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].metric;; + OSRM.G.active_routing_server_url = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].url; + OSRM.G.active_routing_timestamp_url = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].timestamp; + + // requery data timestamp + OSRM.GUI.queryDataTimestamp(); + OSRM.JSONP.call( OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].timestamp+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.GUI.setDataTimestampTimeout, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp'); +}, +_onRoutingEngineChanged: function(engine) { + if( engine == OSRM.G.active_routing_engine ) + return; + + OSRM.GUI.setRoutingEngine( engine ); + + // requery route + if( OSRM.G.markers.route.length > 1 ) + OSRM.Routing.getRoute(); +}, + +// change language of routing engine entries +setRoutingEnginesLanguage: function() { + // gather routing engines + var options = OSRM.GUI.getRoutingEngines(); + + // change dropdown menu names + OSRM.GUI.selectorRenameOptions( "gui-engine-toggle", options ); +}, + +// gather routing engines +getRoutingEngines: function() { + var engines = OSRM.DEFAULTS.ROUTING_ENGINES; + var options = []; + for(var i=0, size=engines.length; i + @@ -207,8 +208,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
diff --git a/WebContent/main.js b/WebContent/main.js index c581b785a..871e0c51f 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -209,7 +209,7 @@ OSRM.parseParameters = function(){ var type = parseInt(name_val[1]); if(type != 0 && type != 1) return; - OSRM.GUI.changeDistanceFormat(type); + OSRM.GUI.setDistanceFormat(type); } else if(name_val[0] == 'loc') { var coordinates = unescape(name_val[1]).split(','); @@ -247,16 +247,10 @@ OSRM.parseParameters = function(){ } else if(name_val[0] == 're') { var active_routing_engine = Number(name_val[1]); - if( active_routing_engine<0 || active_routing_engine>=OSRM.DEFAULTS.HOST_ROUTING_URL.length) + if( active_routing_engine<0 || active_routing_engine>=OSRM.DEFAULTS.ROUTING_ENGINES.length) return; params.active_routing_engine = active_routing_engine; } - else if(name_val[0] == 'rm') { - var active_routing_metric = Number(name_val[1]); - if( active_routing_metric<0 ) - return; - params.active_routing_metric = active_routing_metric; - } } // case 1: destination given @@ -300,9 +294,7 @@ OSRM.parseParameters = function(){ OSRM.G.active_alternative = params.active_alternative || 0; // set routing server - OSRM.G.active_routing_engine = params.active_routing_engine || 0; - OSRM.G.active_routing_metric = params.active_routing_metric || 0; - OSRM.G.active_routing_server_url = OSRM.DEFAULTS.HOST_ROUTING_URL[ OSRM.G.active_routing_engine ]; + OSRM.GUI.setRoutingEngine( params.active_routing_engine || OSRM.DEFAULTS.ROUTING_ENGINE ); // compute route OSRM.Routing.getRoute({keepAlternative:true}); diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index 7a8f95fba..4315c9f07 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -236,7 +236,7 @@ printWindowLoaded: function(){ } // scale control - print_window.OSRM.G.DISTANCE_FORMAT = OSRM.G.DISTANCE_FORMAT; + print_window.OSRM.G.active_distance_format = OSRM.G.active_distance_format; // localization print_window.OSRM.G.Localization.culture = OSRM.loc("CULTURE"); diff --git a/WebContent/printing/printing.js b/WebContent/printing/printing.js index 244834b9a..7b8fe1a6b 100644 --- a/WebContent/printing/printing.js +++ b/WebContent/printing/printing.js @@ -78,8 +78,8 @@ OSRM.drawMap = function(tile_server, bounds) { // 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.options.metric = (OSRM.G.active_distance_format != 1); + OSRM.G.map.scaleControl.options.imperial = (OSRM.G.active_distance_format == 1); OSRM.G.map.scaleControl.addTo(OSRM.G.map); // need to rebuild objects for instanceof to work correctly diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index aabffb9f0..14c1a0bb8 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -31,9 +31,9 @@ OSRM.Routing = { // init routing data structures init: function() { - OSRM.G.active_routing_engine = 0; - OSRM.G.active_routing_metric = 0; - OSRM.G.active_routing_server_url = OSRM.DEFAULTS.HOST_ROUTING_URL[ OSRM.G.active_routing_engine ]; + // init variables + OSRM.GUI.setRoutingEngine( OSRM.DEFAULTS.ROUTING_ENGINE ); + OSRM.G.markers = new OSRM.Markers(); OSRM.G.route = new OSRM.Route(); OSRM.G.response = { via_points:[] }; diff --git a/WebContent/routing/OSRM.RoutingDescription.js b/WebContent/routing/OSRM.RoutingDescription.js index a8c5ed37c..cf9eb8b1d 100644 --- a/WebContent/routing/OSRM.RoutingDescription.js +++ b/WebContent/routing/OSRM.RoutingDescription.js @@ -30,9 +30,8 @@ onClickRouteDescription: function(lat, lng) { onClickCreateShortcut: function(src){ src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat.toFixed(6) + ',' + OSRM.G.map.getCenter().lng.toFixed(6); src += '&alt='+OSRM.G.active_alternative; - src += '&df=' + OSRM.G.DISTANCE_FORMAT; + src += '&df=' + OSRM.G.active_distance_format; src += '&re=' + OSRM.G.active_routing_engine; - src += '&rm=' + OSRM.G.active_routing_metric; var source = OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, OSRM.DEFAULTS.HOST_SHORTENER_URL+src);