1 // GraphHopper bicycle engine
3 OSM.RoutingEngines.list.push({
4 name: 'Bicycle (GraphHopper)',
7 getRoute: function(isFinal, points) {
8 var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=en";
9 for (var i = 0; i < points.length; i++) {
10 var pair = points[i].join(',');
11 url += "&point=" + pair;
14 url += "&instructions=true";
15 this.requestJSONP(url + "&type=jsonp&callback=");
17 gotRoute: function(router, data) {
18 if (!data.info.routeFound) {
19 alert("Couldn't find route between those two places");
23 var line = L.PolylineUtil.decode(data.route.coordinates);
24 router.setPolyline(line);
25 // Assemble instructions
27 var instr = data.route.instructions;
28 for (i = 0; i < instr.descriptions.length; i++) {
29 var indi = instr.indications[i];
30 var instrCode = (i==instr.descriptions.length-1) ? 15 : this.GH_INSTR_MAP[indi];
31 var instrText = "<b>" + (i + 1) + ".</b> ";
32 instrText += instr.descriptions[i];
33 var latlng = instr.latLngs[i];
34 var distInMeter = instr.distances[i];
35 steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]);
37 router.setItinerary({steps: steps});
40 "-3": 6, // sharp left
42 "-1": 8, // slight left