Require that map layers are unique

This commit is contained in:
Tim Schaub
2017-04-11 21:30:20 -06:00
parent d28f50465b
commit 64b3302883
2 changed files with 23 additions and 2 deletions

View File

@@ -54,14 +54,14 @@ ol.layer.Group = function(opt_options) {
if (layers) {
if (Array.isArray(layers)) {
layers = new ol.Collection(layers.slice());
layers = new ol.Collection(layers.slice(), {unique: true});
} else {
ol.asserts.assert(layers instanceof ol.Collection,
43); // Expected `layers` to be an array or an `ol.Collection`
layers = layers;
}
} else {
layers = new ol.Collection();
layers = new ol.Collection(undefined, {unique: true});
}
this.setLayers(layers);

View File

@@ -50,6 +50,27 @@ describe('ol.Map', function() {
});
describe('#addLayer()', function() {
it('adds a layer to the map', function() {
var map = new ol.Map({});
var layer = new ol.layer.Tile();
map.addLayer(layer);
expect(map.getLayers().item(0)).to.be(layer);
});
it('throws if a layer is added twice', function() {
var map = new ol.Map({});
var layer = new ol.layer.Tile();
map.addLayer(layer);
var call = function() {
map.addLayer(layer);
};
expect(call).to.throwException();
});
});
describe('#addInteraction()', function() {
it('adds an interaction to the map', function() {
var map = new ol.Map({});