Merge pull request #11300 from mike-000/patch-2
Drag and Drop to update source and fire event only if features added
This commit is contained in:
@@ -140,28 +140,27 @@ 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(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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,11 +214,14 @@ class DragAndDrop extends Interaction {
|
||||
* @param {string} text Text.
|
||||
* @param {import("../format/Feature.js").ReadOptions} options Read options.
|
||||
* @private
|
||||
* @return {Array<import("../Feature.js").FeatureLike>} Features.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
tryReadFeatures_(format, text, options) {
|
||||
try {
|
||||
return format.readFeatures(text, options);
|
||||
return (
|
||||
/** @type {Array<import("../Feature.js").default>} */
|
||||
(format.readFeatures(text, options))
|
||||
);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user