X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/974e404a6e21e953354c38fc71338deb259f13ed..7869631e83a7686c06d92aaefb8a23245e930b57:/app/assets/javascripts/index/directions/fossgis_valhalla.js diff --git a/app/assets/javascripts/index/directions/fossgis_valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js index bbccccb13..493d09072 100644 --- a/app/assets/javascripts/index/directions/fossgis_valhalla.js +++ b/app/assets/javascripts/index/directions/fossgis_valhalla.js @@ -1,36 +1,36 @@ (function () { - function FOSSGISValhallaEngine(id, costing) { + function FOSSGISValhallaEngine(modeId, costing) { const INSTR_MAP = [ - 0, // kNone = 0; - 8, // kStart = 1; - 8, // kStartRight = 2; - 8, // kStartLeft = 3; - 14, // kDestination = 4; - 14, // kDestinationRight = 5; - 14, // kDestinationLeft = 6; - 0, // kBecomes = 7; - 0, // kContinue = 8; - 1, // kSlightRight = 9; - 2, // kRight = 10; - 3, // kSharpRight = 11; - 4, // kUturnRight = 12; - 4, // kUturnLeft = 13; - 7, // kSharpLeft = 14; - 6, // kLeft = 15; - 5, // kSlightLeft = 16; - 0, // kRampStraight = 17; - 24, // kRampRight = 18; - 25, // kRampLeft = 19; - 24, // kExitRight = 20; - 25, // kExitLeft = 21; - 0, // kStayStraight = 22; - 1, // kStayRight = 23; - 5, // kStayLeft = 24; - 20, // kMerge = 25; - 10, // kRoundaboutEnter = 26; - 10, // kRoundaboutExit = 27; - 17, // kFerryEnter = 28; - 0, // kFerryExit = 29; + "straight", // kNone = 0; + "start", // kStart = 1; + "start", // kStartRight = 2; + "start", // kStartLeft = 3; + "destination", // kDestination = 4; + "destination", // kDestinationRight = 5; + "destination", // kDestinationLeft = 6; + "straight", // kBecomes = 7; + "straight", // kContinue = 8; + "slight-right", // kSlightRight = 9; + "right", // kRight = 10; + "sharp-right", // kSharpRight = 11; + "u-turn", // kUturnRight = 12; + "u-turn", // kUturnLeft = 13; + "sharp-left", // kSharpLeft = 14; + "left", // kLeft = 15; + "slight-left", // kSlightLeft = 16; + "straight", // kRampStraight = 17; + "exit-right", // kRampRight = 18; + "exit-left", // kRampLeft = 19; + "exit-right", // kExitRight = 20; + "exit-left", // kExitLeft = 21; + "straight", // kStayStraight = 22; + "slight-right", // kStayRight = 23; + "slight-left", // kStayLeft = 24; + "merge-left", // kMerge = 25; + "roundabout", // kRoundaboutEnter = 26; + "roundabout", // kRoundaboutExit = 27; + "ferry", // kFerryEnter = 28; + "straight", // kFerryExit = 29; null, // kTransit = 30; null, // kTransitTransfer = 31; null, // kTransitRemainOn = 32; @@ -38,8 +38,8 @@ null, // kTransitConnectionTransfer = 34; null, // kTransitConnectionDestination = 35; null, // kPostTransitConnectionDestination = 36; - 21, // kMergeRight = 37; - 20 // kMergeLeft = 38; + "merge-right", // kMergeRight = 37; + "merge-left" // kMergeLeft = 38; ]; function _processDirections(tripLegs) { @@ -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); }());