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 // *** needs to give credit
8 OSM.RoutingEngines.list.push({
9 name: "javascripts.directions.engines.mapquest_bike",
25 12: 2, // right on-ramp
26 13: 8, // left on-ramp
27 14: 2, // right off-ramp
28 15: 8, // left off-ramp
31 18: 1 // straight fork
33 getRoute: function(isFinal,points) {
34 var url="http://open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
35 var from=points[0]; var to=points[points.length-1];
36 url+="&from="+from.join(',');
37 url+="&to="+to.join(',');
38 url+="&routeType=bicycle";
39 //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
40 url+="&manMaps=false";
41 url+="&shapeFormat=raw&generalize=0";
42 this.requestJSONP(url+"&callback=");
44 gotRoute: function(router,data) {
45 // *** what if no route?
48 var shape=data.route.shape.shapePoints;
49 for (var i=0; i<shape.length; i+=2) {
50 poly.push(L.latLng(shape[i],shape[i+1]));
52 router.setPolyline(poly);
54 // data.shape.maneuverIndexes links turns to polyline positions
55 // data.legs[0].maneuvers is list of turns
57 var mq=data.route.legs[0].maneuvers;
58 for (var i=0; i<mq.length; i++) {
60 var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType];
61 steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]);
63 router.setItinerary( { steps: steps });