From b342480f3b4c563e5d547b7502d32484c9a50242 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Fri, 4 Apr 2025 11:45:26 -0400 Subject: [PATCH 1/2] fix: explicit batch instead of blindly on add data Co-authored-by: Yohan Boniface --- umap/static/umap/js/modules/data/layer.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index f3e51eac..a742755b 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -327,7 +327,7 @@ export class DataLayer { this.clear() return this._umap.formatter .parse(raw, this.options.remoteData.format) - .then((geojson) => this.fromGeoJSON(geojson)) + .then((geojson) => this.fromGeoJSON(geojson, false)) .catch((error) => { console.debug(error) Alert.error( @@ -460,10 +460,7 @@ export class DataLayer { try { // Do not fail if remote data is somehow invalid, // otherwise the layer becomes uneditable. - this.sync.startBatch() - const features = this.makeFeatures(geojson, sync) - this.sync.commitBatch() - return features + return this.makeFeatures(geojson, sync) } catch (err) { console.debug('Error with DataLayer', this.id) console.error(err) @@ -529,7 +526,11 @@ export class DataLayer { async importRaw(raw, format) { return this._umap.formatter .parse(raw, format) - .then((geojson) => this.addData(geojson)) + .then((geojson) => { + this.sync.startBatch() + this.addData(geojson) + this.sync.commitBatch() + }) .catch((error) => { console.debug(error) Alert.error(translate('Import failed: invalid data')) @@ -926,8 +927,13 @@ export class DataLayer { this.sync.update('options', this.options, oldOptions) } this.empty() - if (this.isRemoteLayer()) this.fetchRemoteData() - else this.addData(geojson) + if (this.isRemoteLayer()) { + this.fetchRemoteData() + } else { + this.sync.startBatch() + this.addData(geojson) + this.sync.commitBatch() + } } }) } From 91c3b098df681ca0c3f671309814b3d524c5fef5 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 4 Apr 2025 18:45:31 +0200 Subject: [PATCH 2/2] wip: return data in DataLayer.importRaw --- umap/static/umap/js/modules/data/layer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index a742755b..febef6dc 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -528,8 +528,9 @@ export class DataLayer { .parse(raw, format) .then((geojson) => { this.sync.startBatch() - this.addData(geojson) + const data = this.addData(geojson) this.sync.commitBatch() + return data }) .catch((error) => { console.debug(error)