- // Take directions and write them out
- // data = { steps: array of [latlng, sprite number, instruction text, distance in metres, highlightPolyline] }
- // sprite numbers equate to OSRM's route_instructions turn values
- r.setItinerary = function (data) {
- // Create base table
- $("#content").removeClass("overlay-sidebar");
- $('#sidebar_content').empty();
- var html = ('<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;">' +
- '<span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') +
- '</h2><p id="routing_summary">' +
- I18n.t('javascripts.directions.distance') + ': ' + r.formatDistance(data.distance) + '. ' +
- I18n.t('javascripts.directions.time') + ': ' + r.formatTime(data.time) + '.</p>' +
- '<table id="turnbyturn" />').replace(/~/g, "'");
- $('#sidebar_content').html(html);
- // Add each row
- var cumulative = 0;
- for (var i = 0; i < data.steps.length; i++) {
- var step = data.steps[i];
- // Distance
- var dist = step[3];
- 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";
- }
- // Add to table
- var row = $("<tr class='turn'/>");
- row.append("<td class='direction i" + step[1] + "'> ");
- row.append("<td class='instruction'>" + step[2]);
- row.append("<td class='distance'>" + dist);
- with ({ instruction: step[2], ll: step[0], lineseg: step[4] }) {
- row.on('click', function (e) {
- r.clickTurn(instruction, ll);
- });
- row.hover(function (e) {
- r.highlightSegment(lineseg);
- }, function (e) {
- r.unhighlightSegment();
- });
- }
- ;
- $('#turnbyturn').append(row);
- cumulative += step[3];