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

hide panel when routing control has empty waypoints

Open anyayunli opened this issue 8 years ago • 4 comments

If no waypoints specified, the panel will appears as a line. Could we hide it ? screen shot 2017-01-20 at 2 42 17 pm

      var routingControl = L.Routing.control({
          createMarker: function() {
            return null;
          },
          lineOptions: { styles: [{ color: '#2598FF', opacity: 1, weight: 5 }] },
          fitSelectedRoutes: false
        }).addTo(map);

anyayunli avatar Jan 20 '17 22:01 anyayunli

Hi, and thanks for reporting. This is on my todo list, and has even been implemented in the develop branch. Sadly, that branch has diverged a bit too much from master, so given that I don't work actively on LRM at the moment, I don't think I will have time to pick that up any time soon.

You can get a feel for how it was implemented here: https://github.com/perliedman/leaflet-routing-machine/blob/develop/src/control.js#L447

I'll keep this open to remember to fix this. Any help fixing this would of course be very welcome!

perliedman avatar Jan 23 '17 07:01 perliedman

Use map.removeControl(route) .. it worked for me

Himanshu-jd avatar Feb 21 '19 07:02 Himanshu-jd

Use map.removeControl(route) .. it worked for me

can you explain how to use it?

khumam avatar Jun 23 '20 14:06 khumam

Hopefully this will help you

// MAP DIV

// Initialise Map const map = L.map('mapid').setView([51.505, -0.09], 13);

// this will create your routing control const routingControl = map.routing.control({ collapsible: true, show: false, lineOptions: { addWaypoints: false, }, waypoints: [ L.latLng(fromlat, fromlng), L.latLng(tolat, tolong), ], router: map.routing.router({ costing: 'auto' }), }).addTo(map);

// for removing routing controls routingControl.setWaypoints([]); // this will work

// OR this will also work

map.removeControl(routingControl)

Himanshu-jd avatar Jun 23 '20 15:06 Himanshu-jd