move editing stuff out of Polyline.js into Polyline.Edit.js

This commit is contained in:
Vladimir Agafonkin 2012-12-12 18:24:44 +02:00
parent dea6a349c0
commit 5f467337f6
2 changed files with 23 additions and 26 deletions

View File

@ -220,3 +220,26 @@ L.Handler.PolyEdit = L.Handler.extend({
return map.layerPointToLatLng(p1._add(p2)._divideBy(2));
}
});
L.Polyline.addInitHook(function () {
if (L.Handler.PolyEdit) {
this.editing = new L.Handler.PolyEdit(this);
if (this.options.editable) {
this.editing.enable();
}
}
this.on('add', function () {
if (this.editing && this.editing.enabled()) {
this.editing.addHooks();
}
});
this.on('remove', function () {
if (this.editing && this.editing.enabled()) {
this.editing.removeHooks();
}
});
});

View File

@ -3,15 +3,6 @@ L.Polyline = L.Path.extend({
L.Path.prototype.initialize.call(this, options);
this._latlngs = this._convertLatLngs(latlngs);
// TODO refactor: move to Polyline.Edit.js
if (L.Handler.PolyEdit) {
this.editing = new L.Handler.PolyEdit(this);
if (this.options.editable) {
this.editing.enable();
}
}
},
options: {
@ -90,23 +81,6 @@ L.Polyline = L.Path.extend({
return bounds;
},
// TODO refactor: move to Polyline.Edit.js
onAdd: function (map) {
L.Path.prototype.onAdd.call(this, map);
if (this.editing && this.editing.enabled()) {
this.editing.addHooks();
}
},
onRemove: function (map) {
if (this.editing && this.editing.enabled()) {
this.editing.removeHooks();
}
L.Path.prototype.onRemove.call(this, map);
},
_convertLatLngs: function (latlngs) {
var i, len;
for (i = 0, len = latlngs.length; i < len; i++) {