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, routeType) {
18 10: 21, // right merge
20 12: 21, // right on-ramp
21 13: 20, // left on-ramp
22 14: 24, // right off-ramp
23 15: 25, // left off-ramp
26 18: 0 // straight fork
31 creditline: '<a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="' + document.location.protocol + '//developer.mapquest.com/content/osm/mq_logo.png">',
34 getRoute: function (points, callback) {
36 var to = points[points.length - 1];
39 url: document.location.protocol + OSM.MAPQUEST_DIRECTIONS_URL,
41 key: OSM.MAPQUEST_KEY,
42 from: from.lat + "," + from.lng,
43 to: to.lat + "," + to.lng,
45 // locale: I18n.currentLocale(), //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n may only provides language, e.g. "de"
52 success: function (data) {
53 if (data.info.statuscode !== 0)
54 return callback(true);
58 var shape = data.route.shape.shapePoints;
59 for (i = 0; i < shape.length; i += 2) {
60 line.push(L.latLng(shape[i], shape[i + 1]));
63 // data.route.shape.maneuverIndexes links turns to polyline positions
64 // data.route.legs[0].maneuvers is list of turns
66 var mq = data.route.legs[0].maneuvers;
67 for (i = 0; i < mq.length; i++) {
70 var linesegstart, linesegend, lineseg;
71 linesegstart = data.route.shape.maneuverIndexes[i];
72 if (i === mq.length - 1) {
74 linesegend = linesegstart + 1;
76 d = MQ_SPRITE_MAP[s.turnType];
77 linesegend = data.route.shape.maneuverIndexes[i + 1] + 1;
80 for (var j = linesegstart; j < linesegend; j++) {
81 lineseg.push(L.latLng(data.route.shape.shapePoints[j * 2], data.route.shape.shapePoints[j * 2 + 1]));
83 steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance * 1000, lineseg]);
89 distance: data.route.distance * 1000,
101 if (OSM.MAPQUEST_KEY) {
102 OSM.Directions.addEngine(new MapQuestEngine("mapquest_bicycle", "bicycle"), true);
103 OSM.Directions.addEngine(new MapQuestEngine("mapquest_foot", "pedestrian"), true);
104 OSM.Directions.addEngine(new MapQuestEngine("mapquest_car", "fastest"), true);