move type cast to tryReadFeatures_
This commit is contained in:
@@ -140,24 +140,21 @@ class DragAndDrop extends Interaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatConstructors = this.formatConstructors_;
|
const formatConstructors = this.formatConstructors_;
|
||||||
let features = [];
|
|
||||||
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||||
const format = new formatConstructors[i]();
|
const format = new formatConstructors[i]();
|
||||||
features = this.tryReadFeatures_(format, result, {
|
const features = this.tryReadFeatures_(format, result, {
|
||||||
featureProjection: projection,
|
featureProjection: projection,
|
||||||
});
|
});
|
||||||
if (features && features.length > 0) {
|
if (features && features.length > 0) {
|
||||||
if (this.source_) {
|
if (this.source_) {
|
||||||
this.source_.clear();
|
this.source_.clear();
|
||||||
this.source_.addFeatures(
|
this.source_.addFeatures(features);
|
||||||
/** @type {Array<import("../Feature.js").default>} */ (features)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new DragAndDropEvent(
|
new DragAndDropEvent(
|
||||||
DragAndDropEventType.ADD_FEATURES,
|
DragAndDropEventType.ADD_FEATURES,
|
||||||
file,
|
file,
|
||||||
/** @type {Array<import("../Feature.js").default>} */ (features),
|
features,
|
||||||
projection
|
projection
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -217,11 +214,13 @@ class DragAndDrop extends Interaction {
|
|||||||
* @param {string} text Text.
|
* @param {string} text Text.
|
||||||
* @param {import("../format/Feature.js").ReadOptions} options Read options.
|
* @param {import("../format/Feature.js").ReadOptions} options Read options.
|
||||||
* @private
|
* @private
|
||||||
* @return {Array<import("../Feature.js").FeatureLike>} Features.
|
* @return {Array<import("../Feature.js").default>} Features.
|
||||||
*/
|
*/
|
||||||
tryReadFeatures_(format, text, options) {
|
tryReadFeatures_(format, text, options) {
|
||||||
try {
|
try {
|
||||||
return format.readFeatures(text, options);
|
return
|
||||||
|
/** @type {Array<import("../Feature.js").default>} */
|
||||||
|
(format.readFeatures(text, options));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user