move editing stuff out of Polyline.js into Polyline.Edit.js
This commit is contained in:
parent
dea6a349c0
commit
5f467337f6
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user