//= require leaflet/routing-machine
//= require leaflet/lrm-mapzen

L.easyButton('fa-map-marker', function(btn, map) {
  if (sidebar.isVisible()) {
    sidebar.hide();
  } else {
    $("#sidebar").load("/map/routes", function() {
      sidebar.show();
    });
  }
}).addTo(map);

L.Routing.control({
  waypoints: [
    L.latLng(-15.762023, -47.867114),
    L.latLng(-15.761096, -47.867648)
  ],
  router: L.Routing.mapzen('mapzen-CEq2eYW', {
    costing: 'pedestrian'
  }),
  formatter: new L.Routing.mapzenFormatter()
}).addTo(map);


map.contextmenu.enable();
map.contextmenu.addItem({
  text: 'Rotas a partir daqui',
  callback: routesFromHere
});

map.contextmenu.addItem({
  text: 'Rotas para cá',
  callback: routesToHere
});

function routesFromHere(e) {
  var lat = e.latlng.lat;
  var lng = e.latlng.lng;
  $('#route_origin').val( lat + ", " + lng);
  control.spliceWaypoints(0, 1, e.latlng);
}

function routesToHere(e) {
  $('#route_destination').val(e.latlng);
  control.spliceWaypoints(0, 1, e.latlng);
}

@@ -755,16 +755,47 @@
 re(e) %7B%0A
+  if (sidebar.isVisible()) %7B%0A  
   var la
@@ -814,16 +814,18 @@
 .lat;%0A  
+ 
+ 
 var lng 
@@ -840,16 +840,18 @@
 ng.lng;%0A
+  
   $('#ro
@@ -867,17 +867,16 @@
 n').val(
- 
 lat + %22,
@@ -880,32 +880,34 @@
  %22, %22 + lng);%0A  
+ 
+ 
 control.spliceWa
@@ -935,38 +935,221 @@
 g);%0A
-%7D%0A%0Afunction routesToHere(e) %7B%0A
+  %7D else %7B%0A    $(%22#sidebar%22).load(%22/map/routes%22, function() %7B%0A      sidebar.show();%0A    %7D);%0A  %7D%0A%7D%0A%0Afunction routesToHere(e) %7B%0A  if (sidebar.isVisible()) %7B%0A    var lat = e.latlng.lat;%0A    var lng = e.latlng.lng;%0A  
   $(
@@ -1174,27 +1174,37 @@
 n').val(
-e.
 lat
+ + ', ' + 
 lng);%0A
+  
   contro
@@ -1238,10 +1238,106 @@
 atlng);%0A
+  %7D else %7B%0A    $(%22#sidebar%22).load(%22/map/routes%22, function() %7B%0A      sidebar.show();%0A    %7D);%0A  %7D%0A
 %7D%0A

Fix the visibility of the sidebar with routes