perliedman / leaflet-routing-machine

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

addWaypoints in L.Routing.Line is not working #618

Closed mikhail349 closed 3 years ago

mikhail349 commented 3 years ago

I'm trying to render route line like this:

onRouteChanged = (route) => {
          if (this.line) {
                this.map.removeLayer(this.line);
           }
           this.line = L.Routing.line(route);
           this.line.addTo(this.map);
}

It's working, but this line is not draggable to add a new waypoint. What I did wrong?

addWaypoints is true by default, but I also tried to set it this.line = L.Routing.line(route, {addWaypoints: true}); and

this.routing = L.Routing.control({
    //...
    lineOptions : {
        addWaypoints: true
    }        
    //...
}).addTo(this.map);
mikhail349 commented 3 years ago

This helps

this.line.on('linetouched', (e) => {
            if (e.afterIndex < self.routing.getWaypoints().length - 1) {
                self.routing._plan.dragNewWaypoint(e);
            }
        });