Disallow adding the same feature twice

This commit is contained in:
Tim Schaub
2014-05-20 10:05:47 -06:00
parent 652f11cefa
commit a2b81d6bd0
2 changed files with 21 additions and 3 deletions

View File

@@ -128,15 +128,18 @@ ol.source.Vector.prototype.addFeatureInternal = function(feature) {
var extent = geometry.getExtent();
this.rBush_.insert(extent, feature);
} else {
this.nullGeometryFeatures_[goog.getUid(feature).toString()] = feature;
this.nullGeometryFeatures_[featureKey] = feature;
}
var id = feature.getId();
if (goog.isDef(id)) {
var sid = id.toString();
goog.asserts.assert(!(goog.isDef(this.idIndex_[sid])));
goog.asserts.assert(!(sid in this.idIndex_),
'Feature with same id already added to the source: ' + id);
this.idIndex_[sid] = feature;
} else {
this.undefIdIndex_[goog.getUid(feature).toString()] = feature;
goog.asserts.assert(!(featureKey in this.undefIdIndex_),
'Feature already added to the source');
this.undefIdIndex_[featureKey] = feature;
}
this.dispatchEvent(
new ol.source.VectorEvent(ol.source.VectorEventType.ADDFEATURE, feature));