I am trying to make leaflet markers snap to a grid (e.g. 10px) when dragging. The only method I can think of so far is to re-implement L.Draggable so that the offset calculated in _onMove is rounded to the nearest multiple of the grid size.

Is this the best way to do this? (Will it even work to override it then re-assign it to L.Draggable?)

I have seen plenty of questions about snapping features to another feature, which is relatively easy since you can just listen to dragend and do the snap at the end of the move. In this case I need to snap each 'drag'..

closed as off-topic by PolyGeo May 30 '18 at 11:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Try this leaflet plugin Leaflet.Snap. Easy to install and implement – geomajor56 Jan 4 '18 at 1:22
  • Nope, this will snap to other features. As noted in the question; there is plenty of info about this. I want to snap to a 'grid' (I.e every movement of a marker or feature is forced to land on a grid point, meaning you cant move a feature by less than 5 pixels or whatever the grid size is) – James Jan 15 '18 at 9:14

Browse other questions tagged or ask your own question.