Add distance/time summary
authorRichard Fairhurst <richard@systemeD.net>
Sat, 8 Mar 2014 16:14:14 +0000 (16:14 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 8 Mar 2014 16:14:14 +0000 (16:14 +0000)
app/assets/javascripts/routing.js.erb
app/assets/javascripts/routing_engines/graphhopper.js
app/assets/javascripts/routing_engines/mapquest.js
app/assets/javascripts/routing_engines/osrm.js
app/assets/stylesheets/common.css.scss
config/locales/en.yml

index c774928b9346dcb11ed1474adbb08810dfdff18f..42373ef9d7ec740e738a6a0b4738ad17de2f0881 100644 (file)
@@ -194,7 +194,10 @@ OSM.Routing=function(map,name,jqSearch) {
                $('#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') + 
                $('#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><table id="turnbyturn" />').replace(/~/g,"'");
+                         '</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;
                $('#sidebar_content').html(html);
                // Add each row
                var cumulative=0;
@@ -224,6 +227,15 @@ OSM.Routing=function(map,name,jqSearch) {
        r.clickTurn=function(num,latlng) {
                r.popup=L.popup().setLatLng(latlng).setContent("<p>"+(num+1)+"</p>").openOn(r.map);
        };
        r.clickTurn=function(num,latlng) {
                r.popup=L.popup().setLatLng(latlng).setContent("<p>"+(num+1)+"</p>").openOn(r.map);
        };
+       r.formatDistance=function(m) {
+               if      (m < 1000 ) { return Math.round(m) + "m"; }
+               else if (m < 10000) { return (m/1000.0).toFixed(1) + "km"; }
+               else                { return Math.round(m / 1000)  + "km"; }
+       };
+       r.formatTime=function(s) {
+               var d=new Date(s*1000); var h=d.getHours(); var m=d.getMinutes();
+               return h+":"+(m<10 ? '0' : '')+m;
+       };
 
        // Close all routing UI
        
 
        // Close all routing UI
        
index 9762c0fe4f0eb62c1cc25422d6479bb977979be0..5c10433c2d81244fdcd1456684ea1fd15848f3f8 100644 (file)
@@ -44,7 +44,7 @@ GraphHopperEngine.prototype.createConfig = function() {
                 var distInMeter = instr.distances[i];
                 steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]);
             }
                 var distInMeter = instr.distances[i];
                 steps.push([{lat: latlng[0], lng: latlng[1]}, instrCode, instrText, distInMeter]);
             }
-            router.setItinerary({steps: steps});
+            router.setItinerary({ steps: steps, distance: data.route.distance, time: data.route['time']/1000 });
             return true;
         },
         GH_INSTR_MAP: {
             return true;
         },
         GH_INSTR_MAP: {
index bd580da3e34ca602fc45a6099fbccb7f01e004da..3e6e0c3fc8ffc479fe0600e37ba54a53379562f4 100644 (file)
@@ -47,7 +47,7 @@ MapQuestEngine.prototype.createConfig = function() {
                        url+="&"+that.vehicleParam;
                        //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
                        url+="&manMaps=false";
                        url+="&"+that.vehicleParam;
                        //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
                        url+="&manMaps=false";
-                       url+="&shapeFormat=raw&generalize=0";
+                       url+="&shapeFormat=raw&generalize=0&unit=k";
                        this.requestCORS(url);
                },
                gotRoute: function(router,data) {
                        this.requestCORS(url);
                },
                gotRoute: function(router,data) {
@@ -69,7 +69,7 @@ MapQuestEngine.prototype.createConfig = function() {
                                var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType];
                                steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]);
                        }
                                var d=(i==mq.length-1) ? 15: this.MQ_SPRITE_MAP[s.turnType];
                                steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance*1000]);
                        }
-                       router.setItinerary( { steps: steps });
+                       router.setItinerary( { steps: steps, distance: data.route.distance*1000, time: data.route['time'] });
                        return true;
                }
        };
                        return true;
                }
        };
index fde871019917d671f699eb154619412dd74f191b..041f456f0ba9c6a474d42232d3f072149e12d82a 100644 (file)
@@ -46,7 +46,7 @@ OSRMEngine.prototype.createConfig = function() {
                                if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); }
                                steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
                        }
                                if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); }
                                steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
                        }
-                       if (steps.length) router.setItinerary({ steps: steps });
+                       if (steps.length) router.setItinerary({ steps: steps, distance: data.route_summary.total_distance, time: data.route_summary.total_time });
                        return true;
                }
        };
                        return true;
                }
        };
index a8fba1943fa0eee84d150d4e1cadae6185a4c45f..4eefddbe7369a3e9318842e5bb1f8d5520539cf7 100644 (file)
@@ -639,6 +639,10 @@ nav.secondary {
       font-size: 13px;
     }
 
       font-size: 13px;
     }
 
+    p {
+      padding: 0 $lineheight $lineheight/4;
+    }
+
     .icon.close {
       float: right;
       cursor: pointer;
     .icon.close {
       float: right;
       cursor: pointer;
index e5bb7f3f069a170cb91a4293f358e41d896e161f..bb3f542b78a4b63f64aecebe052a24627e2440c1 100644 (file)
@@ -2127,6 +2127,7 @@ en:
         mapquest_foot: "Foot (MapQuest)"
         osrm_car: "Car (OSRM)"
       directions: "Directions"
         mapquest_foot: "Foot (MapQuest)"
         osrm_car: "Car (OSRM)"
       directions: "Directions"
+      distance: "Distance"
       errors:
         no_route: "Couldn't find a route between those two places."
         no_place: "Sorry - couldn't find that place."
       errors:
         no_route: "Couldn't find a route between those two places."
         no_place: "Sorry - couldn't find that place."
@@ -2149,6 +2150,7 @@ en:
         against_oneway: "Go against one-way on "
         end_oneway: "End of one-way on "
         unnamed: "(unnamed)"
         against_oneway: "Go against one-way on "
         end_oneway: "End of one-way on "
         unnamed: "(unnamed)"
+      time: "Time"
   redaction:
     edit:
       description: "Description"
   redaction:
     edit:
       description: "Description"