Cancel any outstanding route when starting a new one

Fixes #913
This commit is contained in:
Tom Hughes 2015-02-26 18:39:31 +00:00
parent 4b2c64fbed
commit 4254a1f291
4 changed files with 8 additions and 6 deletions

View file

@ -145,6 +145,9 @@ OSM.Directions = function (map) {
} }
function getRoute() { function getRoute() {
// Cancel any route that is already in progress
if (awaitingRoute) awaitingRoute.abourt();
// go fetch geocodes for any endpoints which have not already // go fetch geocodes for any endpoints which have not already
// been geocoded. // been geocoded.
for (var ep_i = 0; ep_i < 2; ++ep_i) { 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 // just using it in-place and replacing it in case it has to be used
// again. // again.
$('#sidebar_content').html($('.directions_form .loader_copy').html()); $('#sidebar_content').html($('.directions_form .loader_copy').html());
awaitingRoute = true;
map.setSidebarOverlaid(false); map.setSidebarOverlaid(false);
chosenEngine.getRoute([o, d], function (err, route) { awaitingRoute = chosenEngine.getRoute([o, d], function (err, route) {
awaitingRoute = false; awaitingRoute = null;
if (err) { if (err) {
map.removeLayer(polyline); map.removeLayer(polyline);

View file

@ -32,7 +32,7 @@ function GraphHopperEngine(id, vehicleParam) {
url += "&point=" + points[i].lat + ',' + points[i].lng; url += "&point=" + points[i].lat + ',' + points[i].lng;
} }
$.ajax({ return $.ajax({
url: url, url: url,
dataType: 'jsonp', dataType: 'jsonp',
success: function (data) { success: function (data) {

View file

@ -42,7 +42,7 @@ function MapQuestEngine(id, vehicleParam) {
url += "&manMaps=false"; url += "&manMaps=false";
url += "&shapeFormat=raw&generalize=0&unit=k"; url += "&shapeFormat=raw&generalize=0&unit=k";
$.ajax({ return $.ajax({
url: url, url: url,
success: function (data) { success: function (data) {
if (data.info.statuscode !== 0) if (data.info.statuscode !== 0)

View file

@ -44,7 +44,7 @@ function OSRMEngine() {
url += "&checksum=" + hintData.checksum; url += "&checksum=" + hintData.checksum;
} }
$.ajax({ return $.ajax({
url: url, url: url,
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {