Vector source / prevent adding features with duplicate id...
...in the collection. Previously two features with the same id could be pushed manually in the features collection and stay there. This would cause an error when clearing the source. Fixes #6183.
This commit is contained in:
@@ -282,6 +282,9 @@ class VectorSource extends Source {
|
||||
* instead. A feature will not be added to the source if feature with
|
||||
* the same id is already there. The reason for this behavior is to avoid
|
||||
* feature duplication when using bbox or tile loading strategies.
|
||||
* 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.
|
||||
* @api
|
||||
*/
|
||||
@@ -300,6 +303,9 @@ class VectorSource extends Source {
|
||||
const featureKey = getUid(feature);
|
||||
|
||||
if (!this.addToIndex_(featureKey, feature)) {
|
||||
if (this.featuresCollection_) {
|
||||
this.featuresCollection_.remove(feature);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user