From 9389a7698a5c44a5ec7796fdb24bd6eee3dbd0d6 Mon Sep 17 00:00:00 2001 From: Christian Beiwinkel Date: Fri, 16 Dec 2022 16:57:14 +0100 Subject: [PATCH 1/4] renamed fossgis engine --- .../index/directions/{fossgis.js => osrm.js} | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) rename app/assets/javascripts/index/directions/{fossgis.js => osrm.js} (95%) diff --git a/app/assets/javascripts/index/directions/fossgis.js b/app/assets/javascripts/index/directions/osrm.js similarity index 95% rename from app/assets/javascripts/index/directions/fossgis.js rename to app/assets/javascripts/index/directions/osrm.js index 8e5e8e621..280e66a80 100644 --- a/app/assets/javascripts/index/directions/fossgis.js +++ b/app/assets/javascripts/index/directions/osrm.js @@ -1,12 +1,12 @@ -// FOSSGIS engine (OSRM based) +// OSRM engine // Doesn't yet support hints -function FOSSGISEngine(id, vehicleType) { +function OSRMEngine(id, vehicleType) { var cachedHints = []; return { id: id, - creditline: "FOSSGIS Routing Service", + creditline: "OSRM (FOSSGIS)", draggable: true, _transformSteps: function (input_steps, line) { @@ -207,7 +207,6 @@ function FOSSGISEngine(id, vehicleType) { }; } -OSM.Directions.addEngine(new FOSSGISEngine("fossgis_osrm_car", "car"), true); -OSM.Directions.addEngine(new FOSSGISEngine("fossgis_osrm_bike", "bike"), true); -OSM.Directions.addEngine(new FOSSGISEngine("fossgis_osrm_foot", "foot"), true); - +OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_car", "car"), true); +OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_bike", "bike"), true); +OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_foot", "foot"), true); From 85f627c5c2d759046f159e4017ea799d92442178 Mon Sep 17 00:00:00 2001 From: Christian Beiwinkel Date: Fri, 16 Dec 2022 17:05:36 +0100 Subject: [PATCH 2/4] added valhalla routing engine --- .../javascripts/index/directions/valhalla.js | 112 ++++++++++++++++++ app/assets/javascripts/osm.js.erb | 1 + app/controllers/application_controller.rb | 2 +- config/locales/en.yml | 3 + config/settings.yml | 1 + 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/index/directions/valhalla.js diff --git a/app/assets/javascripts/index/directions/valhalla.js b/app/assets/javascripts/index/directions/valhalla.js new file mode 100644 index 000000000..1e424caba --- /dev/null +++ b/app/assets/javascripts/index/directions/valhalla.js @@ -0,0 +1,112 @@ +function ValhallaEngine(id, costing) { + var 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; + 11, // kRoundaboutExit = 27; + 17, // kFerryEnter = 28; + 0, // kFerryExit = 29; + ...Array(7).fill(), // irrelevant transit maneuvers + 21, // kMergeRight = 37; + 20 // kMergeLeft = 38; + ]; + + return { + id: id, + creditline: + "Valhalla (FOSSGIS)", + draggable: false, + + getRoute: function (points, callback) { + return $.ajax({ + url: OSM.FOSSGIS_VALHALLA_URL, + data: { + json: JSON.stringify({ + locations: points.map(function (p) { + return { lat: p.lat, lon: p.lng }; + }), + costing: costing, + directions_options: { + units: "km", + language: I18n.currentLocale() + } + }) + }, + dataType: "json", + success: function (data) { + var trip = data.trip; + + if (trip.status === 0) { + var line = []; + var steps = []; + var distance = 0; + var time = 0; + + trip.legs.forEach(function (leg) { + var legLine = L.PolylineUtil.decode(leg.shape, { + precision: 6 + }); + + line = line.concat(legLine); + + leg.maneuvers.forEach(function (manoeuvre) { + var point = legLine[manoeuvre.begin_shape_index]; + + steps.push([ + { lat: point[0], lng: point[1] }, + INSTR_MAP[manoeuvre.type], + manoeuvre.instruction, + manoeuvre.length * 1000, + [] + ]); + }); + + distance = distance + leg.summary.length; + time = time + leg.summary.time; + }); + + callback(false, { + line: line, + steps: steps, + distance: distance * 1000, + time: time + }); + } else { + callback(true); + } + }, + error: function () { + callback(true); + } + }); + } + }; +} + + OSM.Directions.addEngine(new ValhallaEngine("valhalla_car", "auto"), true); + OSM.Directions.addEngine(new ValhallaEngine("valhalla_bicycle", "bicycle"), true); + OSM.Directions.addEngine(new ValhallaEngine("valhalla_foot", "pedestrian"), true); diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 89f14caee..0ffd35e2c 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -18,6 +18,7 @@ OSM = { NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>, GRAPHHOPPER_URL: <%= Settings.graphhopper_url.to_json %>, FOSSGIS_OSRM_URL: <%= Settings.fossgis_osrm_url.to_json %>, + FOSSGIS_VALHALLA_URL: <%= Settings.fossgis_valhalla_url.to_json %>, DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>, <% if Settings.key?(:thunderforest_key) %> diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d3f57f086..87be14e5b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -289,7 +289,7 @@ class ApplicationController < ActionController::Base append_content_security_policy_directives( :child_src => %w[http://127.0.0.1:8111 https://127.0.0.1:8112], :frame_src => %w[http://127.0.0.1:8111 https://127.0.0.1:8112], - :connect_src => [Settings.nominatim_url, Settings.overpass_url, Settings.fossgis_osrm_url, Settings.graphhopper_url], + :connect_src => [Settings.nominatim_url, Settings.overpass_url, Settings.fossgis_osrm_url, Settings.graphhopper_url, Settings.fossgis_valhalla_url], :form_action => %w[render.openstreetmap.org], :style_src => %w['unsafe-inline'] ) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0d52e59a7..ba2add26f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2927,6 +2927,9 @@ en: graphhopper_bicycle: "Bicycle (GraphHopper)" graphhopper_car: "Car (GraphHopper)" graphhopper_foot: "Foot (GraphHopper)" + valhalla_bicycle: "Bicycle (Valhalla)" + valhalla_car: "Car (Valhalla)" + valhalla_foot: "Foot (Valhalla)" descend: "Descend" directions: "Directions" distance: "Distance" diff --git a/config/settings.yml b/config/settings.yml index 09672c2c3..6e3f431f7 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -99,6 +99,7 @@ overpass_credentials: false # Routing endpoints graphhopper_url: "https://graphhopper.com/api/1/route" fossgis_osrm_url: "https://routing.openstreetmap.de/" +fossgis_valhalla_url: "https://valhalla1.openstreetmap.de/route" # External authentication credentials #google_auth_id: "" #google_auth_secret: "" From 613c1ba234432cee94ad68f9478e7b60e2dc06e5 Mon Sep 17 00:00:00 2001 From: Christian Beiwinkel Date: Thu, 22 Dec 2022 17:33:20 +0100 Subject: [PATCH 3/4] added manoeuvre numbering --- app/assets/javascripts/index/directions/valhalla.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index/directions/valhalla.js b/app/assets/javascripts/index/directions/valhalla.js index 1e424caba..2b946b783 100644 --- a/app/assets/javascripts/index/directions/valhalla.js +++ b/app/assets/javascripts/index/directions/valhalla.js @@ -73,13 +73,13 @@ function ValhallaEngine(id, costing) { line = line.concat(legLine); - leg.maneuvers.forEach(function (manoeuvre) { + leg.maneuvers.forEach(function (manoeuvre, idx) { var point = legLine[manoeuvre.begin_shape_index]; steps.push([ { lat: point[0], lng: point[1] }, INSTR_MAP[manoeuvre.type], - manoeuvre.instruction, + "" + (idx + 1) + ". " + manoeuvre.instruction, manoeuvre.length * 1000, [] ]); From 1e332721531b9b3baa1a8795a718cdeffdb2bd40 Mon Sep 17 00:00:00 2001 From: Christian Beiwinkel Date: Thu, 22 Dec 2022 17:39:50 +0100 Subject: [PATCH 4/4] consistent naming of FOSSGIS routers --- .../index/directions/{osrm.js => fossgis_osrm.js} | 8 ++++---- .../index/directions/{valhalla.js => fossgis_valhalla.js} | 8 ++++---- config/locales/en.yml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) rename app/assets/javascripts/index/directions/{osrm.js => fossgis_osrm.js} (96%) rename app/assets/javascripts/index/directions/{valhalla.js => fossgis_valhalla.js} (89%) diff --git a/app/assets/javascripts/index/directions/osrm.js b/app/assets/javascripts/index/directions/fossgis_osrm.js similarity index 96% rename from app/assets/javascripts/index/directions/osrm.js rename to app/assets/javascripts/index/directions/fossgis_osrm.js index 280e66a80..3989ff2b6 100644 --- a/app/assets/javascripts/index/directions/osrm.js +++ b/app/assets/javascripts/index/directions/fossgis_osrm.js @@ -1,7 +1,7 @@ // OSRM engine // Doesn't yet support hints -function OSRMEngine(id, vehicleType) { +function FOSSGISOSRMEngine(id, vehicleType) { var cachedHints = []; return { @@ -207,6 +207,6 @@ function OSRMEngine(id, vehicleType) { }; } -OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_car", "car"), true); -OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_bike", "bike"), true); -OSM.Directions.addEngine(new OSRMEngine("fossgis_osrm_foot", "foot"), true); +OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_car", "car"), true); +OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_bike", "bike"), true); +OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_foot", "foot"), true); diff --git a/app/assets/javascripts/index/directions/valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js similarity index 89% rename from app/assets/javascripts/index/directions/valhalla.js rename to app/assets/javascripts/index/directions/fossgis_valhalla.js index 2b946b783..c897a3b16 100644 --- a/app/assets/javascripts/index/directions/valhalla.js +++ b/app/assets/javascripts/index/directions/fossgis_valhalla.js @@ -1,4 +1,4 @@ -function ValhallaEngine(id, costing) { +function FOSSGISValhallaEngine(id, costing) { var INSTR_MAP = [ 0, // kNone = 0; 8, // kStart = 1; @@ -107,6 +107,6 @@ function ValhallaEngine(id, costing) { }; } - OSM.Directions.addEngine(new ValhallaEngine("valhalla_car", "auto"), true); - OSM.Directions.addEngine(new ValhallaEngine("valhalla_bicycle", "bicycle"), true); - OSM.Directions.addEngine(new ValhallaEngine("valhalla_foot", "pedestrian"), true); + 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); diff --git a/config/locales/en.yml b/config/locales/en.yml index ba2add26f..0efe22cb2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2927,9 +2927,9 @@ en: graphhopper_bicycle: "Bicycle (GraphHopper)" graphhopper_car: "Car (GraphHopper)" graphhopper_foot: "Foot (GraphHopper)" - valhalla_bicycle: "Bicycle (Valhalla)" - valhalla_car: "Car (Valhalla)" - valhalla_foot: "Foot (Valhalla)" + fossgis_valhalla_bicycle: "Bicycle (Valhalla)" + fossgis_valhalla_car: "Car (Valhalla)" + fossgis_valhalla_foot: "Foot (Valhalla)" descend: "Descend" directions: "Directions" distance: "Distance"