]> git.openstreetmap.org Git - rails.git/commitdiff
Prevent exceptions while reversing directions
authorHolger Jeromin <mailgithub@katur.de>
Sun, 26 Jan 2020 10:01:45 +0000 (11:01 +0100)
committerGitHub <noreply@github.com>
Sun, 26 Jan 2020 10:01:45 +0000 (11:01 +0100)
app/assets/javascripts/index/directions.js

index 4c39d6781e1673d61d3e7c28aa186bb509acd464..5f822b47268f4a7f946bc9b26d362d85fe31f41d 100644 (file)
@@ -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
     }));
   });