]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/routing_engines/cloudmade_foot.js
Parse CloudMade directions
[rails.git] / app / assets / javascripts / routing_engines / cloudmade_foot.js
index 3d047f8ab766862d17b82be65a76797c2ad05738..a2b7bbc9a80d2868cedf65bbee69e2bd3d2c18fe 100644 (file)
@@ -1,10 +1,21 @@
 // CloudMade foot engine
 // *** again, this should be shared from a Cloudmade library somewhere
 // *** this API key is taken from some example code, not for real live use!
+// http://cloudmade.com/documentation/routing
 
 OSM.RoutingEngines.list.push({
        name: 'Foot (CloudMade)',
        draggable: true,
+       CM_SPRITE_MAP: {
+               "C": 1,
+               "TL": 7,
+               "TSLL": 8,
+               "TSHL": 6,
+               "TR": 3,
+               "TSLR": 2,
+               "TSHR": 4,
+               "TU": 5
+       }, // was half expecting to see TLDR in there
        getRoute: function(final,points) {
                var url="http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/";
                var p=[];
@@ -16,11 +27,15 @@ OSM.RoutingEngines.list.push({
                url+="/foot.js";
                this.requestJSONP(url+"?callback=");
        },
-       gotRoute: function(data) {
-               console.log(data);
-               // *** todo
-               // *** will require some degree of refactoring because instruction text is pre-assembled
-               // *** otherwise largely like OSRM (funny that)
+       gotRoute: function(router,data) {
+               router.setPolyline(data.route_geometry);
+               // Assemble instructions
+               var steps=[];
+               for (i=0; i<data.route_instructions.length; i++) {
+                       var s=data.route_instructions[i];
+                       steps.push([data.route_geometry[s[2]], this.CM_SPRITE_MAP[s[7]], s[0], s[1]]);
+               }
+               router.setItinerary({ steps: steps });
        }
 });