Leaflet polyline segment edit
An extension to Leaflet.draw to allow editing large polylines one chunk at the time.
Browsers usually can't handle editing large polylines with Leaflet.Draw. Each vertex creates new elements that must be managed and added the DOM: that leads the browser to freeze with too many points. This extension splits the polyline being edited in many segments that can be edited independently.
Important: this is not a standalone plugin, it requires Leaflet.draw to work.
The plugins works with both L.Polygons (multi or simple, with or without holes) and L.Polylines.
Tested on Leaflet 1.0.0+ branch.
You can use
$ npm install leaflet-polyline-segment-edit
unpkg (you might need to change the version)
Leaflet.Draw and this plugin to your page.
Create and instance of
new L.Edit.PolySegmentEditing(map, geometry, options) and enable it to start editing the geometry.
You can change the segment size and style via options.
var poly = L;var options =segmentSize: 250style:default:weight: 3color: 'tomato'hover:weight: 6color: 'orange'editing:weight: 2color: 'gray';var editor = map poly options;// The segments won't show until the handler is enablededitor;// After all the work is doneeditor;
segmentSize [integer] - The size of each segment. Defaults to
style.default [object] - The default style for the line segments.
style.hover [object] - Style to display when hovered. Useful for showing which part of the geometry is going to be edited.
style.editing [object] - The style of the segment while being edited.
All the styles default to Leaflet.Draw's default style. Check Leaflet's API for examples.
L.Draw.Event.LINESEGMENTEDIT is fired after a vertex is edited.
You can also listen to
This plugin allows polygons with holes to be edited. However, it doesn't enforce the geometry integrity (overlapping holes, holes outside the shell, crossing segments, etc.).
Thanks to gmaps-large-polygons for the inspiration.