X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2d09b9408b4f3f9a7c7a5782098c6c5b81ae1206..567a9e5b23b07babe32381fd45647dc88ff1915e:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index ae01cb566..f7ce2adc1 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -3,7 +3,7 @@ //= require qs/dist/qs OSM.Directions = function (map) { - var awaitingRoute; // true if we've asked the engine for a route and are waiting to hear back + var routeRequest = null; // jqXHR object of an ongoing route request or null var chosenEngine; var popup = L.popup({ autoPanPadding: [100, 100] }); @@ -21,9 +21,11 @@ OSM.Directions = function (map) { }); var endpointDragCallback = function (dragging) { - if (map.hasLayer(polyline)) { - getRoute(false, !dragging); - } + if (!map.hasLayer(polyline)) return; + if (dragging && !chosenEngine.draggable) return; + if (dragging && routeRequest) return; + + getRoute(false, !dragging); }; var endpointGeocodeCallback = function () { getRoute(true, true); @@ -68,11 +70,8 @@ OSM.Directions = function (map) { }); endpoint.marker.on("drag dragend", function (e) { - var dragging = (e.type === "drag"); - if (dragging && !chosenEngine.draggable) return; - if (dragging && awaitingRoute) return; endpoint.setLatLng(e.target.getLatLng()); - dragCallback(dragging); + dragCallback(e.type === "drag"); }); input.on("keydown", function () { @@ -202,7 +201,7 @@ OSM.Directions = function (map) { function getRoute(fitRoute, reportErrors) { // Cancel any route that is already in progress - if (awaitingRoute) awaitingRoute.abort(); + if (routeRequest) routeRequest.abort(); // go fetch geocodes for any endpoints which have not already // been geocoded. @@ -236,8 +235,8 @@ OSM.Directions = function (map) { $("#sidebar_content").html($(".directions_form .loader_copy").html()); map.setSidebarOverlaid(false); - awaitingRoute = chosenEngine.getRoute([o, d], function (err, route) { - awaitingRoute = null; + routeRequest = chosenEngine.getRoute([o, d], function (err, route) { + routeRequest = null; if (err) { map.removeLayer(polyline);