Merge remote-tracking branch 'upstream/pull/2063'
authorTom Hughes <tom@compton.nu>
Tue, 29 Jan 2019 21:35:29 +0000 (21:35 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 29 Jan 2019 21:35:29 +0000 (21:35 +0000)
app/assets/javascripts/index/directions.js
app/assets/javascripts/index/directions/fossgis.js [moved from app/assets/javascripts/index/directions/osrm.js with 92% similarity]
app/assets/javascripts/index/directions/mapquest.js [deleted file]
app/assets/javascripts/osm.js.erb
app/controllers/application_controller.rb
config/example.application.yml
config/locales/en.yml

index 8a80328cc05c3767813ac7ff3823330001095d9e..bdba41ec25c2aca44f7c439a639abda38f036d27 100644 (file)
@@ -159,15 +159,17 @@ OSM.Directions = function (map) {
     return h + ":" + (m < 10 ? '0' : '') + m;
   }
 
-  function setEngine(id) {
-    engines.forEach(function(engine, i) {
-      if (engine.id === id) {
-        chosenEngine = engine;
-        select.val(i);
-      }
+  function findEngine(id) {
+    return engines.findIndex(function(engine) {
+      return engine.id === id;
     });
   }
 
+  function setEngine(index) {
+    chosenEngine = engines[index];
+    select.val(index);
+  }
+
   function getRoute(fitRoute, reportErrors) {
     // Cancel any route that is already in progress
     if (awaitingRoute) awaitingRoute.abort();
@@ -316,11 +318,11 @@ OSM.Directions = function (map) {
     select.append("<option value='" + i + "'>" + I18n.t('javascripts.directions.engines.' + engine.id) + "</option>");
   });
 
-  var chosenEngineId = $.cookie('_osm_directions_engine');
-  if(!chosenEngineId) {
-    chosenEngineId = 'osrm_car';
+  var chosenEngineIndex = findEngine('fossgis_osrm_car');
+  if ($.cookie('_osm_directions_engine')) {
+    chosenEngineIndex = findEngine($.cookie('_osm_directions_engine'));
   }
-  setEngine(chosenEngineId);
+  setEngine(chosenEngineIndex);
 
   select.on("change", function (e) {
     chosenEngine = engines[e.target.selectedIndex];
@@ -374,7 +376,11 @@ OSM.Directions = function (map) {
         to = route[1] && L.latLng(route[1].split(','));
 
     if (params.engine) {
-      setEngine(params.engine);
+      var engineIndex = findEngine(params.engine);
+
+      if (engineIndex >= 0) {
+        setEngine(engineIndex);
+      }
     }
 
     endpoints[0].setValue(params.from || "", from);
similarity index 92%
rename from app/assets/javascripts/index/directions/osrm.js
rename to app/assets/javascripts/index/directions/fossgis.js
index 2f9498d039d43cc15ab4a4514cb208655251e2b4..a1a7624acb4a574f6c2e75e017af4f71aa3608e3 100644 (file)
@@ -1,12 +1,12 @@
-// OSRM car engine
+// FOSSGIS engine (OSRM based)
 // Doesn't yet support hints
 
-function OSRMEngine() {
+function FOSSGISEngine(id, vehicleType) {
   var cachedHints = [];
 
   return {
-    id: "osrm_car",
-    creditline: '<a href="http://project-osrm.org/" target="_blank">OSRM</a>',
+    id: id,
+    creditline: '<a href="https://routing.openstreetmap.de/about.html" target="_blank">FOSSGIS Routing Service</a>',
     draggable: true,
 
     _transformSteps: function(input_steps, line) {
@@ -133,7 +133,7 @@ function OSRMEngine() {
           }
         } else if (step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
           var params = {};
-          if (step.exits && step.maneuver.type.match(/^off ramp$/)) params.exit = step.exits;
+          if (step.exits && step.maneuver.type.match(/^(off ramp)$/)) params.exit = step.exits;
           if (step.destinations) params.directions = destinations;
           if (namedRoad) params.directions = name;
           if (Object.keys(params).length > 0) {
@@ -169,7 +169,7 @@ function OSRMEngine() {
         return p.lng + ',' + p.lat;
       }).join(';');
 
-      var req_url = OSM.OSRM_URL + encoded_coords;
+      var req_url = OSM.FOSSGIS_OSRM_URL + "routed-" + vehicleType + "/route/v1/driving/" + encoded_coords;
 
       var onResponse = function (data) {
         if (data.code !== 'Ok')
@@ -207,4 +207,7 @@ function OSRMEngine() {
   };
 }
 
-OSM.Directions.addEngine(new OSRMEngine(), true);
+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);
+
diff --git a/app/assets/javascripts/index/directions/mapquest.js b/app/assets/javascripts/index/directions/mapquest.js
deleted file mode 100644 (file)
index 739ce65..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-// For docs, see:
-// https://developer.mapquest.com/web/products/open/directions-service
-// https://open.mapquestapi.com/directions/
-// https://github.com/apmon/openstreetmap-website/blob/21edc353a4558006f0ce23f5ec3930be6a7d4c8b/app/controllers/routing_controller.rb#L153
-
-function MapQuestEngine(id, routeType) {
-  var MQ_SPRITE_MAP = {
-    0: 0, // straight
-    1: 1, // slight right
-    2: 2, // right
-    3: 3, // sharp right
-    4: 4, // reverse
-    5: 7, // sharp left
-    6: 6, // left
-    7: 5, // slight left
-    8: 4, // right U-turn
-    9: 4, // left U-turn
-    10: 21, // right merge
-    11: 20, // left merge
-    12: 21, // right on-ramp
-    13: 20, // left on-ramp
-    14: 24, // right off-ramp
-    15: 25, // left off-ramp
-    16: 18, // right fork
-    17: 19, // left fork
-    18: 0  // straight fork
-  };
-
-  return {
-    id: id,
-    creditline: '<a href="https://www.mapquest.com/" target="_blank">MapQuest</a> <img src="' + document.location.protocol + '//developer.mapquest.com/content/osm/mq_logo.png">',
-    draggable: false,
-
-    getRoute: function (points, callback) {
-      var from = points[0];
-      var to = points[points.length - 1];
-
-      return $.ajax({
-        url: OSM.MAPQUEST_DIRECTIONS_URL,
-        data: {
-          key: OSM.MAPQUEST_KEY,
-          from: from.lat + "," + from.lng,
-          to: to.lat + "," + to.lng,
-          routeType: routeType,
-          // locale: I18n.currentLocale(), //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n may only provides language, e.g. "de"
-          manMaps: false,
-          shapeFormat: "raw",
-          generalize: 0,
-          unit: "k"
-        },
-        dataType: "jsonp",
-        success: function (data) {
-          if (data.info.statuscode !== 0)
-            return callback(true);
-
-          var i;
-          var line = [];
-          var shape = data.route.shape.shapePoints;
-          for (i = 0; i < shape.length; i += 2) {
-            line.push(L.latLng(shape[i], shape[i + 1]));
-          }
-
-          // data.route.shape.maneuverIndexes links turns to polyline positions
-          // data.route.legs[0].maneuvers is list of turns
-          var steps = [];
-          var mq = data.route.legs[0].maneuvers;
-          for (i = 0; i < mq.length; i++) {
-            var s = mq[i];
-            var d;
-            var linesegstart, linesegend, lineseg;
-            linesegstart = data.route.shape.maneuverIndexes[i];
-            if (i === mq.length - 1) {
-              d = 15;
-              linesegend = linesegstart + 1;
-            } else {
-              d = MQ_SPRITE_MAP[s.turnType];
-              linesegend = data.route.shape.maneuverIndexes[i + 1] + 1;
-            }
-            lineseg = [];
-            for (var j = linesegstart; j < linesegend; j++) {
-              lineseg.push(L.latLng(data.route.shape.shapePoints[j * 2], data.route.shape.shapePoints[j * 2 + 1]));
-            }
-            steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance * 1000, lineseg]);
-          }
-
-          callback(false, {
-            line: line,
-            steps: steps,
-            distance: data.route.distance * 1000,
-            time: data.route.time
-          });
-        },
-        error: function () {
-          callback(true);
-        }
-      });
-    }
-  };
-}
-
-if (OSM.MAPQUEST_KEY) {
-  OSM.Directions.addEngine(new MapQuestEngine("mapquest_bicycle", "bicycle"), true);
-  OSM.Directions.addEngine(new MapQuestEngine("mapquest_foot", "pedestrian"), true);
-  OSM.Directions.addEngine(new MapQuestEngine("mapquest_car", "fastest"), true);
-}
index a671175108f3ab2b464489e808004eb8131eead7..a9e1a475ec15d8daf302e4cc9faeb2355adb3859 100644 (file)
@@ -14,13 +14,9 @@ OSM = {
   OVERPASS_URL:            <%= OVERPASS_URL.to_json %>,
   NOMINATIM_URL:           <%= NOMINATIM_URL.to_json %>,
   GRAPHHOPPER_URL:         <%= GRAPHHOPPER_URL.to_json %>,
-  MAPQUEST_DIRECTIONS_URL: <%= MAPQUEST_DIRECTIONS_URL.to_json %>,
-  OSRM_URL:                <%= OSRM_URL.to_json %>,
+  FOSSGIS_OSRM_URL:        <%= FOSSGIS_OSRM_URL.to_json %>,
   DEFAULT_LOCALE:          <%= I18n.default_locale.to_json %>,
 
-<% if defined?(MAPQUEST_KEY) %>
-  MAPQUEST_KEY:            <%= MAPQUEST_KEY.to_json %>,
-<% end %>
 <% if defined?(THUNDERFOREST_KEY) %>
   THUNDERFOREST_KEY:       <%= THUNDERFOREST_KEY.to_json %>,
 <% end %>
index bc1fd488df4002cf8b781823f27b52eabb9393ff..9666adf129698f8fc690c61c33aec247623e7acb 100644 (file)
@@ -333,11 +333,9 @@ 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 => [NOMINATIM_URL, OVERPASS_URL, OSRM_URL, GRAPHHOPPER_URL],
+      :connect_src => [NOMINATIM_URL, OVERPASS_URL, FOSSGIS_OSRM_URL, GRAPHHOPPER_URL],
       :form_action => %w[render.openstreetmap.org],
-      :style_src => %w['unsafe-inline'],
-      :script_src => [MAPQUEST_DIRECTIONS_URL],
-      :img_src => %w[developer.mapquest.com]
+      :style_src => %w['unsafe-inline']
     )
 
     if STATUS == :database_offline || STATUS == :api_offline
index b0b468d9ee07b1f6044f05295a5034effc52975b..7db7861b2dfe8acf84f47fdeb8d7ca5c4b441f4c 100644 (file)
@@ -104,8 +104,7 @@ defaults: &defaults
   overpass_url: "https://overpass-api.de/api/interpreter"
   # Routing endpoints
   graphhopper_url: "https://graphhopper.com/api/1/route"
-  mapquest_directions_url: "https://open.mapquestapi.com/directions/v2/route"
-  osrm_url: "https://router.project-osrm.org/route/v1/driving/"
+  fossgis_osrm_url: "https://routing.openstreetmap.de/"
   # External authentication credentials
   #google_auth_id: ""
   #google_auth_secret: ""
@@ -118,8 +117,6 @@ defaults: &defaults
   #github_auth_secret: ""
   #wikipedia_auth_id: ""
   #wikipedia_auth_secret: ""
-  # MapQuest authentication details
-  #mapquest_key: ""
   # Thunderforest authentication details
   #thunderforest_key: ""
   # Key for generating TOTP tokens
index 2c1f0ad2b44dda80a0c3385a4f4c646909bf1c82..a81172de2269096fc8d0efc201ae660b6fe339f5 100644 (file)
@@ -2438,13 +2438,12 @@ en:
     directions:
       ascend: "Ascend"
       engines:
+        fossgis_osrm_bike: "Bicycle (OSRM)"
+        fossgis_osrm_car: "Car (OSRM)"
+        fossgis_osrm_foot: "Foot (OSRM)"
         graphhopper_bicycle: "Bicycle (GraphHopper)"
         graphhopper_car: "Car (GraphHopper)"
         graphhopper_foot: "Foot (GraphHopper)"
-        mapquest_bicycle: "Bicycle (MapQuest)"
-        mapquest_car: "Car (MapQuest)"
-        mapquest_foot: "Foot (MapQuest)"
-        osrm_car: "Car (OSRM)"
       descend: "Descend"
       directions: "Directions"
       distance: "Distance"