leaflet-routing-machine
leaflet-routing-machine copied to clipboard
Disable adding waypoints and dragging current waypoints
I'm trying to enable/disable the addWaypoints and draggableWaypoints in real time, but it doesn't work. It did work if I define them when creating the control, but that doesn't suit my needs. I need to toggle between the states mid-air. I tried:
this.routeControl.getPlan().this.routeControl.getPlan().options.addWaypoints = false;
this.routeControl.getPlan().this.routeControl.getPlan().options.draggableWaypoints = false;
but it didn't work. I also tried without the "options", directly on the plan itself but still no luck. How do I enable/disable the states without re-creating the routing control?
Hi there, thanks for reporting this!
Actually, I do not think this is possible at the moment. The reason is that the options are checked when the control is created, and listeners are created is adding waypoints is enabled, otherwise not. That means, just changing the options will not add the listeners automatically.
A way to fix this would be to always add the required listeners, and then checking the state of the options inside the listeners instead.
A PR to fix this would be very welcome, I'm not actively working on LRM at the moment, so it will be a while before I can find the time to address this myself.