Skip to content

leplatrem/Leaflet.Snap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet.Snap

Enables snapping of draggable markers to polylines and other layers !

Check out the demo !

It depends on Leaflet.GeometryUtil.

For Polyline edition snapping it also depends on Leaflet.draw.

If your guide layer contains several thousands for features, adding the LayerIndex is recommended, this plugin takes advantage of the spatial index if it is available.

Usage

  • Add leaflet.snap.js and leaflet.geometryutil.js (optionally leaflet.draw.js for polyline edition)

For markers :

    var guideLayer = ...;

    var marker = L.marker([48.488, 1.395]).addTo(map);
        marker.snapediting = new L.Handler.MarkerSnap(map, marker);
        marker.snapediting.addGuideLayer(guideLayer);
        marker.snapediting.enable();

For polylines (requires Leaflet.draw):

    var polyline = L.polyline(...).addTo(map);
        polyline.snapediting = new L.Handler.PolylineSnap(map, polyline);
        polyline.snapediting.addGuideLayer(guideLayer);
        polyline.snapediting.enable();

Events:

snap ( layer, latlng ) : fired when snapped to layer at latlng

unsnap ( layer ) : fired when unsnapped from layer

CHANGELOG

  • Fix Snaping if guide layer has Leaflet.LayerIndex

TODO

  • Add init hooks to simplify initialization

Authors

Makina Corpus

About

Enables snapping of draggable markers to polylines and other layers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published