Parse CloudMade directions

This commit is contained in:
Richard Fairhurst 2014-01-22 18:53:30 +00:00
parent 36ee18b88e
commit 81ebdee185

View file

@ -6,6 +6,16 @@
OSM.RoutingEngines.list.push({ OSM.RoutingEngines.list.push({
name: 'Foot (CloudMade)', name: 'Foot (CloudMade)',
draggable: true, 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) { getRoute: function(final,points) {
var url="http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/"; var url="http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/";
var p=[]; var p=[];
@ -18,10 +28,14 @@ OSM.RoutingEngines.list.push({
this.requestJSONP(url+"?callback="); this.requestJSONP(url+"?callback=");
}, },
gotRoute: function(router,data) { gotRoute: function(router,data) {
console.log(data); router.setPolyline(data.route_geometry);
// *** todo // Assemble instructions
// *** will require some degree of refactoring because instruction text is pre-assembled var steps=[];
// *** otherwise largely like OSRM (funny that) 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 });
} }
}); });