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.
This commit is contained in:
Alexis Métaireau 2024-05-09 11:14:43 +02:00
parent e4bcb53c6f
commit 28a359e03f

View file

@ -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