From f96f08fc360cfd29ec579261d93c9862041dd3b9 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 6 Jul 2018 23:05:05 +0200 Subject: [PATCH] Allow to clone markers also cc @deuzeffe --- umap/static/umap/js/umap.features.js | 26 +++++++++++++------------- umap/static/umap/test/Marker.js | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 334bc29c..e35c23b4 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -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; - }, + } }; diff --git a/umap/static/umap/test/Marker.js b/umap/static/umap/test/Marker.js index aec190d7..108d1a0f 100644 --- a/umap/static/umap/test/Marker.js +++ b/umap/static/umap/test/Marker.js @@ -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); + }); + + }); + });