From a172eda242bcfa6e4a6c05b787e744690909bf18 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 26 Jun 2014 17:55:38 +0200 Subject: [PATCH] Remove uniqueness constraint check --- src/ol/source/vectorsource.js | 9 +-------- test/spec/ol/source/vectorsource.test.js | 14 ++++++-------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index c8297d242f..fb9f2d841e 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -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; } } diff --git a/test/spec/ol/source/vectorsource.test.js b/test/spec/ol/source/vectorsource.test.js index 8957fd2305..a8d513851a 100644 --- a/test/spec/ol/source/vectorsource.test.js +++ b/test/spec/ol/source/vectorsource.test.js @@ -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); }); });