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:
Olivier Guyot
2019-05-23 11:35:39 +02:00
parent ddb7da3733
commit 442fa907ce
2 changed files with 19 additions and 0 deletions

View File

@@ -719,6 +719,19 @@ describe('ol.source.Vector', function() {
expect(source.getFeatures().length).to.be(0);
});
it('prevents adding two features with a duplicate id in the collection', function() {
source = new VectorSource({
features: new Collection()
});
const feature1 = new Feature();
feature1.setId('1');
const feature2 = new Feature();
feature2.setId('1');
const collection = source.getFeaturesCollection();
collection.push(feature1);
collection.push(feature2);
expect(collection.getLength()).to.be(1);
});
});
describe('with a collection of features plus spatial index', function() {