From 28a359e03f8e0c4b228679cb9f21c50ad5f9ee6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 9 May 2024 11:14:43 +0200 Subject: [PATCH] fix(sync): Allow cloning of features Removing the `id` from the feature when cloning makes it generate a new one. Without this change, the cloned feature keep the already existing `id`, and during sync, the original object is lost (replaced by the clone). Nobody wants to be replaced by a clone. --- umap/static/umap/js/umap.features.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index e8834a2a..c137173f 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -595,7 +595,10 @@ U.FeatureMixin = { }, clone: function () { - const layer = this.datalayer.geojsonToFeatures(this.toGeoJSON()) + const geoJSON = this.toGeoJSON() + delete geoJSON.id + delete geoJSON.properties.id + const layer = this.datalayer.geojsonToFeatures(geoJSON) layer.isDirty = true layer.edit() return layer @@ -652,7 +655,7 @@ U.Marker = L.Marker.extend({ }, this ) - this.on('editable:drawing:end', this.onCommit) + this.on('editable:drawing:commit', this.onCommit) if (!this.isReadOnly()) this.on('mouseover', this._enableDragging) this.on('mouseout', this._onMouseOut) this._popupHandlersAdded = true // prevent Leaflet from binding event on bindPopup @@ -1275,6 +1278,8 @@ U.Polygon = L.Polygon.extend({ toPolyline: function () { const geojson = this.toGeoJSON() + delete geojson.id + delete geojson.properties.id geojson.geometry.type = 'LineString' geojson.geometry.coordinates = U.Utils.flattenCoordinates( geojson.geometry.coordinates