2 // http://developer.mapquest.com/web/products/open/directions-service
3 // http://open.mapquestapi.com/directions/
4 // https://github.com/apmon/openstreetmap-website/blob/21edc353a4558006f0ce23f5ec3930be6a7d4c8b/app/controllers/routing_controller.rb#L153
6 function MapQuestEngine(id, vehicleParam) {
20 12: 2, // right on-ramp
21 13: 8, // left on-ramp
22 14: 2, // right off-ramp
23 15: 8, // left off-ramp
26 18: 1 // straight fork
31 creditline: '<a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">',
34 getRoute: function (points, callback) {
35 var url = document.location.protocol + "//open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
37 var to = points[points.length - 1];
38 url += "&from=" + from.lat + ',' + from.lng;
39 url += "&to=" + to.lat + ',' + to.lng;
40 url += "&" + vehicleParam;
41 //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n may only provides language, e.g. "de"
42 url += "&manMaps=false";
43 url += "&shapeFormat=raw&generalize=0&unit=k";
47 success: function (data) {
48 if (data.info.statuscode != 0)
49 return callback(true);
52 var shape = data.route.shape.shapePoints;
53 for (var i = 0; i < shape.length; i += 2) {
54 line.push(L.latLng(shape[i], shape[i + 1]));
57 // data.route.shape.maneuverIndexes links turns to polyline positions
58 // data.route.legs[0].maneuvers is list of turns
60 var mq = data.route.legs[0].maneuvers;
61 for (var i = 0; i < mq.length; i++) {
64 var linesegstart, linesegend, lineseg;
65 linesegstart = data.route.shape.maneuverIndexes[i];
66 if (i == mq.length - 1) {
68 linesegend = linesegstart + 1;
70 d = MQ_SPRITE_MAP[s.turnType];
71 linesegend = data.route.shape.maneuverIndexes[i + 1] + 1;
74 for (var j = linesegstart; j < linesegend; j++) {
75 lineseg.push(L.latLng(data.route.shape.shapePoints[j * 2], data.route.shape.shapePoints[j * 2 + 1]));
77 steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance * 1000, lineseg]);
83 distance: data.route.distance * 1000,
84 time: data.route['time']
92 OSM.Directions.addEngine(MapQuestEngine("mapquest_bicycle", "routeType=bicycle"), true);
93 OSM.Directions.addEngine(MapQuestEngine("mapquest_foot", "routeType=pedestrian"), true);
94 OSM.Directions.addEngine(MapQuestEngine("mapquest_car", "routeType=fastest"), true);