perliedman / leaflet-routing-machine

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

Stop Propagation after linetouch event #477

Closed habib-farhan closed 6 years ago

habib-farhan commented 6 years ago

Hi Per,

I am adding waypoint with a click on the map and not with context menu, so when i click on route line to addWaypoints, apparently the map also gets the event and waypoints are added. I tried to do the e.stopPropagation, but I get the error, "its not a funciton". What can i add here to stop event propagation?

_hookEvents: function(l) { l.on('linetouched', function(e) { this._plan.dragNewWaypoint(e); }, this); },

Best, Farhan

perliedman commented 6 years ago

Hi, the problem is that linetouched is an event generated by Leaflet's event system, it is not a DOM event, and as such also does not have the same methods (like stopPropagation, preventDefault, etc.).

Additionally, even if this event was stopped from bubbling, it would not help, since the initial mousedown event would still bubble.

So, in conclusion, the fix is to make sure the handler for mousedown stops propagation.