diff --git a/src/ol/Feature.js b/src/ol/Feature.js index 12cc0d0a40..4efccf3127 100644 --- a/src/ol/Feature.js +++ b/src/ol/Feature.js @@ -57,10 +57,11 @@ import BaseObject, {getChangeEventType} from './Object.js'; * ``` * * @api + * @template {import("./geom/Geometry.js").default} Geometry */ class Feature extends BaseObject { /** - * @param {import("./geom/Geometry.js").default|Object=} opt_geometryOrProperties + * @param {Geometry|Object=} opt_geometryOrProperties * You may pass a Geometry object directly, or an object literal containing * properties. If you pass an object literal, you may include a Geometry * associated with a `geometry` key. @@ -106,7 +107,7 @@ class Feature extends BaseObject { if (opt_geometryOrProperties) { if (typeof /** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry === 'function') { - const geometry = /** @type {import("./geom/Geometry.js").default} */ (opt_geometryOrProperties); + const geometry = /** @type {Geometry} */ (opt_geometryOrProperties); this.setGeometry(geometry); } else { /** @type {Object} */ @@ -140,13 +141,13 @@ class Feature extends BaseObject { * Get the feature's default geometry. A feature may have any number of named * geometries. The "default" geometry (the one that is rendered by default) is * set when calling {@link module:ol/Feature~Feature#setGeometry}. - * @return {import("./geom/Geometry.js").default|undefined} The default geometry for the feature. + * @return {Geometry|undefined} The default geometry for the feature. * @api * @observable */ getGeometry() { return ( - /** @type {import("./geom/Geometry.js").default|undefined} */ (this.get(this.geometryName_)) + /** @type {Geometry|undefined} */ (this.get(this.geometryName_)) ); } @@ -218,7 +219,7 @@ class Feature extends BaseObject { /** * Set the default geometry for the feature. This will update the property * with the name returned by {@link module:ol/Feature~Feature#getGeometryName}. - * @param {import("./geom/Geometry.js").default|undefined} geometry The new geometry. + * @param {Geometry|undefined} geometry The new geometry. * @api * @observable */ diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index c72f777bbe..2e32437502 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -35,12 +35,13 @@ import RBush from '../structs/RBush.js'; * @classdesc * Events emitted by {@link module:ol/source/Vector} instances are instances of this * type. + * @template {import("../geom/Geometry.js").default} Geometry */ export class VectorSourceEvent extends Event { /** * @param {string} type Type. - * @param {import("../Feature.js").default=} opt_feature Feature. + * @param {import("../Feature.js").default=} opt_feature Feature. */ constructor(type, opt_feature) { @@ -48,7 +49,7 @@ export class VectorSourceEvent extends Event { /** * The feature being added or removed. - * @type {import("../Feature.js").default|undefined} + * @type {import("../Feature.js").default|undefined} * @api */ this.feature = opt_feature; @@ -154,8 +155,9 @@ export class VectorSourceEvent extends Event { * by this source are suitable for editing. See {@link module:ol/source/VectorTile~VectorTile} for * vector data that is optimized for rendering. * - * @fires VectorSourceEvent + * @fires VectorSourceEvent * @api + * @template {import("../geom/Geometry.js").default} Geometry */ class VectorSource extends Source { /** @@ -215,7 +217,7 @@ class VectorSource extends Source { /** * @private - * @type {RBush} + * @type {RBush>} */ this.featuresRtree_ = useSpatialIndex ? new RBush() : null; @@ -227,21 +229,21 @@ class VectorSource extends Source { /** * @private - * @type {!Object} + * @type {!Object>} */ this.nullGeometryFeatures_ = {}; /** * A lookup of features by id (the return from feature.getId()). * @private - * @type {!Object} + * @type {!Object>} */ this.idIndex_ = {}; /** * A lookup of features without id (keyed by getUid(feature)). * @private - * @type {!Object} + * @type {!Object>} */ this.undefIdIndex_ = {}; @@ -253,7 +255,7 @@ class VectorSource extends Source { /** * @private - * @type {Collection} + * @type {Collection>} */ this.featuresCollection_ = null; @@ -285,7 +287,7 @@ class VectorSource extends Source { * Note: this also applies if an {@link module:ol/Collection} is used for features, * meaning that if a feature with a duplicate id is added in the collection, it will * be removed from it right away. - * @param {import("../Feature.js").default} feature Feature to add. + * @param {import("../Feature.js").default} feature Feature to add. * @api */ addFeature(feature) { @@ -296,7 +298,7 @@ class VectorSource extends Source { /** * Add a feature without firing a `change` event. - * @param {import("../Feature.js").default} feature Feature. + * @param {import("../Feature.js").default} feature Feature. * @protected */ addFeatureInternal(feature) { @@ -328,7 +330,7 @@ class VectorSource extends Source { /** * @param {string} featureKey Unique identifier for the feature. - * @param {import("../Feature.js").default} feature The feature. + * @param {import("../Feature.js").default} feature The feature. * @private */ setupChangeEvents_(featureKey, feature) { @@ -343,7 +345,7 @@ class VectorSource extends Source { /** * @param {string} featureKey Unique identifier for the feature. - * @param {import("../Feature.js").default} feature The feature. + * @param {import("../Feature.js").default} feature The feature. * @return {boolean} The feature is "valid", in the sense that it is also a * candidate for insertion into the Rtree. * @private @@ -368,7 +370,7 @@ class VectorSource extends Source { /** * Add a batch of features to the source. - * @param {Array} features Features to add. + * @param {Array>} features Features to add. * @api */ addFeatures(features) { @@ -379,7 +381,7 @@ class VectorSource extends Source { /** * Add features without firing a `change` event. - * @param {Array} features Features. + * @param {Array>} features Features. * @protected */ addFeaturesInternal(features) { @@ -420,14 +422,14 @@ class VectorSource extends Source { /** - * @param {!Collection} collection Collection. + * @param {!Collection>} collection Collection. * @private */ bindFeaturesCollection_(collection) { let modifyingCollection = false; listen(this, VectorEventType.ADDFEATURE, /** - * @param {VectorSourceEvent} evt The vector source event + * @param {VectorSourceEvent} evt The vector source event */ function(evt) { if (!modifyingCollection) { @@ -438,7 +440,7 @@ class VectorSource extends Source { }); listen(this, VectorEventType.REMOVEFEATURE, /** - * @param {VectorSourceEvent} evt The vector source event + * @param {VectorSourceEvent} evt The vector source event */ function(evt) { if (!modifyingCollection) { @@ -454,7 +456,7 @@ class VectorSource extends Source { function(evt) { if (!modifyingCollection) { modifyingCollection = true; - this.addFeature(/** @type {import("../Feature.js").default} */ (evt.element)); + this.addFeature(/** @type {import("../Feature.js").default} */ (evt.element)); modifyingCollection = false; } }, this); @@ -465,7 +467,7 @@ class VectorSource extends Source { function(evt) { if (!modifyingCollection) { modifyingCollection = true; - this.removeFeature(/** @type {import("../Feature.js").default} */ (evt.element)); + this.removeFeature(/** @type {import("../Feature.js").default} */ (evt.element)); modifyingCollection = false; } }, this); @@ -518,7 +520,7 @@ class VectorSource extends Source { * stop and the function will return the same value. * Note: this function only iterate through the feature that have a defined geometry. * - * @param {function(import("../Feature.js").default): T} callback Called with each feature + * @param {function(import("../Feature.js").default): T} callback Called with each feature * on the source. Return a truthy value to stop iteration. * @return {T|undefined} The return value from the last call to the callback. * @template T @@ -540,7 +542,7 @@ class VectorSource extends Source { * value. * * @param {import("../coordinate.js").Coordinate} coordinate Coordinate. - * @param {function(import("../Feature.js").default): T} callback Called with each feature + * @param {function(import("../Feature.js").default): T} callback Called with each feature * whose goemetry contains the provided coordinate. * @return {T|undefined} The return value from the last call to the callback. * @template T @@ -571,7 +573,7 @@ class VectorSource extends Source { * features, equivalent to {@link module:ol/source/Vector~VectorSource#forEachFeature #forEachFeature()}. * * @param {import("../extent.js").Extent} extent Extent. - * @param {function(import("../Feature.js").default): T} callback Called with each feature + * @param {function(import("../Feature.js").default): T} callback Called with each feature * whose bounding box intersects the provided extent. * @return {T|undefined} The return value from the last call to the callback. * @template T @@ -595,7 +597,7 @@ class VectorSource extends Source { * {@link module:ol/source/Vector~VectorSource#forEachFeatureInExtent #forEachFeatureInExtent()} method instead. * * @param {import("../extent.js").Extent} extent Extent. - * @param {function(import("../Feature.js").default): T} callback Called with each feature + * @param {function(import("../Feature.js").default): T} callback Called with each feature * whose geometry intersects the provided extent. * @return {T|undefined} The return value from the last call to the callback. * @template T @@ -604,7 +606,7 @@ class VectorSource extends Source { forEachFeatureIntersectingExtent(extent, callback) { return this.forEachFeatureInExtent(extent, /** - * @param {import("../Feature.js").default} feature Feature. + * @param {import("../Feature.js").default} feature Feature. * @return {T|undefined} The return value from the last call to the callback. */ function(feature) { @@ -623,7 +625,7 @@ class VectorSource extends Source { * Get the features collection associated with this source. Will be `null` * unless the source was configured with `useSpatialIndex` set to `false`, or * with an {@link module:ol/Collection} as `features`. - * @return {Collection} The collection of features. + * @return {Collection>} The collection of features. * @api */ getFeaturesCollection() { @@ -633,7 +635,7 @@ class VectorSource extends Source { /** * Get all features on the source in random order. - * @return {Array} Features. + * @return {Array>} Features. * @api */ getFeatures() { @@ -647,7 +649,7 @@ class VectorSource extends Source { } } return ( - /** @type {Array} */ (features) + /** @type {Array>} */ (features) ); } @@ -655,7 +657,7 @@ class VectorSource extends Source { /** * Get all features whose geometry intersects the provided coordinate. * @param {import("../coordinate.js").Coordinate} coordinate Coordinate. - * @return {Array} Features. + * @return {Array>} Features. * @api */ getFeaturesAtCoordinate(coordinate) { @@ -675,7 +677,7 @@ class VectorSource extends Source { * This method is not available when the source is configured with * `useSpatialIndex` set to `false`. * @param {import("../extent.js").Extent} extent Extent. - * @return {Array} Features. + * @return {Array>} Features. * @api */ getFeaturesInExtent(extent) { @@ -689,10 +691,10 @@ class VectorSource extends Source { * This method is not available when the source is configured with * `useSpatialIndex` set to `false`. * @param {import("../coordinate.js").Coordinate} coordinate Coordinate. - * @param {function(import("../Feature.js").default):boolean=} opt_filter Feature filter function. + * @param {function(import("../Feature.js").default):boolean=} opt_filter Feature filter function. * The filter function will receive one argument, the {@link module:ol/Feature feature} * and it should return a boolean value. By default, no filtering is made. - * @return {import("../Feature.js").default} Closest feature. + * @return {import("../Feature.js").default} Closest feature. * @api */ getClosestFeatureToCoordinate(coordinate, opt_filter) { @@ -712,7 +714,7 @@ class VectorSource extends Source { const filter = opt_filter ? opt_filter : TRUE; this.featuresRtree_.forEachInExtent(extent, /** - * @param {import("../Feature.js").default} feature Feature. + * @param {import("../Feature.js").default} feature Feature. */ function(feature) { if (filter(feature)) { @@ -759,7 +761,7 @@ class VectorSource extends Source { * `source.getFeatureById(2)` will return a feature with id `'2'` or `2`. * * @param {string|number} id Feature identifier. - * @return {import("../Feature.js").default} The feature (or `null` if not found). + * @return {import("../Feature.js").default} The feature (or `null` if not found). * @api */ getFeatureById(id) { @@ -803,7 +805,7 @@ class VectorSource extends Source { * @private */ handleFeatureChange_(event) { - const feature = /** @type {import("../Feature.js").default} */ (event.target); + const feature = /** @type {import("../Feature.js").default} */ (event.target); const featureKey = getUid(feature); const geometry = feature.getGeometry(); if (!geometry) { @@ -851,7 +853,7 @@ class VectorSource extends Source { /** * Returns true if the feature is contained within the source. - * @param {import("../Feature.js").default} feature Feature. + * @param {import("../Feature.js").default} feature Feature. * @return {boolean} Has feature. * @api */ @@ -933,7 +935,7 @@ class VectorSource extends Source { * Remove a single feature from the source. If you want to remove all features * at once, use the {@link module:ol/source/Vector~VectorSource#clear #clear()} method * instead. - * @param {import("../Feature.js").default} feature Feature to remove. + * @param {import("../Feature.js").default} feature Feature to remove. * @api */ removeFeature(feature) { @@ -952,7 +954,7 @@ class VectorSource extends Source { /** * Remove feature without firing a `change` event. - * @param {import("../Feature.js").default} feature Feature. + * @param {import("../Feature.js").default} feature Feature. * @protected */ removeFeatureInternal(feature) { @@ -973,7 +975,7 @@ class VectorSource extends Source { /** * Remove a feature from the id index. Called internally when the feature id * may have changed. - * @param {import("../Feature.js").default} feature The feature. + * @param {import("../Feature.js").default} feature The feature. * @return {boolean} Removed the feature from the index. * @private */