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