perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

Clearing waypoints also leaves 2 blank waypoints. #606

Closed stephan-v closed 4 years ago

stephan-v commented 4 years ago

I am setting leaflet-routing-machine like so:

this.route = Leaflet.Routing.control(options).addTo(this.map);

Now I would like to use the spliceWaypoints method to start manipulating the waypoints. Except when I actually check the waypoints without having set any at all there are already 2 empty waypoints without lat lng attributes inside of the waypoints.

this.route.getWaypoints()

Even when trying to clear the waypoints using:

this.route.setWaypoints([]);

The 2 blank waypoints are still in there.

I understand that from the premise of routing you need 2 waypoints but this makes it really hard to start from a blank slate and dynamically add waypoints using the spliceWaypoints method.

Is this meant to be set up like this or is there a way to still clear up the waypoints? Let's say I would wanna start out with a single waypoint and add more right now there is no way to tell if the first waypoint actually is my own or the default blank waypoint without having to check the lat and lng attributes all the time.

perliedman commented 4 years ago

Yes, this is the intended way, to make sure the user can always enter a start and end waypoint. You would have to check the existence of lat/lng, or just replace the waypoints that are already there.