makinacorpus / Leaflet.Snap

Enables snapping of draggable markers to polylines and other layers
https://makinacorpus.github.io/Leaflet.Snap/
MIT License
198 stars 69 forks source link

Self snapping polygon #34

Open Agrinotes opened 8 years ago

Agrinotes commented 8 years ago

First of all, I wanted to thank you for this amazing plugin ! I am currently working with Leaflet Draw, and I wanted to know if Leaflet.Snap can snap vertices from a polygon being drawn. A kind of self-snapping feature ? The idea is to help the user close the polygon by snapping the first point... Any idea how to do this ? Thanks in advance !

mapmeld commented 8 years ago

@Agroscopik in my experience, as you are first drawing the polygon, your mouse is already snapping to the first point? Example using Leaflet.draw and Leaflet.snap: http://asiafoundation.github.io/SnapEditor/ (click the polygon button on the left to start drawing a polygon)

Agrinotes commented 8 years ago

@mapmeld thank you for your answer. In your example you need the mouse to be "exactly" hover the first point to finish drawing the polygon. What I need is something like what they have to draw farming fields in https://farmlogs.com/ Even if your mouse is 15px away from the first point (represented by a square in your example), it "snaps" it. It makes it easier to close the polygon. Do you know if Leaflet Snap can do that ?