2 function FOSSGISValhallaEngine(modeId, costing) {
4 "straight", // kNone = 0;
5 "start", // kStart = 1;
6 "start", // kStartRight = 2;
7 "start", // kStartLeft = 3;
8 "destination", // kDestination = 4;
9 "destination", // kDestinationRight = 5;
10 "destination", // kDestinationLeft = 6;
11 "straight", // kBecomes = 7;
12 "straight", // kContinue = 8;
13 "slight-right", // kSlightRight = 9;
14 "right", // kRight = 10;
15 "sharp-right", // kSharpRight = 11;
16 "u-turn-right", // kUturnRight = 12;
17 "u-turn-left", // kUturnLeft = 13;
18 "sharp-left", // kSharpLeft = 14;
19 "left", // kLeft = 15;
20 "slight-left", // kSlightLeft = 16;
21 "straight", // kRampStraight = 17;
22 "exit-right", // kRampRight = 18;
23 "exit-left", // kRampLeft = 19;
24 "exit-right", // kExitRight = 20;
25 "exit-left", // kExitLeft = 21;
26 "straight", // kStayStraight = 22;
27 "slight-right", // kStayRight = 23;
28 "slight-left", // kStayLeft = 24;
29 "merge-left", // kMerge = 25;
30 "roundabout", // kRoundaboutEnter = 26;
31 "roundabout", // kRoundaboutExit = 27;
32 "ferry", // kFerryEnter = 28;
33 "straight", // kFerryExit = 29;
34 null, // kTransit = 30;
35 null, // kTransitTransfer = 31;
36 null, // kTransitRemainOn = 32;
37 null, // kTransitConnectionStart = 33;
38 null, // kTransitConnectionTransfer = 34;
39 null, // kTransitConnectionDestination = 35;
40 null, // kPostTransitConnectionDestination = 36;
41 "merge-right", // kMergeRight = 37;
42 "merge-left" // kMergeLeft = 38;
45 function _processDirections(leg) {
46 const line = L.PolylineUtil.decode(leg.shape, { precision: 6 });
48 const steps = leg.maneuvers.map(manoeuvre => [
49 INSTR_MAP[manoeuvre.type],
50 manoeuvre.instruction,
51 manoeuvre.length * 1000,
52 line.slice(manoeuvre.begin_shape_index, manoeuvre.end_shape_index + 1)
58 distance: leg.summary.length * 1000,
59 time: leg.summary.time,
60 credit: "Valhalla (FOSSGIS)",
61 creditlink: "https://gis-ops.com/global-open-valhalla-server-online/"
67 provider: "fossgis_valhalla",
70 getRoute: function (points, signal) {
71 const query = new URLSearchParams({
72 json: JSON.stringify({
73 locations: points.map(function (p) {
74 return { lat: p.lat, lon: p.lng, radius: 5 };
79 language: OSM.i18n.locale
83 return fetch(OSM.FOSSGIS_VALHALLA_URL + "?" + query, { signal })
84 .then(response => response.json())
86 if (trip.status !== 0) throw new Error();
87 return _processDirections(trip.legs[0]);
93 OSM.Directions.addEngine(new FOSSGISValhallaEngine("car", "auto"), true);
94 OSM.Directions.addEngine(new FOSSGISValhallaEngine("bicycle", "bicycle"), true);
95 OSM.Directions.addEngine(new FOSSGISValhallaEngine("foot", "pedestrian"), true);