Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel marker dragging by pressing the ESCAPE key #687

Open
SuperPat45 opened this issue Feb 9, 2023 · 1 comment
Open

Cancel marker dragging by pressing the ESCAPE key #687

SuperPat45 opened this issue Feb 9, 2023 · 1 comment
Labels

Comments

@SuperPat45
Copy link
Contributor

While we drag an itinerary marker, it would be great to have ability to cancel de move by pressing the ESCAPE key.
In this case, the marker return to its original position (or is deleted for new marker) and the original itinerary is redrawn.

@curtisy1
Copy link
Collaborator

curtisy1 commented Feb 9, 2023

This is a tricky one and might not work with all Leaflet versions, since it's probably undefined behavior but it is possible. You will have to override the createMarker function to save markers in an intermediate array (this is so you know which marker you will be dragging).

Then you need to hook into the marker's dragstart event to save the original position (since it gets mutated on drag)

And finally, define a listener that stops dragging on keydown/keyup. I played around with it in this fiddle. As you can see, when pressing ESC while dragging, the dragend event does not get fired and so the route should not be affected.

Note that this does not incorporate LRM yet but I'm sure you can figure that part out! And if you need help, feel free to ask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants