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 MapQuestEngine = function (vehicleName, vehicleParam, locale) {
7 this.vehicleName = vehicleName;
8 this.vehicleParam = vehicleParam;
14 MapQuestEngine.prototype.createConfig = function () {
17 name: "javascripts.directions.engines.mapquest_" + this.vehicleName.toLowerCase(),
18 creditline: '<a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">',
35 12: 2, // right on-ramp
36 13: 8, // left on-ramp
37 14: 2, // right off-ramp
38 15: 8, // left off-ramp
41 18: 1 // straight fork
44 getRoute: function (isFinal, points) {
45 var url = document.location.protocol + "//open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
47 var to = points[points.length - 1];
48 url += "&from=" + from.join(',');
49 url += "&to=" + to.join(',');
50 url += "&" + that.vehicleParam;
51 //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"
52 url += "&manMaps=false";
53 url += "&shapeFormat=raw&generalize=0&unit=k";
54 this.requestCORS(url);
57 gotRoute: function (router, data) {
58 if (data.info.statuscode != 0) return false;
61 var shape = data.route.shape.shapePoints;
62 for (var i = 0; i < shape.length; i += 2) {
63 poly.push(L.latLng(shape[i], shape[i + 1]));
65 router.setPolyline(poly);
67 // data.route.shape.maneuverIndexes links turns to polyline positions
68 // data.route.legs[0].maneuvers is list of turns
70 var mq = data.route.legs[0].maneuvers;
71 for (var i = 0; i < mq.length; i++) {
74 var linesegstart, linesegend, lineseg;
75 linesegstart = data.route.shape.maneuverIndexes[i];
76 if (i == mq.length - 1) {
78 linesegend = linesegstart + 1;
80 d = this.MQ_SPRITE_MAP[s.turnType];
81 linesegend = data.route.shape.maneuverIndexes[i + 1] + 1;
84 for (var j = linesegstart; j < linesegend; j++) {
85 lineseg.push(L.latLng(data.route.shape.shapePoints[j * 2], data.route.shape.shapePoints[j * 2 + 1]));
87 steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance * 1000, lineseg]);
89 router.setItinerary({ steps: steps, distance: data.route.distance * 1000, time: data.route['time'] });
95 OSM.DirectionsEngines.add(true, new MapQuestEngine("Bicycle", "routeType=bicycle").createConfig());
96 OSM.DirectionsEngines.add(true, new MapQuestEngine("Foot", "routeType=pedestrian").createConfig());
97 OSM.DirectionsEngines.add(true, new MapQuestEngine("Car", "routeType=fastest").createConfig());
98 // can be: routeType=fastest|shortest|pedestrian|multimodal|bicycle