From 1812ce8b286bc5f54d8d0ddd47b9c31cd4388eab Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:08:00 +0100 Subject: [PATCH 1/5] update source and fire event only if features added --- src/ol/interaction/DragAndDrop.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index 3736e8c633..b41287e2be 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -147,21 +147,21 @@ class DragAndDrop extends Interaction { featureProjection: projection, }); if (features && features.length > 0) { + if (this.source_) { + this.source_.clear(); + this.source_.addFeatures(features); + } + this.dispatchEvent( + new DragAndDropEvent( + DragAndDropEventType.ADD_FEATURES, + file, + features, + projection + ) + ); break; } } - if (this.source_) { - this.source_.clear(); - this.source_.addFeatures(features); - } - this.dispatchEvent( - new DragAndDropEvent( - DragAndDropEventType.ADD_FEATURES, - file, - features, - projection - ) - ); } /** From 21f4d4998b6809c172ce579a6e505b18bd55a54e Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jul 2020 17:02:38 +0100 Subject: [PATCH 2/5] type casting --- src/ol/interaction/DragAndDrop.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index b41287e2be..d5caa1aa39 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -149,13 +149,13 @@ class DragAndDrop extends Interaction { if (features && features.length > 0) { if (this.source_) { this.source_.clear(); - this.source_.addFeatures(features); + this.source_.addFeatures(/** @type {Array} */ (features)); } this.dispatchEvent( new DragAndDropEvent( DragAndDropEventType.ADD_FEATURES, file, - features, + /** @type {Array} */ (features), projection ) ); From 9fb45aa2d2f952799382ae1a244a46a3e7b42c0d Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jul 2020 17:06:52 +0100 Subject: [PATCH 3/5] fix prettier --- src/ol/interaction/DragAndDrop.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index d5caa1aa39..e8f942521a 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -149,7 +149,9 @@ class DragAndDrop extends Interaction { if (features && features.length > 0) { if (this.source_) { this.source_.clear(); - this.source_.addFeatures(/** @type {Array} */ (features)); + this.source_.addFeatures( + /** @type {Array} */ (features) + ); } this.dispatchEvent( new DragAndDropEvent( From f9f90ea766b5ce98500d7426d1474c343eb88a2b Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:16:49 +0100 Subject: [PATCH 4/5] move type cast to tryReadFeatures_ --- src/ol/interaction/DragAndDrop.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index e8f942521a..f3519db365 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -140,24 +140,21 @@ class DragAndDrop extends Interaction { } const formatConstructors = this.formatConstructors_; - let features = []; for (let i = 0, ii = formatConstructors.length; i < ii; ++i) { const format = new formatConstructors[i](); - features = this.tryReadFeatures_(format, result, { + const features = this.tryReadFeatures_(format, result, { featureProjection: projection, }); if (features && features.length > 0) { if (this.source_) { this.source_.clear(); - this.source_.addFeatures( - /** @type {Array} */ (features) - ); + this.source_.addFeatures(features); } this.dispatchEvent( new DragAndDropEvent( DragAndDropEventType.ADD_FEATURES, file, - /** @type {Array} */ (features), + features, projection ) ); @@ -217,11 +214,13 @@ class DragAndDrop extends Interaction { * @param {string} text Text. * @param {import("../format/Feature.js").ReadOptions} options Read options. * @private - * @return {Array} Features. + * @return {Array} Features. */ tryReadFeatures_(format, text, options) { try { - return format.readFeatures(text, options); + return + /** @type {Array} */ + (format.readFeatures(text, options)); } catch (e) { return null; } From 926d740a8e634fa63806eded17e8a00852a678ad Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:24:56 +0100 Subject: [PATCH 5/5] fix syntax of return with typecast --- src/ol/interaction/DragAndDrop.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index f3519db365..e1e839c308 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -218,9 +218,10 @@ class DragAndDrop extends Interaction { */ tryReadFeatures_(format, text, options) { try { - return - /** @type {Array} */ - (format.readFeatures(text, options)); + return ( + /** @type {Array} */ + (format.readFeatures(text, options)) + ); } catch (e) { return null; }