diff --git a/doc/errors/index.md b/doc/errors/index.md index 5da35ba9ff..e6b14708a8 100644 --- a/doc/errors/index.md +++ b/doc/errors/index.md @@ -220,3 +220,7 @@ The `{-y}` placeholder requires a tile grid with extent. ### 57 At least 2 conditions are required. + +### 58 + +Duplicate item added to a unique collection. For example, it may be that you tried to add the same layer to a map twice. Check for calls to `map.addLayer()` or other places where the map's layer collection is modified. diff --git a/src/ol/collection.js b/src/ol/collection.js index c21bc2f867..d168cb7d16 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -6,6 +6,7 @@ goog.provide('ol.Collection'); goog.require('ol'); +goog.require('ol.AssertionError'); goog.require('ol.CollectionEventType'); goog.require('ol.Object'); goog.require('ol.events.Event'); @@ -256,7 +257,7 @@ ol.Collection.prototype.updateLength_ = function() { ol.Collection.prototype.assertUnique_ = function(elem, opt_except) { for (var i = 0, ii = this.array_.length; i < ii; ++i) { if (this.array_[i] === elem && i !== opt_except) { - throw new Error('Duplicate item added to a unique collection'); + throw new ol.AssertionError(58); } } };