- var steps = [];
- var len = path.instructions.length;
- for (var i = 0; i < len; i++) {
- var instr = path.instructions[i];
- var instrCode = (i === len - 1) ? 15 : GH_INSTR_MAP[instr.sign];
- var instrText = "<b>" + (i + 1) + ".</b> ";
- instrText += instr.text;
- var latLng = line[instr.interval[0]];
- var distInMeter = instr.distance;
- steps.push([
- {lat: latLng.lat, lng: latLng.lng},
- instrCode,
- instrText,
- distInMeter,
- []
- ]); // TODO does graphhopper map instructions onto line indices?
+ getRoute: function (points, callback) {
+ // GraphHopper Directions API documentation
+ // https://graphhopper.com/api/1/docs/routing/
+ const data = {
+ vehicle: vehicleType,
+ locale: I18n.currentLocale(),
+ key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
+ elevation: false,
+ instructions: true,
+ turn_costs: vehicleType === "car",
+ point: points.map(p => p.lat + "," + p.lng)
+ };
+ return $.ajax({
+ url: OSM.GRAPHHOPPER_URL,
+ data,
+ traditional: true,
+ dataType: "json",
+ success: function ({ paths }) {
+ if (!paths || paths.length === 0) {
+ return callback(true);
+ }
+ callback(false, _processDirections(paths[0]));
+ },
+ error: function () {
+ callback(true);