Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-editable

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-editable

Make geometries editable in Leaflet

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.5K
decreased by-8%
Maintainers
1
Weekly downloads
 
Created
Source

# Leaflet.Editable

Make geometries editable in Leaflet.

This is not a plug and play UI, and will not. This is a minimal, lightweight, and fully extendable API to control editing of geometries. So you can easily build your own UI with your own needs and choices.

See the demo UI, an more examples below. This is also the drawing engine behind uMap.

Design keys:

  • only the core needs
  • no UI, instead hooks everywhere needed
  • everything programatically controlable
  • MultiPolygon/MultiPolyline support
  • Polygons' holes support
  • touch support
  • tests

Note: only geojson features are supported for now: Marker, Polyline, Polygon, and MultiPolygon/MultiPolylines (no Rectangle, Circle…)

## Install

You need Leaflet >= 0.7.3, and then include src/Leaflet.Editable.js.

## Quick start

Allow Leaflet.Editable in the map options:

var map = L.map('map', {editable: true});

Then, to start editing an existing feature, call the enableEdit method on it:

var polyline = L.polyline([[43.1, 1.2], [43.2, 1.3],[43.3, 1.2]]).addTo(map);
polyline.enableEdit();

If you want to draw a new line:

map.editTools.startPolyline();  // map.editTools has been created
                                // by passing editable: true option to the map

If you want to continue an existing line:

polyline.editor.continueForward();
// or
polyline.editor.continueBackward();

## Examples

## API

Leaflet.Editable is made to be fully extendable. You have three ways to customize the behaviour: using options, listening to events, or extending.

### L.Map

Leaflet.Editable add options and events to the L.Map object.

#### Options

option namedefaultusage
editablefalseWhether to create a L.Editable instance at map init or not.
editOptions{}Options to pass to L.Editable when instanciating.
Events
event namepropertiesusage
editable:createdlayerFired when a new feature (Marker, Polyline…) has been created.
editable:enablelayerFired when an existing feature is ready to be edited
editable:disablelayerFired when an existing feature is not ready anymore to be edited
editable:editinglayerFired as soon as any change is made to the feature geometry
editable:drawing:startlayerFired when a feature is to be drawn
editable:drawing:endlayerFired when a feature is not drawn anymore
editable:drawing:cancellayerFired when user cancel drawing while a feature is being drawn
editable:drawing:commitlayerFired when user finish drawing a feature
editable:drawing:clicklayerFired when user click while drawing
editable:vertex:ctrlclickoriginalEvent, latlng, vertex, layerFired when a click having ctrlKey is issued on a vertex
editable:vertex:shiftclickoriginalEvent, latlng, vertex, layerFired when a click having shiftKey is issued on a vertex
editable:vertex:altclickoriginalEvent, latlng, vertex, layerFired when a click having altKey is issued on a vertex
editable:vertex:contextmenuoriginalEvent, latlng, vertex, layerFired when a contextmenu is issued on a vertex
editable:vertex:deletedoriginalEvent, latlng, vertex, layerFired after a vertex has been deleted by user
editable:vertex:deletedoriginalEvent, latlng, vertex, layerFired after a vertex has been deleted by user
editable:vertex:dragoriginalEvent, latlng, vertex, layerFired when a vertex is dragged by user
editable:vertex:dragstartoriginalEvent, latlng, vertex, layerFired before a vertex is dragged by user
editable:vertex:dragendoriginalEvent, latlng, vertex, layerFired after a vertex is dragged by user

L.Editable

You will usually have only one instance of L.Editable, and generally the one created automatically at map init: map.editTools. It's the toolbox you will use to create new features, and also the object you will configure with options. Let's see them.

Options

Note: you can pass them when creating a map using the editOptions key.

option namedefaultusage
polylineClassL.PolylineClass to be used when creating a new Polyline
polygonClassL.PolygonClass to be used when creating a new Polygon
markerClassL.MarkerClass to be used when creating a new Marker
drawingCSSClassleaflet-editable-drawingCSS class to be added to the map container while drawing
editLayernew L.LayerGroup()Layer used to store edit tools (vertex, line guide…)
featuresLayernew L.LayerGroup()Default layer used to store drawn features (marker, polyline…)
vertexMarkerClassL.Editable.VertexMarkerClass to be used as vertex, for path editing
middleMarkerClassL.Editable.MiddleMarkerClass to be used as middle vertex, pulled by the user to create a new point in the middle of a path
polylineEditorClassL.Editable.PolylineEditorClass to be used as Polyline editor
polygonEditorClassL.Editable.PolygonEditorClass to be used as Polygon editor
markerEditorClassL.Editable.MarkerEditorClass to be used as Marker editor
lineGuideOptions{}Options to be passed to the line guides
skipMiddleMarkersnullSet this to true if you don't want middle markers
Methods

Those are the public methods. You will generally access them by the map.editTools instance:

map.editTools.startPolyline();
method nameparamsreturnusage
startPolylinelatlng*created L.Polyline instanceStart drawing a polyline. If latlng is given, a first point will be added. In any case, continuing on user click.
startPolygonlatlng*created L.Polygon instanceStart drawing a polygon. If latlng is given, a first point will be added. In any case, continuing on user click.
startMarkerlatlng*created L.Marker instanceStart 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).
stopDrawingWhen you need to stop any ongoing drawing, without needing to know which editor is active.
Events

Same as L.Map.

L.Editable.VertexMarker

The marker used to handle path vertex. You will usually interact with a VertexMarker instance when listening for events like editable:vertex:ctrlclick.

Those are its public methods.

method nameparamsreturnusage
deleteDelete a vertex and the related latlng.
getIndexintGet the index of the current vertex among others of the same LatLngs group.
getLastIndexintGet last vertex index of the LatLngs group of the current vertex.
getPreviousVertexMarker instanceGet the previous VertexMarker in the same LatLngs group.
getNextVertexMarker instanceGet the next VertexMarker in the same LatLngs group.

L.Editable.BaseEditor

When editing a feature (marker, polyline…), an editor is attached to it. This editor basically knows how to handle the edition.

It has some public methods:

method nameparamsreturnusage
enablethisSet up the drawing tools for the feature to be editable.
disablethisRemove editing tools.

L.Editable.MarkerEditor

Inherit from L.Editable.BaseEditor.

L.Editable.PathEditor

Inherit from L.Editable.BaseEditor.

Inherited by L.Editable.PolylineEditor and L.Editable.PolygonEditor.

Interesting new method:

method nameparamsreturnusage
resetRebuild edit elements (vertex, middlemarker, etc.)

### L.Editable.PolylineEditor

Inherit from L.Editable.PathEditor.

Useful specific methods:

method nameparamsreturnusage
continueForwardSet up drawing tools to continue the line forward
continueBackwardSet up drawing tools to continue the line backward

### L.Editable.PolygonEditor

Inherit from L.Editable.PathEditor.

method nameparamsreturnusage
newHolelatlng*Set up drawing tools for creating a new hole on the polygon. If the latlng param is given, a first point is created.

EditableMixin

EditableMixin is included to L.Polyline, L.Polygon and L.Marker. It adds the following methods to them.

When editing is enabled, the editor is accessible on the instance with the editor property.

#### Methods

method nameparamsreturnusage
enableEditrelated editor instanceEnable editing, by creating an editor if not existing, and then calling enable on it
disableEditDisable editing, also remove the editor property reference.
toggleEditEnable or disable editing, according to current status.
editEnabledbooleanReturn true if current instance has an editor attached, and this editor is enabled.
Events

Some events are also fired on the feature itself.

event namepropertiesusage
editable:drawing:startlayerFired when a feature is to be drawn
editable:drawing:endlayerFired when a feature is not drawn anymore
editable:drawing:cancellayerFired when user cancel drawing while a feature is being drawn
editable:drawing:commitlayerFired when user finish drawing a feature
editable:drawing:clicklayerFired when user click while drawing
editable:vertex:ctrlclickoriginalEvent, latlng, vertex, layerFired when a click having ctrlKey is issued on a vertex
editable:vertex:shiftclickoriginalEvent, latlng, vertex, layerFired when a click having shiftKey is issued on a vertex
editable:vertex:altclickoriginalEvent, latlng, vertex, layerFired when a click having altKey is issued on a vertex
editable:vertex:contextmenuoriginalEvent, latlng, vertex, layerFired when a contextmenu is issued on a vertex
editable:vertex:deletedoriginalEvent, latlng, vertex, layerFired after a vertex has been deleted by user

## Licence

Leaflet.Editable is released under the WTFPL licence.

Keywords

FAQs

Package last updated on 05 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc