]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/routing_engines/cloudmade_foot.js
Merge pull request #6 from apmon/jsroute
[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         draggable: false,
9         CM_SPRITE_MAP: {
10                 "C": 1,
11                 "TL": 7,
12                 "TSLL": 8,
13                 "TSHL": 6,
14                 "TR": 3,
15                 "TSLR": 2,
16                 "TSHR": 4,
17                 "TU": 5
18         }, // was half expecting to see TLDR in there
19         getRoute: function(isFinal,points) {
20                 var url="http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/";
21                 var p=[];
22                 for (var i=0; i<points.length; i++) {
23                         p.push(points[i][0]);
24                         p.push(points[i][1]);
25                 }
26                 url+=p.join(',');
27                 url+="/foot.js";
28         url+="?lang=" + I18n.currentLocale();
29                 this.requestJSONP(url+"&callback=");
30         },
31         gotRoute: function(router,data) {
32                 router.setPolyline(data.route_geometry);
33                 // Assemble instructions
34                 var steps=[];
35                 for (i=0; i<data.route_instructions.length; i++) {
36                         var s=data.route_instructions[i];
37                         steps.push([data.route_geometry[s[2]], this.CM_SPRITE_MAP[s[7]], s[0], s[1]]);
38                 }
39                 router.setItinerary({ steps: steps });
40         }
41 });
42