Leaflet.Editable add options and events to the L.Map
object.
See Editable
events for the list of events fired on the Map.
var map = L.map('map', {
editable: true,
editOptions: {
…
}
});
Option | Type | Default | Description |
---|---|---|---|
editToolsClass |
class
| L.Editable |
Class to be used as vertex, for path editing. |
editable |
boolean
| false |
Whether to create a L.Editable instance at map init. |
editOptions |
hash
| {} |
Options to pass to L.Editable when instantiating. |
EditableMixin
is included to L.Polyline
, L.Polygon
, L.Rectangle
, L.Circle
and L.Marker
. It adds some methods to them.
When editing is enabled, the editor is accessible on the instance with the
editor
property.
Method | Returns | Description |
---|---|---|
enableEdit( |
this.editor |
Enable editing, by creating an editor if not existing, and then calling enable on it. |
editEnabled() |
boolean |
Return true if current instance has an editor attached, and this editor is enabled. |
disableEdit() |
|
Disable editing, also remove the editor property reference. |
toggleEdit() |
|
Enable or disable editing, according to current status. |
Main edition handler. By default, it is attached to the map
as map.editTools
property.
Leaflet.Editable is made to be fully extendable. You have three ways to customize
the behaviour: using options, listening to events, or extending.
Option | Type | Default | Description |
---|---|---|---|
zIndex |
int
| 1000 |
The default zIndex of the editing tools. |
polygonClass |
class
| L.Polygon |
Class to be used when creating a new Polygon. |
polylineClass |
class
| L.Polyline |
Class to be used when creating a new Polyline. |
markerClass |
class
| L.Marker |
Class to be used when creating a new Marker. |
circleMarkerClass |
class
| L.CircleMarker |
Class to be used when creating a new CircleMarker. |
rectangleClass |
class
| L.Rectangle |
Class to be used when creating a new Rectangle. |
circleClass |
class
| L.Circle |
Class to be used when creating a new Circle. |
drawingCSSClass |
string
| 'leaflet-editable-drawing' |
CSS class to be added to the map container while drawing. |
drawingCursor |
const
| 'crosshair' |
Cursor mode set to the map while drawing. |
editLayer |
Layer
| new L.LayerGroup() |
Layer used to store edit tools (vertex, line guide…). |
featuresLayer |
Layer
| new L.LayerGroup() |
Default layer used to store drawn features (Marker, Polyline…). |
polylineEditorClass |
class
| PolylineEditor |
Class to be used as Polyline editor. |
polygonEditorClass |
class
| PolygonEditor |
Class to be used as Polygon editor. |
markerEditorClass |
class
| MarkerEditor |
Class to be used as Marker editor. |
circleMarkerEditorClass |
class
| CircleMarkerEditor |
Class to be used as CircleMarker editor. |
rectangleEditorClass |
class
| RectangleEditor |
Class to be used as Rectangle editor. |
circleEditorClass |
class
| CircleEditor |
Class to be used as Circle editor. |
lineGuideOptions |
hash
| {} |
Options to be passed to the line guides. |
skipMiddleMarkers |
boolean
| false |
Set this to true if you don't want middle markers. |
vertexMarkerClass |
class
| VertexMarker |
Class to be used as vertex, for path editing. |
middleMarkerClass |
class
| VertexMarker |
Class to be used as middle vertex, pulled by the user to create a new point in the middle of a path. |
Event | Data | Description |
---|---|---|
editable:created
| ||
editable:enable
| ||
editable:disable
| ||
editable:editing
| ||
editable:dragstart
| ||
editable:drag
| ||
editable:dragend
|
Event | Data | Description |
---|---|---|
editable:drawing:start
| ||
editable:drawing:end
| ||
editable:drawing:cancel
| ||
editable:drawing:commit
| ||
editable:drawing:mousedown
| ||
editable:drawing:mouseup
| ||
editable:drawing:click
| ||
editable:drawing:move
| ||
editable:drawing:clicked
|
Event | Data | Description |
---|---|---|
editable:vertex:new
| ||
editable:vertex:click
| ||
editable:vertex:clicked
| ||
editable:vertex:rawclick
| ||
editable:vertex:deleted
| ||
editable:vertex:ctrlclick
| ||
editable:vertex:shiftclick
| ||
editable:vertex:metakeyclick
| ||
editable:vertex:altclick
| ||
editable:vertex:contextmenu
| ||
editable:vertex:mousedown
| ||
editable:vertex:mouseover
| ||
editable:vertex:mouseout
| ||
editable:vertex:drag
| ||
editable:vertex:dragstart
| ||
editable:vertex:dragend
|
Event | Data | Description |
---|---|---|
editable:middlemarker:mousedown
|
Event | Data | Description |
---|---|---|
editable:shape:new
| ||
editable:shape:delete
| ||
editable:shape:deleted
|
map.editTools
instance:
map.editTools.startPolyline();
Method | Returns | Description |
---|---|---|
drawing() |
boolean |
Return true if any drawing action is ongoing. |
stopDrawing() |
|
When you need to stop any ongoing drawing, without needing to know which editor is active. |
commitDrawing() |
|
When you need to commit any ongoing drawing, without needing to know which editor is active. |
startPolyline( |
L.Polyline |
Start drawing a Polyline. If latlng is given, a first point will be added. In any case, continuing on user click.
If options is given, it will be passed to the Polyline class constructor. |
startPolygon( |
L.Polygon |
Start drawing a Polygon. If latlng is given, a first point will be added. In any case, continuing on user click.
If options is given, it will be passed to the Polygon class constructor. |
startMarker( |
L.Marker |
Start adding a Marker. If latlng is given, the Marker will be shown first at this point.
In any case, it will follow the user mouse, and will have a final latlng on next click (or touch).
If options is given, it will be passed to the Marker class constructor. |
startCircleMarker( |
L.CircleMarker |
Start adding a CircleMarker. If latlng is given, the CircleMarker will be shown first at this point.
In any case, it will follow the user mouse, and will have a final latlng on next click (or touch).
If options is given, it will be passed to the CircleMarker class constructor. |
startRectangle( |
L.Rectangle |
Start drawing a Rectangle. If latlng is given, the Rectangle anchor will be added. In any case, continuing on user drag.
If options is given, it will be passed to the Rectangle class constructor. |
startCircle( |
L.Circle |
Start drawing a Circle. If latlng is given, the Circle anchor will be added. In any case, continuing on user drag.
If options is given, it will be passed to the Circle class constructor. |
When editing a feature (Marker, Polyline…), an editor is attached to it. This editor basically knows how to handle the edition.
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Editor for Marker.
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Base class for all path editors.
Method | Returns | Description |
---|---|---|
reset() |
|
Rebuild edit elements (Vertex, MiddleMarker, etc.). |
push() |
|
Programmatically add a point while drawing. |
pop() |
L.LatLng or null |
Programmatically remove last point (if any) while drawing. |
newShape( |
|
Add a new shape (Polyline, Polygon) in a multi, and setup up drawing tools to draw it;
if optional latlng is given, start a path at this point. |
deleteShapeAt( |
Array |
Remove a path shape at the given latlng . |
appendShape( |
|
Append a new shape to the Polygon or Polyline. |
prependShape( |
|
Prepend a new shape to the Polygon or Polyline. |
insertShape( |
|
Insert a new shape to the Polygon or Polyline at given index (default is to append). |
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Method | Returns | Description |
---|---|---|
continueBackward( |
|
Set up drawing tools to continue the line backward. |
continueForward( |
|
Set up drawing tools to continue the line forward. |
splitShape( |
|
Split the given latlngs shape at index index and integrate new shape in instance latlngs . |
Method | Returns | Description |
---|---|---|
reset() |
|
Rebuild edit elements (Vertex, MiddleMarker, etc.). |
push() |
|
Programmatically add a point while drawing. |
pop() |
L.LatLng or null |
Programmatically remove last point (if any) while drawing. |
newShape( |
|
Add a new shape (Polyline, Polygon) in a multi, and setup up drawing tools to draw it;
if optional latlng is given, start a path at this point. |
deleteShapeAt( |
Array |
Remove a path shape at the given latlng . |
appendShape( |
|
Append a new shape to the Polygon or Polyline. |
prependShape( |
|
Prepend a new shape to the Polygon or Polyline. |
insertShape( |
|
Insert a new shape to the Polygon or Polyline at given index (default is to append). |
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Method | Returns | Description |
---|---|---|
newHole( |
|
Set up drawing tools for creating a new hole on the Polygon. If the latlng param is given, a first point is created. |
Method | Returns | Description |
---|---|---|
reset() |
|
Rebuild edit elements (Vertex, MiddleMarker, etc.). |
push() |
|
Programmatically add a point while drawing. |
pop() |
L.LatLng or null |
Programmatically remove last point (if any) while drawing. |
newShape( |
|
Add a new shape (Polyline, Polygon) in a multi, and setup up drawing tools to draw it;
if optional latlng is given, start a path at this point. |
deleteShapeAt( |
Array |
Remove a path shape at the given latlng . |
appendShape( |
|
Append a new shape to the Polygon or Polyline. |
prependShape( |
|
Prepend a new shape to the Polygon or Polyline. |
insertShape( |
|
Insert a new shape to the Polygon or Polyline at given index (default is to append). |
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Method | Returns | Description |
---|---|---|
reset() |
|
Rebuild edit elements (Vertex, MiddleMarker, etc.). |
push() |
|
Programmatically add a point while drawing. |
pop() |
L.LatLng or null |
Programmatically remove last point (if any) while drawing. |
newShape( |
|
Add a new shape (Polyline, Polygon) in a multi, and setup up drawing tools to draw it;
if optional latlng is given, start a path at this point. |
deleteShapeAt( |
Array |
Remove a path shape at the given latlng . |
appendShape( |
|
Append a new shape to the Polygon or Polyline. |
prependShape( |
|
Prepend a new shape to the Polygon or Polyline. |
insertShape( |
|
Insert a new shape to the Polygon or Polyline at given index (default is to append). |
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Method | Returns | Description |
---|---|---|
reset() |
|
Rebuild edit elements (Vertex, MiddleMarker, etc.). |
push() |
|
Programmatically add a point while drawing. |
pop() |
L.LatLng or null |
Programmatically remove last point (if any) while drawing. |
newShape( |
|
Add a new shape (Polyline, Polygon) in a multi, and setup up drawing tools to draw it;
if optional latlng is given, start a path at this point. |
deleteShapeAt( |
Array |
Remove a path shape at the given latlng . |
appendShape( |
|
Append a new shape to the Polygon or Polyline. |
prependShape( |
|
Prepend a new shape to the Polygon or Polyline. |
insertShape( |
|
Insert a new shape to the Polygon or Polyline at given index (default is to append). |
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |
Handler for dragging path vertices.
VertexMarker
instance when listening for events like editable:vertex:ctrlclick
.
Method | Returns | Description |
---|---|---|
delete() |
|
Delete a vertex and the related LatLng. |
getIndex() |
int |
Get the index of the current vertex among others of the same LatLngs group. |
getLastIndex() |
int |
Get last vertex index of the LatLngs group of the current vertex. |
getPrevious() |
VertexMarker |
Get the previous VertexMarker in the same LatLngs group. |
getNext() |
VertexMarker |
Get the next VertexMarker in the same LatLngs group. |
split() |
|
Split the vertex LatLngs group at its index, if possible. |
continue() |
|
Continue the vertex LatLngs from this vertex. Only active for first and last vertices of a Polyline. |
Method | Returns | Description |
---|---|---|
cancel() |
|
Cancel any subsequent action. |
Property | Type | Description |
---|---|---|
vertex
|
Property | Type | Description |
---|---|---|
shape
|
Method | Returns | Description |
---|---|---|
cancel() |
|
Cancel any subsequent action. |
Property | Type | Description |
---|---|---|
vertex
|
Method | Returns | Description |
---|---|---|
cancel() |
|
Cancel any subsequent action. |
Property | Type | Description |
---|---|---|
shape
|
Property | Type | Description |
---|---|---|
layer
|
Editor for CircleMarker.
Method | Returns | Description |
---|---|---|
enable() |
this |
Set up the drawing tools for the feature to be editable. |
disable() |
this |
Remove the drawing tools for the feature. |
drawing() |
boolean |
Return true if any drawing action is ongoing with this editor. |