Make VectorSource Options generic

This commit is contained in:
Maximilian Krög
2022-07-30 02:03:31 +02:00
parent 1c1270cba4
commit 217230172b

View File

@@ -72,7 +72,7 @@ export class VectorSourceEvent extends Event {
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {Array<import("../Feature.js").default>|Collection<import("../Feature.js").default>} [features]
* @property {Array<import("../Feature.js").default<Geometry>>|Collection<import("../Feature.js").default<Geometry>>} [features]
* Features. If provided as {@link module:ol/Collection~Collection}, the features in the source
* and the collection will stay in sync.
* @property {import("../format/Feature.js").default} [format] The feature format used by the XHR
@@ -159,6 +159,7 @@ export class VectorSourceEvent extends Event {
* @property {boolean} [wrapX=true] Wrap the world horizontally. For vector editing across the
* -180° and 180° meridians to work properly, this should be set to `false`. The
* resulting geometry coordinates will then exceed the world bounds.
* @template {import("../geom/Geometry.js").default} [Geometry=import("../geom/Geometry.js").default]
*/
/**
@@ -173,7 +174,7 @@ export class VectorSourceEvent extends Event {
*/
class VectorSource extends Source {
/**
* @param {Options} [opt_options] Vector source options.
* @param {Options<Geometry>} [opt_options] Vector source options.
*/
constructor(opt_options) {
const options = opt_options || {};
@@ -296,17 +297,17 @@ class VectorSource extends Source {
*/
this.featuresCollection_ = null;
let collection, features;
/** @type {Collection<import("../Feature.js").default<Geometry>>} */
let collection;
/** @type {Array<import("../Feature.js").default<Geometry>>} */
let features;
if (Array.isArray(options.features)) {
features =
/** @type {Array<import("../Feature.js").default<Geometry>>} */ (
options.features
);
} else if (options.features) {
collection =
/** @type {Collection<import("../Feature.js").default<Geometry>>} */ (
options.features
);
collection = options.features;
features = collection.getArray();
}
if (!useSpatialIndex && collection === undefined) {