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) {
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});
41 "-3": 6, // sharp left
43 "-1": 8, // slight left