1 // GraphHopper bicycle engine
3 OSM.RoutingEngines.list.push({
4 name: "javascripts.directions.engines.graphhopper_bike",
5 creditline: 'Directions courtesy of <a href="http://graphhopper.com/routing/" target="_blank">Graphhopper</a>',
8 getRoute: function(isFinal, points) {
9 var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=" + I18n.currentLocale();
10 for (var i = 0; i < points.length; i++) {
11 var pair = points[i].join(',');
12 url += "&point=" + pair;
15 url += "&instructions=true";
16 this.requestJSONP(url + "&type=jsonp&callback=");
18 gotRoute: function(router, data) {
19 if (!data.info.routeFound) {
20 alert("Couldn't find route between those two places");
24 var line = L.PolylineUtil.decode(data.route.coordinates);
25 router.setPolyline(line);
26 // Assemble instructions
28 var instr = data.route.instructions;
29 for (i = 0; i < instr.descriptions.length; i++) {
30 var indi = instr.indications[i];
31 var instrCode = (i==instr.descriptions.length-1) ? 15 : this.GH_INSTR_MAP[indi];
32 var instrText = "<b>" + (i + 1) + ".</b> ";
33 instrText += instr.descriptions[i];
34 var latlng = instr.latLngs[i];
35 var distInMeter = instr.distances[i];
36 steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]);
38 router.setItinerary({steps: steps});
41 "-3": 6, // sharp left
43 "-1": 8, // slight left