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