Allow to clone markers also
cc @deuzeffe
This commit is contained in:
parent
73b8b60068
commit
f96f08fc36
2 changed files with 29 additions and 13 deletions
|
@ -376,6 +376,11 @@ L.U.FeatureMixin = {
|
|||
callback: this.confirmDelete,
|
||||
context: this,
|
||||
iconCls: 'umap-delete'
|
||||
},
|
||||
{
|
||||
text: L._('Clone this feature'),
|
||||
callback: this.clone,
|
||||
context: this
|
||||
}
|
||||
);
|
||||
return items;
|
||||
|
@ -424,6 +429,13 @@ L.U.FeatureMixin = {
|
|||
|
||||
isMulti: function () {
|
||||
return false;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var layer = this.datalayer.geojsonToFeatures(this.toGeoJSON());
|
||||
layer.isDirty = true;
|
||||
layer.edit();
|
||||
return layer;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -750,11 +762,6 @@ L.U.PathMixin = {
|
|||
|
||||
getContextMenuEditItems: function (e) {
|
||||
var items = L.U.FeatureMixin.getContextMenuEditItems.call(this, e);
|
||||
items.push({
|
||||
text: L._('Clone this feature'),
|
||||
callback: this.clone,
|
||||
context: this
|
||||
});
|
||||
if (this.map.editedFeature && this.isSameClass(this.map.editedFeature) && this.map.editedFeature !== this) {
|
||||
items.push({
|
||||
text: L._('Transfer shape to edited feature'),
|
||||
|
@ -788,14 +795,7 @@ L.U.PathMixin = {
|
|||
isOnScreen: function () {
|
||||
var bounds = this.map.getBounds();
|
||||
return bounds.overlaps(this.getBounds());
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var layer = this.datalayer.geojsonToFeatures(this.toGeoJSON());
|
||||
layer.isDirty = true;
|
||||
layer.edit();
|
||||
return layer;
|
||||
},
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -31,4 +31,20 @@ describe('L.U.Marker', function () {
|
|||
|
||||
});
|
||||
|
||||
describe('#clone', function () {
|
||||
|
||||
it('should clone marker', function () {
|
||||
var layer = new L.U.Marker(this.map, [10, 20], {datalayer: this.datalayer}).addTo(this.datalayer);
|
||||
assert.equal(this.datalayer._index.length, 4);
|
||||
other = layer.clone();
|
||||
assert.ok(this.map.hasLayer(other));
|
||||
assert.equal(this.datalayer._index.length, 5);
|
||||
// Must not be the same reference
|
||||
assert.notEqual(layer._latlng, other._latlng);
|
||||
assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat);
|
||||
assert.equal(L.Util.formatNum(layer._latlng.lng), other._latlng.lng);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue