]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Cancel any outstanding route when starting a new one
[rails.git] / app / assets / javascripts / index / directions.js
index 6149228ecb22ad02c79a5b10a5f9e8e33d2479b0..f7ac876369c2f21fb7288c602b28337e6293a4cc 100644 (file)
@@ -145,6 +145,9 @@ OSM.Directions = function (map) {
   }
 
   function getRoute() {
+    // Cancel any route that is already in progress
+    if (awaitingRoute) awaitingRoute.abourt();
+
     // go fetch geocodes for any endpoints which have not already
     // been geocoded.
     for (var ep_i = 0; ep_i < 2; ++ep_i) {
@@ -177,11 +180,10 @@ OSM.Directions = function (map) {
     // just using it in-place and replacing it in case it has to be used
     // again.
     $('#sidebar_content').html($('.directions_form .loader_copy').html());
-    awaitingRoute = true;
     map.setSidebarOverlaid(false);
 
-    chosenEngine.getRoute([o, d], function (err, route) {
-      awaitingRoute = false;
+    awaitingRoute = chosenEngine.getRoute([o, d], function (err, route) {
+      awaitingRoute = null;
 
       if (err) {
         map.removeLayer(polyline);