leaflet-routing-machine icon indicating copy to clipboard operation
leaflet-routing-machine copied to clipboard

"Show: false" not hiding itinerary

Open Jadamae77 opened this issue 5 years ago • 3 comments

I have looked and looked through the other issues and tried multiple things and I cannot get the itinerary instructions hidden. I have tried setting show to false in the options, calling .hide() on the control (the leaflet-routing-container-hide class is added to the div but the styles don't change) and I have also tried adding CSS to hide the div, but my style properties don't even show up in the browser devtools. The itinerary is always displayed. Any help would be appreciated.

TS


  setRoute(coordinates: Coordinates[]) {
    const waypoints: L.LatLng[] = [];
    coordinates.forEach((coords) => {
      waypoints.push(L.latLng(coords.lat, coords.lng));
    });
    const route = L.Routing.control({
      waypoints,
      plan: L.Routing.plan(waypoints, {
        createMarker: (i, waypoint, n) => {
          return L.marker(waypoint.latLng, {
            icon: this.icon,
          });
        },
      }),
      routeWhileDragging: true,
      router: new L.Routing.OSRMv1({ serviceUrl: mapConfigs.osrmUrl }),
      show: false,
    });
    route.addTo(this.map);
    // route.hide();
  }

CSS tried

 div.leaflet-routing-alternatives-container {
  display: none !important;
} 

.leaflet-routing-container {
  display: none;
} 

Jadamae77 avatar Sep 14 '20 15:09 Jadamae77

Hi, @Jadamae77! I have faced the same issue by trying to use show: false without success.

However, I managed to hide the itinerary using CSS:

.leaflet-control-container .leaflet-routing-container-hide {
  display: none;
}

Hope it helps!

laurokirsch avatar Oct 28 '20 03:10 laurokirsch

@laurokirsch thanks!

For anyone else having the same issue, this works as well.

div.leaflet-top.leaflet-right{ display: none !important; width: 0px !important; height: 0px !important; }

Jadamae77 avatar Nov 02 '20 15:11 Jadamae77

This works for me, however this is a js way not css:

First - you need a variable to store control, in my example: var control = L.Routing.control({ ... })

then you can hide panel using: control.hide();

or later show again: control.show();

or delete whole routing: map.removeControl(control);

assuming map is your map, and control is your control variable.

Please taka a look at my live example: https://jsfiddle.net/b81vu029/2/

Hope that helps / works for you.

tikky avatar Jan 04 '21 10:01 tikky