]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/routing_engines/mapquest_bicycle.js
Reformat string to avoid long line
[rails.git] / app / assets / javascripts / routing_engines / mapquest_bicycle.js
1 // see: 
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
5
6 OSM.RoutingEngines.list.push({
7         name: "javascripts.directions.engines.mapquest_bike",
8         creditline: 'Directions courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">',
9         draggable: false,
10         _hints: {},
11         MQ_SPRITE_MAP: {
12                 0: 1, // straight
13                 1: 2, // slight right
14                 2: 3, // right
15                 3: 4, // sharp right
16                 4: 5, // reverse
17                 5: 6, // sharp left
18                 6: 7, // left
19                 7: 8, // slight left
20                 8: 5, // right U-turn
21                 9: 5, // left U-turn
22                 10: 2, // right merge
23                 11: 8, // left merge
24                 12: 2, // right on-ramp
25                 13: 8, // left on-ramp
26                 14: 2, // right off-ramp
27                 15: 8, // left off-ramp
28                 16: 2, // right fork
29                 17: 8, // left fork
30                 18: 1  // straight fork
31         },
32         getRoute: function(isFinal,points) {
33                 var url="http://open.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluur290anu%2Crl%3Do5-908a0y";
34                 var from=points[0]; var to=points[points.length-1];
35                 url+="&from="+from.join(',');
36                 url+="&to="+to.join(',');
37                 url+="&routeType=bicycle";
38         //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
39                 url+="&manMaps=false";
40                 url+="&shapeFormat=raw&generalize=0";
41                 this.requestJSONP(url+"&callback=");
42         },
43         gotRoute: function(router,data) {
44                 // *** what if no route?
45                 
46                 var poly=[];
47                 var shape=data.route.shape.shapePoints;
48                 for (var i=0; i<shape.length; i+=2) {
49                         poly.push(L.latLng(shape[i],shape[i+1]));
50                 }
51                 router.setPolyline(poly);
52
53                 // data.shape.maneuverIndexes links turns to polyline positions
54                 // data.legs[0].maneuvers is list of turns
55                 var steps=[];
56                 var mq=data.route.legs[0].maneuvers;
57                 for (var i=0; i<mq.length; i++) {
58                         var s=mq[i];
59                         var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType];
60                         steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]);
61                 }
62                 router.setItinerary( { steps: steps });
63         }
64 });