mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
fix(sync): Keep features IDs for Polygons and Lines
It wasn't passed previously, so objects where duplicated.
This commit is contained in:
parent
c6ee25b906
commit
e24173eb9f
2 changed files with 20 additions and 14 deletions
|
@ -26,7 +26,7 @@ class BaseUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
getLayerFromID(layerId) {
|
||||
getDataLayerFromID(layerId) {
|
||||
if (layerId) return this.map.getDataLayerByUmapId(layerId)
|
||||
return this.map.defaultEditDataLayer()
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export class MapUpdater extends BaseUpdater {
|
|||
|
||||
export class DataLayerUpdater extends BaseUpdater {
|
||||
update({ key, metadata, value }) {
|
||||
const datalayer = this.getLayerFromID(metadata.id)
|
||||
const datalayer = this.getDataLayerFromID(metadata.id)
|
||||
console.log('datalayer', datalayer, key, value)
|
||||
this.updateObjectValue(datalayer, key, value)
|
||||
datalayer.render([key])
|
||||
|
@ -64,7 +64,7 @@ export class DataLayerUpdater extends BaseUpdater {
|
|||
**/
|
||||
class FeatureUpdater extends BaseUpdater {
|
||||
getFeatureFromMetadata({ id, layerId }) {
|
||||
const datalayer = this.getLayerFromID(layerId)
|
||||
const datalayer = this.getDataLayerFromID(layerId)
|
||||
return datalayer.getFeatureById(id)
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class FeatureUpdater extends BaseUpdater {
|
|||
|
||||
upsert({ metadata, value }) {
|
||||
let { id, layerId } = metadata
|
||||
const datalayer = this.getLayerFromID(layerId)
|
||||
const datalayer = this.getDataLayerFromID(layerId)
|
||||
let feature = this.getFeatureFromMetadata(metadata, value)
|
||||
feature = datalayer.geometryToFeature({ geometry: value.geometry, id, feature })
|
||||
feature.addTo(datalayer)
|
||||
|
@ -89,7 +89,7 @@ class FeatureUpdater extends BaseUpdater {
|
|||
|
||||
switch (key) {
|
||||
case 'geometry':
|
||||
const datalayer = this.getLayerFromID(metadata.layerId)
|
||||
const datalayer = this.getDataLayerFromID(metadata.layerId)
|
||||
datalayer.geometryToFeature({ geometry: value, id: metadata.id, feature })
|
||||
default:
|
||||
this.updateObjectValue(feature, key, value)
|
||||
|
|
|
@ -1119,20 +1119,25 @@ U.DataLayer = L.Evented.extend({
|
|||
return new U.Marker(this.map, latlng, { geojson: geojson, datalayer: this }, id)
|
||||
},
|
||||
|
||||
_lineToLayer: function (geojson, latlngs) {
|
||||
return new U.Polyline(this.map, latlngs, {
|
||||
geojson: geojson,
|
||||
datalayer: this,
|
||||
color: null,
|
||||
})
|
||||
_lineToLayer: function (geojson, latlngs, id) {
|
||||
return new U.Polyline(
|
||||
this.map,
|
||||
latlngs,
|
||||
{
|
||||
geojson: geojson,
|
||||
datalayer: this,
|
||||
color: null,
|
||||
},
|
||||
id
|
||||
)
|
||||
},
|
||||
|
||||
_polygonToLayer: function (geojson, latlngs) {
|
||||
_polygonToLayer: function (geojson, latlngs, id) {
|
||||
// Ensure no empty hole
|
||||
// for (let i = latlngs.length - 1; i > 0; i--) {
|
||||
// if (!latlngs.slice()[i].length) latlngs.splice(i, 1);
|
||||
// }
|
||||
return new U.Polygon(this.map, latlngs, { geojson: geojson, datalayer: this })
|
||||
return new U.Polygon(this.map, latlngs, { geojson: geojson, datalayer: this }, id)
|
||||
},
|
||||
|
||||
importRaw: function (raw, type) {
|
||||
|
@ -1592,9 +1597,10 @@ U.DataLayer = L.Evented.extend({
|
|||
// TODO Add an index
|
||||
// For now, iterate on all the features.
|
||||
getFeatureById: function (id) {
|
||||
console.log('looking for feature with id ', id)
|
||||
for (const i in this._layers) {
|
||||
let feature = this._layers[i]
|
||||
if (feature.id == id) {
|
||||
if (feature.id === id) {
|
||||
return feature
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue