From 7915a22cafafc1fcbd59d798ac1734ecfd083adc Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sat, 8 Mar 2014 12:31:06 +0000 Subject: [PATCH] Use generic GraphHopper engine --- app/assets/javascripts/routing.js.erb | 2 +- .../routing_engines/graphhopper.js | 63 +++++++++++++++++++ .../routing_engines/graphhopper_bicycle.js | 49 --------------- config/locales/en.yml | 3 +- 4 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 app/assets/javascripts/routing_engines/graphhopper.js delete mode 100644 app/assets/javascripts/routing_engines/graphhopper_bicycle.js diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index d1c66e293..2a10a9d5e 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -238,7 +238,7 @@ OSM.Routing=function(map,name,jqSearch) { // Add all engines var list=OSM.RoutingEngines.list; - list.sort(function(a,b) { return a.name>b.name; }); + list.sort(function(a,b) { return I18n.t(a.name)>I18n.t(b.name); }); var select=r.jqSearch.find('select.routing_engines'); for (var i=0; i "; + instrText += instr.descriptions[i]; + var latlng = instr.latLngs[i]; + var distInMeter = instr.distances[i]; + steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]); + } + router.setItinerary({steps: steps}); + return true; + }, + GH_INSTR_MAP: { + "-3": 6, // sharp left + "-2": 7, // left + "-1": 8, // slight left + 0: 0, // straight + 1: 1, // slight right + 2: 2, // right + 3: 3 // sharp right + } + }; +}; + +OSM.RoutingEngines.list.push(new GraphHopperEngine("Bicycle", "vehicle=bike").createConfig()); +OSM.RoutingEngines.list.push(new GraphHopperEngine("Foot", "vehicle=foot").createConfig()); diff --git a/app/assets/javascripts/routing_engines/graphhopper_bicycle.js b/app/assets/javascripts/routing_engines/graphhopper_bicycle.js deleted file mode 100644 index acf089278..000000000 --- a/app/assets/javascripts/routing_engines/graphhopper_bicycle.js +++ /dev/null @@ -1,49 +0,0 @@ -// GraphHopper bicycle engine - -OSM.RoutingEngines.list.push({ - name: "javascripts.directions.engines.graphhopper_bike", - creditline: 'Directions courtesy of Graphhopper', - draggable: true, - _hints: {}, - getRoute: function(isFinal, points) { - var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=" + I18n.currentLocale(); - for (var i = 0; i < points.length; i++) { - var pair = points[i].join(','); - url += "&point=" + pair; - } - if (isFinal) - url += "&instructions=true"; - this.requestJSONP(url + "&type=jsonp&callback="); - }, - gotRoute: function(router, data) { - if (!data.info.routeFound) { - return false; - } - // Draw polyline - var line = L.PolylineUtil.decode(data.route.coordinates); - router.setPolyline(line); - // Assemble instructions - var steps = []; - var instr = data.route.instructions; - for (i = 0; i < instr.descriptions.length; i++) { - var indi = instr.indications[i]; - var instrCode = (i==instr.descriptions.length-1) ? 15 : this.GH_INSTR_MAP[indi]; - var instrText = "" + (i + 1) + ". "; - instrText += instr.descriptions[i]; - var latlng = instr.latLngs[i]; - var distInMeter = instr.distances[i]; - steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]); - } - router.setItinerary({steps: steps}); - return true; - }, - GH_INSTR_MAP: { - "-3": 6, // sharp left - "-2": 7, // left - "-1": 8, // slight left - 0: 0, // straight - 1: 1, // slight right - 2: 2, // right - 3: 3 // sharp right - } -}); diff --git a/config/locales/en.yml b/config/locales/en.yml index 46fe41d10..8cb9c9674 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2120,7 +2120,8 @@ en: edit_help: Move the map and zoom in on a location you want to edit, then click here. directions: engines: - graphhopper_bike: "Bicycle (GraphHopper)" + graphhopper_bicycle: "Bicycle (GraphHopper)" + graphhopper_foot: "Foot (GraphHopper)" mapquest_bike: "Bicycle (MapQuest)" osrm_car: "Car (OSRM)" cloudmade_foot: "Foot (Cloudmade)" -- 2.39.5