perliedman / leaflet-routing-machine

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

Leaflet Routing Line prevent new waypoints can be added while still can firing linetouched event #702

Closed Kaitohooi closed 4 months ago

Kaitohooi commented 4 months ago

I want to prevent the line from adding new waypoints by setting addWaypoints=false, but the linetouched event didn't fire anymore.

routeLine: function(route) {
            const line = L.Routing.line(route, {
                styles: [
                    {
                        color: defaultColor,
                        weight: 5,
                    }
                ],
                extendToWaypoints: false,
                missingRouteTolerance: 100,
                addWaypoints: false,
            });

            line.on("linetouched", function(e) {
                console.log(routeName, "is clicked");
            })

            return line;
        }
Kaitohooi commented 4 months ago

Without setting addWaypoints=false, it will fire.

Kaitohooi commented 4 months ago
line.eachLayer(function(l) {
    l.on("click", function(e) {
        console.log(routeName, "is clicked");
    })
})

I used to fix this, thanks.