Remove uniqueness constraint check
This commit is contained in:
@@ -135,10 +135,7 @@ ol.source.Vector.prototype.addFeatureInternal = function(feature) {
|
||||
}
|
||||
var id = feature.getId();
|
||||
if (goog.isDef(id)) {
|
||||
var sid = id.toString();
|
||||
goog.asserts.assert(!(sid in this.idIndex_),
|
||||
'Feature with same id already added to the source: ' + id);
|
||||
this.idIndex_[sid] = feature;
|
||||
this.idIndex_[id.toString()] = feature;
|
||||
} else {
|
||||
goog.asserts.assert(!(featureKey in this.undefIdIndex_),
|
||||
'Feature already added to the source');
|
||||
@@ -385,16 +382,12 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) {
|
||||
var sid = id.toString();
|
||||
if (featureKey in this.undefIdIndex_) {
|
||||
delete this.undefIdIndex_[featureKey];
|
||||
goog.asserts.assert(!goog.isDef(this.idIndex_[sid]),
|
||||
'Duplicate feature id: ' + id);
|
||||
this.idIndex_[sid] = feature;
|
||||
} else {
|
||||
if (this.idIndex_[sid] !== feature) {
|
||||
removed = this.removeFromIdIndex_(feature);
|
||||
goog.asserts.assert(removed,
|
||||
'Expected feature to be removed from index');
|
||||
goog.asserts.assert(!(sid in this.idIndex_),
|
||||
'Duplicate feature id: ' + id);
|
||||
this.idIndex_[sid] = feature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,27 +338,25 @@ describe('ol.source.Vector', function() {
|
||||
source = new ol.source.Vector();
|
||||
});
|
||||
|
||||
it('enforces a uniqueness constraint (on add)', function() {
|
||||
it('allows adding feature with the same id', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setId('foo');
|
||||
source.addFeature(feature);
|
||||
var dupe = new ol.Feature();
|
||||
dupe.setId('foo');
|
||||
expect(function() {
|
||||
source.addFeature(dupe);
|
||||
}).to.throwException();
|
||||
source.addFeature(dupe);
|
||||
expect(source.getFeatureById('foo')).to.be(dupe);
|
||||
});
|
||||
|
||||
it('enforces a uniqueness constraint (on change)', function() {
|
||||
it('allows changing feature and set the same id', function() {
|
||||
var foo = new ol.Feature();
|
||||
foo.setId('foo');
|
||||
source.addFeature(foo);
|
||||
var bar = new ol.Feature();
|
||||
bar.setId('bar');
|
||||
source.addFeature(bar);
|
||||
expect(function() {
|
||||
bar.setId('foo');
|
||||
}).to.throwException();
|
||||
bar.setId('foo');
|
||||
expect(source.getFeatureById('foo')).to.be(bar);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user