Leaflet/Leaflet.draw — pull request #323 by manleyjster (2014-09-11 21:09:15+00:00)
Title: Enable marker editing

L.EditToolbar.Edit decides how to handle layers based on the layer type. The process goes like this:

* If `layer instanceof L.Marker` is `true`, then L.EditToolbar.Edit does a series of marker-specific editing actions.
* Otherwise, `L.EditToolbar.Edit` does a few style tweaks, then calls `layer.editing.enable()`, delegating the specific editing behavior to the handler for that layer (i.e. `L.Edit.Rectangle`, `L.Edit.Circle`, `L.Edit.Polyline`, etc.). This means that `layer.editing.enable()` is not called if `layer` inherits from `L.Marker`.

This was a problem for me because I have a complex layer, [`L.Illustrate.Textbox`](https://github.com/manleyjster/Leaflet.Illustrate/blob/master/src/core/L.Illustrate.Textbox.js), which inherits from `L.Marker`, but needs to have custom editing behavior.

As I looked at the code for `L.EditToolbar.Edit`, it seemed that the differential handling of layers into based on marker / non-marker type was fairly arbitrary. Furthermore, there were two lengthy marker-specific methods - `_toggleMarkerHighlight` and `_offsetMarker` - in `L.EditToolbar.Edit` that didn't seem to belong to a general-purpose editing class.

I have refactored `L.EditToolbar.Edit` to address these issues, moving marker-specific behavior into a new `L.Edit.Marker` class. This is nice because it makes `layer.editing.enable()` a universal method for turning on editing behavior, regardless of the layer type. As a bonus, it also makes it easy for plugin developers to override the default editing behavior for classes extending `L.Marker`.