X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a1a3b2c87e53c095d43bb9835590dc525122a062..64d41eac67ecdb3622c519cae9db6f9205e59bdc:/app/assets/javascripts/index/directions/fossgis_valhalla.js?ds=sidebyside diff --git a/app/assets/javascripts/index/directions/fossgis_valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js index bbccccb13..11aa4470b 100644 --- a/app/assets/javascripts/index/directions/fossgis_valhalla.js +++ b/app/assets/javascripts/index/directions/fossgis_valhalla.js @@ -1,5 +1,5 @@ (function () { - function FOSSGISValhallaEngine(id, costing) { + function FOSSGISValhallaEngine(modeId, costing) { const INSTR_MAP = [ 0, // kNone = 0; 8, // kStart = 1; @@ -82,13 +82,14 @@ } return { - id: id, + mode: modeId, + provider: "fossgis_valhalla", creditline: "Valhalla (FOSSGIS)", draggable: false, - getRoute: function (points, callback) { - const data = { + getRoute: function (points, signal) { + const query = new URLSearchParams({ json: JSON.stringify({ locations: points.map(function (p) { return { lat: p.lat, lon: p.lng, radius: 5 }; @@ -99,27 +100,18 @@ language: I18n.currentLocale() } }) - }; - return $.ajax({ - url: OSM.FOSSGIS_VALHALLA_URL, - data, - dataType: "json", - success: function ({ trip }) { - if (trip.status === 0) { - callback(false, _processDirections(trip.legs)); - } else { - callback(true); - } - }, - error: function () { - callback(true); - } }); + return fetch(OSM.FOSSGIS_VALHALLA_URL + "?" + query, { signal }) + .then(response => response.json()) + .then(({ trip }) => { + if (trip.status !== 0) throw new Error(); + return _processDirections(trip.legs); + }); } }; } - OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_car", "auto"), true); - OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_bicycle", "bicycle"), true); - OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_foot", "pedestrian"), true); + OSM.Directions.addEngine(new FOSSGISValhallaEngine("car", "auto"), true); + OSM.Directions.addEngine(new FOSSGISValhallaEngine("bicycle", "bicycle"), true); + OSM.Directions.addEngine(new FOSSGISValhallaEngine("foot", "pedestrian"), true); }());