]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/routing_engines/osrm_car.js
Apparently 'final' is a reserved word in JS...
[rails.git] / app / assets / javascripts / routing_engines / osrm_car.js
index f0c05a8506a9f310c5ee94a2a00eb5e1eac1fbf1..cb80c5615ba3d7fd2e23a5f59aba707c11197a5f 100644 (file)
@@ -6,14 +6,14 @@ OSM.RoutingEngines.list.push({
        name: 'Car (OSRM)',
        draggable: true,
        _hints: {},
-       getRoute: function(final,points) {
+       getRoute: function(isFinal,points) {
                var url="http://router.project-osrm.org/viaroute?z=14&output=json";
                for (var i=0; i<points.length; i++) {
                        var pair=points[i].join(',');
                        url+="&loc="+pair;
                        if (this._hints[pair]) url+= "&hint="+this._hints[pair];
                }
-               if (final) url+="&instructions=true";
+               if (isFinal) url+="&instructions=true";
                this.requestJSONP(url+"&jsonp=");
        },
        gotRoute: function(router,data) {
@@ -21,10 +21,22 @@ OSM.RoutingEngines.list.push({
                        alert("Couldn't find route between those two places");
                        return false;
                }
-               // *** store hints
+               // Draw polyline
                var line=L.PolylineUtil.decode(data.route_geometry);
                for (i=0; i<line.length; i++) { line[i].lat/=10; line[i].lng/=10; }
                router.setPolyline(line);
-               router.setItinerary(data.route_instructions);
+               // *** store hints
+               // Assemble instructions
+               var steps=[];
+               for (i=0; i<data.route_instructions.length; i++) {
+                       var s=data.route_instructions[i];
+                       var instCodes=s[0].split('-');
+                       var instText="<b>"+(i+1)+".</b> ";
+                       instText+=TURN_INSTRUCTIONS[instCodes[0]];
+                       if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
+                       if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : "(unnamed)"; }
+                       steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
+               }
+               if (steps.length) router.setItinerary({ steps: steps });
        }
 });