1 GraphHopperEngine = function(vehicleName, vehicleParam, locale) {
2 this.vehicleName = vehicleName;
3 this.vehicleParam = vehicleParam;
9 GraphHopperEngine.prototype.createConfig = function() {
12 name: "javascripts.directions.engines.graphhopper_"+this.vehicleName.toLowerCase(),
15 getRoute: function(isFinal, points) {
16 var url = "http://graphhopper.com/routing/api/route?"
18 + "&locale=" + that.locale;
19 for (var i = 0; i < points.length; i++) {
20 var pair = points[i].join(',');
21 url += "&point=" + pair;
24 url += "&instructions=true";
25 // GraphHopper supports json too
26 this.requestJSONP(url + "&type=jsonp&callback=");
28 gotRoute: function(router, data) {
29 if (!data.info.routeFound) {
33 var line = L.PolylineUtil.decode(data.route.coordinates);
34 router.setPolyline(line);
35 // Assemble instructions
37 var instr = data.route.instructions;
38 for (i = 0; i < instr.descriptions.length; i++) {
39 var indi = instr.indications[i];
40 var instrCode = (i == instr.descriptions.length - 1) ? 15 : this.GH_INSTR_MAP[indi];
41 var instrText = "<b>" + (i + 1) + ".</b> ";
42 instrText += instr.descriptions[i];
43 var latlng = instr.latLngs[i];
44 var distInMeter = instr.distances[i];
45 steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter, []]); // TODO does graphhopper map instructions onto line indices?
47 router.setItinerary({ steps: steps, distance: data.route.distance, time: data.route['time']/1000 });
51 "-3": 6, // sharp left
53 "-1": 8, // slight left
62 OSM.RoutingEngines.add(false, new GraphHopperEngine("Bicycle", "vehicle=bike").createConfig());
63 OSM.RoutingEngines.add(false, new GraphHopperEngine("Foot", "vehicle=foot").createConfig());