diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 665ac40d..89412135 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -15,7 +15,18 @@ U.FeatureMixin = { onCommit: function () { // When the layer is a remote layer, we don't want to sync the creation of the // points via the websocket, as the other peers will get them themselves. - if (this.datalayer.isRemoteLayer()) return + if (this.datalayer?.isRemoteLayer()) return + + // The "endEdit" event is triggered at the end of an edition, + // and will trigger the sync. + // In the case of a deletion (or a change of layer), we don't want this + // event triggered to cause a sync event, as it would reintroduce + // deleted features. + // The `._marked_for_deletion` private property is here to track this status. + if (this._marked_for_deletion == true) { + this._marked_for_deletion = false + return + } this.sync.upsert(this.toGeoJSON()) }, @@ -23,13 +34,10 @@ U.FeatureMixin = { return this.toGeoJSON().geometry }, - syncDelete: function () { - this.sync.delete() - }, - initialize: function (map, latlng, options, id) { this.map = map this.sync = map.sync_engine.proxy(this) + this._mark_for_deletion = false if (typeof options === 'undefined') { options = {} @@ -271,14 +279,12 @@ U.FeatureMixin = { } return false }, + del: function (sync) { this.isDirty = true this.map.closePopup() if (this.datalayer) { - this.datalayer.removeLayer(this) - this.disconnectFromDataLayer(this.datalayer) - - if (sync !== false) this.syncDelete() + this.datalayer.removeLayer(this, sync) } }, @@ -321,7 +327,9 @@ U.FeatureMixin = { this.datalayer.isDirty = true this.datalayer.removeLayer(this) } + datalayer.addLayer(this) + this.sync.upsert(this.toGeoJSON()) datalayer.isDirty = true this._redraw() }, @@ -499,6 +507,7 @@ U.FeatureMixin = { onRemove: function (map) { this.parentClass.prototype.onRemove.call(this, map) if (this.map.editedFeature === this) { + this._marked_for_deletion = true this.endEdit() this.map.editPanel.close() } diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 82cbe7dc..810d530d 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -896,8 +896,9 @@ U.DataLayer = L.Evented.extend({ if (this.hasDataLoaded()) this.fire('datachanged') }, - removeLayer: function (feature) { + removeLayer: function (feature, sync) { const id = L.stamp(feature) + if (sync !== false) feature.sync.delete() this.layer.removeLayer(feature) feature.disconnectFromDataLayer(this) this._index.splice(this._index.indexOf(id), 1)