From a32f4c231e678dd02a4728355455547d3d20fe2a Mon Sep 17 00:00:00 2001 From: Holger Jeromin Date: Sun, 26 Jan 2020 11:01:45 +0100 Subject: [PATCH] Prevent exceptions while reversing directions --- app/assets/javascripts/index/directions.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 4c39d6781..5f822b472 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -142,12 +142,20 @@ OSM.Directions = function (map) { $(".directions_form .reverse_directions").on("click", function () { var from = endpoints[0].latlng, - to = endpoints[1].latlng; + to = endpoints[1].latlng, + routeFrom = "", + routeTo = ""; + if(from){ + routeFrom = from.lat + "," + from.lng; + } + if(to){ + routeTo = to.lat + "," + to.lng; + } OSM.router.route("/directions?" + querystring.stringify({ from: $("#route_to").val(), to: $("#route_from").val(), - route: to.lat + "," + to.lng + ";" + from.lat + "," + from.lng + route: routeTo + ";" + routeFrom })); }); -- 2.43.2