From: Tom Hughes Date: Tue, 29 Jan 2019 21:35:29 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/2063' X-Git-Tag: live~2730 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/7f8025667b13877ba8dbe4f7457e98402977abbf?hp=db1094c1145754f0ba9ac982aa0920f0f6760b54 Merge remote-tracking branch 'upstream/pull/2063' --- diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 8a80328cc..bdba41ec2 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -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(""); }); - 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); diff --git a/app/assets/javascripts/index/directions/osrm.js b/app/assets/javascripts/index/directions/fossgis.js similarity index 92% rename from app/assets/javascripts/index/directions/osrm.js rename to app/assets/javascripts/index/directions/fossgis.js index 2f9498d03..a1a7624ac 100644 --- a/app/assets/javascripts/index/directions/osrm.js +++ b/app/assets/javascripts/index/directions/fossgis.js @@ -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: 'OSRM', + id: id, + creditline: 'FOSSGIS Routing Service', 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 index 739ce6539..000000000 --- a/app/assets/javascripts/index/directions/mapquest.js +++ /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: 'MapQuest ', - 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); -} diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index a67117510..a9e1a475e 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -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 %> diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bc1fd488d..9666adf12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/config/example.application.yml b/config/example.application.yml index b0b468d9e..7db7861b2 100644 --- a/config/example.application.yml +++ b/config/example.application.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c1f0ad2b..a81172de2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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"