perliedman / leaflet-routing-machine

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

Doubled waypoints added on existing line click #577

Open LCweb-ita opened 4 years ago

LCweb-ita commented 4 years ago

Hi there, I'm creating a routing system increasing the line at each map click. Everything works fine except when I click on the existing path.

The new route end is properly applied, but also another waypoint is added on the same point. Please check this screenshot to better understand: https://i.imgur.com/Bz1tMjU.png

Here's my router configuration:

` routing_ctrl = L.Routing.control({ waypoints: [ L.latLng( to_save.start[0], to_save.start[1]), L.latLng( to_save.end[0], to_save.end[1]) ], geocoder: L.Control.Geocoder.nominatim(), routeWhileDragging: true, reverseWaypoints: false, fitSelectedRoutes: false,

        routeLine: function(r) {
            var line = L.Routing.line(r, {  
                styles: [{color: 'red', opacity: 0.5, weight: 4}],
            });

            //line.on('linetouched', function(e) {});
            return line;
        },

`

Please note I want to keep the line draggable, so I can't use addWaypoints: false How can I fix it?

Thanks

perliedman commented 4 years ago

Hi, there is currently no mechanism to distinguish a click on the line from a drag: both are, in LRM's perspective, the same thing, it's just that you are dragging the new waypoint zero pixels before dropping it.

I am guessing an option to enforce a minimum drag distance would be one way to solve this. I'd be open to discussing an pull request for such a change, but since I'm not actively working on LRM I will not have the time to do it myself.

LCweb-ita commented 4 years ago

Thanks for the kind answer. I'm a developer too, if you tell me where you track the click/drag (file + line) I can try achieving it.