+ var html = '<h2><a class="geolink" href="#">' +
+ '<span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') +
+ '</h2><p id="routing_summary">' +
+ I18n.t('javascripts.directions.distance') + ': ' + formatDistance(route.distance) + '. ' +
+ I18n.t('javascripts.directions.time') + ': ' + formatTime(route.time) + '.</p>' +
+ '<table id="turnbyturn" />';
+
+ $('#sidebar_content')
+ .html(html);
+
+ // Add each row
+ var cumulative = 0;
+ route.steps.forEach(function (step) {
+ var ll = step[0],
+ direction = step[1],
+ instruction = step[2],
+ dist = step[3],
+ lineseg = step[4];
+
+ cumulative += dist;
+
+ if (dist < 5) {
+ dist = "";
+ } else if (dist < 200) {
+ dist = Math.round(dist / 10) * 10 + "m";
+ } else if (dist < 1500) {
+ dist = Math.round(dist / 100) * 100 + "m";
+ } else if (dist < 5000) {
+ dist = Math.round(dist / 100) / 10 + "km";
+ } else {
+ dist = Math.round(dist / 1000) + "km";
+ }
+
+ var row = $("<tr class='turn'/>");
+ row.append("<td><div class='direction i" + direction + "'/></td> ");
+ row.append("<td class='instruction'>" + instruction);
+ row.append("<td class='distance'>" + dist);
+
+ row.on('click', function () {
+ popup
+ .setLatLng(ll)
+ .setContent("<p>" + instruction + "</p>")
+ .openOn(map);
+ });
+
+ row.hover(function () {
+ highlight
+ .setLatLngs(lineseg)
+ .addTo(map);
+ }, function () {
+ map.removeLayer(highlight);
+ });
+
+ $('#turnbyturn').append(row);
+ });
+
+ $('#sidebar_content').append('<p id="routing_credit">' +
+ I18n.t('javascripts.directions.instructions.courtesy', {link: chosenEngine.creditline}) +
+ '</p>');
+
+ $('#sidebar_content a.geolink').on('click', function(e) {
+ e.preventDefault();
+ map.removeLayer(polyline);
+ $('#sidebar_content').html('');
+ map.setSidebarOverlaid(true);
+ // TODO: collapse width of sidebar back to previous
+ });
+ });
+ }
+
+ var engines = OSM.Directions.engines;
+
+ engines.sort(function (a, b) {
+ a = I18n.t('javascripts.directions.engines.' + a.id);
+ b = I18n.t('javascripts.directions.engines.' + b.id);
+ return a.localeCompare(b);
+ });
+
+ var select = $('select.routing_engines');
+
+ engines.forEach(function(engine, i) {
+ select.append("<option value='" + i + "'>" + I18n.t('javascripts.directions.engines.' + engine.id) + "</option>");
+ });
+
+ setEngine('osrm_car');
+
+ select.on("change", function (e) {
+ chosenEngine = engines[e.target.selectedIndex];
+ if (map.hasLayer(polyline)) {
+ getRoute();
+ }