2 // *** this should all be shared from an OSRM library somewhere
3 // *** need to clear hints at some point
5 OSM.RoutingEngines.list.push({
9 getRoute: function(final,points) {
10 var url="http://router.project-osrm.org/viaroute?z=14&output=json";
11 for (var i=0; i<points.length; i++) {
12 var pair=points[i].join(',');
14 if (this._hints[pair]) url+= "&hint="+this._hints[pair];
16 if (final) url+="&instructions=true";
17 this.requestJSONP(url+"&jsonp=");
19 gotRoute: function(router,data) {
20 if (data.status==207) {
21 alert("Couldn't find route between those two places");
25 var line=L.PolylineUtil.decode(data.route_geometry);
26 for (i=0; i<line.length; i++) { line[i].lat/=10; line[i].lng/=10; }
27 router.setPolyline(line);
29 // Assemble instructions
31 for (i=0; i<data.route_instructions.length; i++) {
32 var s=data.route_instructions[i];
33 var instCodes=s[0].split('-');
34 var instText="<b>"+(i+1)+".</b> ";
35 instText+=TURN_INSTRUCTIONS[instCodes[0]];
36 if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
37 if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : "(unnamed)"; }
38 steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
40 router.setItinerary({ steps: steps });