Require that map layers are unique
This commit is contained in:
@@ -54,14 +54,14 @@ ol.layer.Group = function(opt_options) {
|
|||||||
|
|
||||||
if (layers) {
|
if (layers) {
|
||||||
if (Array.isArray(layers)) {
|
if (Array.isArray(layers)) {
|
||||||
layers = new ol.Collection(layers.slice());
|
layers = new ol.Collection(layers.slice(), {unique: true});
|
||||||
} else {
|
} else {
|
||||||
ol.asserts.assert(layers instanceof ol.Collection,
|
ol.asserts.assert(layers instanceof ol.Collection,
|
||||||
43); // Expected `layers` to be an array or an `ol.Collection`
|
43); // Expected `layers` to be an array or an `ol.Collection`
|
||||||
layers = layers;
|
layers = layers;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
layers = new ol.Collection();
|
layers = new ol.Collection(undefined, {unique: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setLayers(layers);
|
this.setLayers(layers);
|
||||||
|
|||||||
@@ -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() {
|
describe('#addInteraction()', function() {
|
||||||
it('adds an interaction to the map', function() {
|
it('adds an interaction to the map', function() {
|
||||||
var map = new ol.Map({});
|
var map = new ol.Map({});
|
||||||
|
|||||||
Reference in New Issue
Block a user