]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/routing_engines/cloudmade_foot.js
13368d0a2d09475c53693634f95a9c5836a80b5e
[rails.git] / app / assets / javascripts / routing_engines / cloudmade_foot.js
1 // CloudMade foot engine
2 // *** again, this should be shared from a Cloudmade library somewhere
3 // *** this API key is taken from some example code, not for real live use!
4 // http://cloudmade.com/documentation/routing
5
6 OSM.RoutingEngines.list.push({
7         name: "javascripts.directions.engines.cloudmade_foot",
8         creditline: 'Directions courtesy of <a href="http://cloudmade.com/products/routing" target="_blank">Cloudmade</a>',
9         draggable: false,
10         CM_SPRITE_MAP: {
11                 "C": 1,
12                 "TL": 7,
13                 "TSLL": 8,
14                 "TSHL": 6,
15                 "TR": 3,
16                 "TSLR": 2,
17                 "TSHR": 4,
18                 "TU": 5
19         }, // was half expecting to see TLDR in there
20         getRoute: function(isFinal,points) {
21                 var url="http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/";
22                 var p=[];
23                 for (var i=0; i<points.length; i++) {
24                         p.push(points[i][0]);
25                         p.push(points[i][1]);
26                 }
27                 url+=p.join(',');
28                 url+="/foot.js";
29         url+="?lang=" + I18n.currentLocale();
30                 this.requestJSONP(url+"&callback=");
31                 return true;
32         },
33         gotRoute: function(router,data) {
34                 router.setPolyline(data.route_geometry);
35                 // Assemble instructions
36                 var steps=[];
37                 for (i=0; i<data.route_instructions.length; i++) {
38                         var s=data.route_instructions[i];
39                         steps.push([data.route_geometry[s[2]], this.CM_SPRITE_MAP[s[7]], s[0], s[1]]);
40                 }
41                 router.setItinerary({ steps: steps });
42         }
43 });
44