]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3848'
authorTom Hughes <tom@compton.nu>
Thu, 22 Dec 2022 16:43:41 +0000 (16:43 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 22 Dec 2022 16:43:41 +0000 (16:43 +0000)
app/assets/javascripts/index/directions/fossgis_osrm.js [moved from app/assets/javascripts/index/directions/fossgis.js with 95% similarity]
app/assets/javascripts/index/directions/fossgis_valhalla.js [new file with mode: 0644]
app/assets/javascripts/osm.js.erb
app/controllers/application_controller.rb
config/locales/en.yml
config/settings.yml

similarity index 95%
rename from app/assets/javascripts/index/directions/fossgis.js
rename to app/assets/javascripts/index/directions/fossgis_osrm.js
index 8e5e8e621d6d8b194e9ecc7f254c43287cb077ab..3989ff2b6441c1f3e87c9725ce16b8f11a40cdb7 100644 (file)
@@ -1,12 +1,12 @@
-// FOSSGIS engine (OSRM based)
+// OSRM engine
 // Doesn't yet support hints
 
-function FOSSGISEngine(id, vehicleType) {
+function FOSSGISOSRMEngine(id, vehicleType) {
   var cachedHints = [];
 
   return {
     id: id,
-    creditline: "<a href=\"https://routing.openstreetmap.de/about.html\" target=\"_blank\">FOSSGIS Routing Service</a>",
+    creditline: "<a href=\"https://routing.openstreetmap.de/about.html\" target=\"_blank\">OSRM (FOSSGIS)</a>",
     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 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/fossgis_valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js
new file mode 100644 (file)
index 0000000..c897a3b
--- /dev/null
@@ -0,0 +1,112 @@
+function FOSSGISValhallaEngine(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:
+      "<a href='https://gis-ops.com/global-open-valhalla-server-online/' target='_blank'>Valhalla (FOSSGIS)</a>",
+    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, idx) {
+                var point = legLine[manoeuvre.begin_shape_index];
+
+                steps.push([
+                  { lat: point[0], lng: point[1] },
+                  INSTR_MAP[manoeuvre.type],
+                  "<b>" + (idx + 1) + ".</b> " + 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 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);
index 89f14caee6545ce00ce5034e676d71c021727546..0ffd35e2ceabfc922889ce572b727e8db3e272a2 100644 (file)
@@ -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) %>
index d3f57f0867f819a037b8ddbf581747ddb54f8530..87be14e5b3559eb56c2d435bb398f7f4f69dc0e8 100644 (file)
@@ -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']
     )
index c2815d142b784bf80e780fbb9573851af7cc3d77..a3e086396e274d46f92df531a4133c7973f859e4 100644 (file)
@@ -2927,6 +2927,9 @@ en:
         graphhopper_bicycle: "Bicycle (GraphHopper)"
         graphhopper_car: "Car (GraphHopper)"
         graphhopper_foot: "Foot (GraphHopper)"
+        fossgis_valhalla_bicycle: "Bicycle (Valhalla)"
+        fossgis_valhalla_car: "Car (Valhalla)"
+        fossgis_valhalla_foot: "Foot (Valhalla)"
       descend: "Descend"
       directions: "Directions"
       distance: "Distance"
index 09672c2c3a6565748d89be6f375055dbf99b9a0b..6e3f431f754b1b8c90ce3fc46b0f33c63562c220 100644 (file)
@@ -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: ""