X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/7a64ebe98265ff8ad6be5b8be9481661cd824f0f..48e886784e742ec28e33c32b3a0e0bf7cf6d21e7:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 8a80328cc..bdba41ec2 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -159,15 +159,17 @@ OSM.Directions = function (map) { return h + ":" + (m < 10 ? '0' : '') + m; } - function setEngine(id) { - engines.forEach(function(engine, i) { - if (engine.id === id) { - chosenEngine = engine; - select.val(i); - } + function findEngine(id) { + return engines.findIndex(function(engine) { + return engine.id === id; }); } + function setEngine(index) { + chosenEngine = engines[index]; + select.val(index); + } + function getRoute(fitRoute, reportErrors) { // Cancel any route that is already in progress if (awaitingRoute) awaitingRoute.abort(); @@ -316,11 +318,11 @@ OSM.Directions = function (map) { select.append(""); }); - var chosenEngineId = $.cookie('_osm_directions_engine'); - if(!chosenEngineId) { - chosenEngineId = 'osrm_car'; + var chosenEngineIndex = findEngine('fossgis_osrm_car'); + if ($.cookie('_osm_directions_engine')) { + chosenEngineIndex = findEngine($.cookie('_osm_directions_engine')); } - setEngine(chosenEngineId); + setEngine(chosenEngineIndex); select.on("change", function (e) { chosenEngine = engines[e.target.selectedIndex]; @@ -374,7 +376,11 @@ OSM.Directions = function (map) { to = route[1] && L.latLng(route[1].split(',')); if (params.engine) { - setEngine(params.engine); + var engineIndex = findEngine(params.engine); + + if (engineIndex >= 0) { + setEngine(engineIndex); + } } endpoints[0].setValue(params.from || "", from);