]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/routing.js.erb
Close directions
[rails.git] / app / assets / javascripts / routing.js.erb
index 1f50fa480f44a193bbf7ad6ce95d2a75f242e338..ed95512528c153873555ffae6bd7b18b1616c835 100644 (file)
@@ -10,6 +10,7 @@
        *** click each part
        *** translation (including all alerts and presentation)
        *** export GPX
+       *** URL history (or do we consciously not want to support that?)
 */
 
 var TURN_INSTRUCTIONS=["",
@@ -96,7 +97,7 @@ OSM.Routing=function(map,name,jqSearch) {
        r.setItinerary=function(steps) {
                $("#content").removeClass("overlay-sidebar");
                $('#sidebar_content').empty();
-               var html='<h2><a class="geolink" href="#"><span class="icon close"></span></a>Directions</h2>';
+               var html='<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;"><span class="icon close"></span></a>Directions</h2>'.replace(/~/g,"'");
                html+="<table>";
                for (var i=0; i<steps.length; i++) {
                        var step=steps[i];
@@ -106,16 +107,31 @@ OSM.Routing=function(map,name,jqSearch) {
                        instText+=TURN_INSTRUCTIONS[instCodes[0]];
                        if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
                        if (instCodes[0]!=15) { instText+=step[1] ? "<b>"+step[1]+"</b>" : "(unnamed)"; }
+                       // Distance
+                       var dist=step[2];
+                       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
                        html+="<tr>";
                        html+="<td class='direction i"+instCodes[0]+"'> ";
-                       html+="<td>"+instText;
+                       html+="<td class='instruction'>"+instText;
+                       html+="<td class='distance'>"+dist;
                }
                html+="</table>";
         $('#sidebar_content').html(html);
        };
 
 
+       // Close all routing UI
+       
+       r.close=function() {
+               $("#content").addClass("overlay-sidebar");
+               if (r.polyline) map.removeLayer(r.polyline);
+       };
+
        // Add engines
        
        r.engines=[];