Add layerGroup#getLayers and tests. Fixes #1460
This commit is contained in:
parent
b7701d1d86
commit
71d17180c8
@ -47,6 +47,7 @@
|
||||
|
||||
<!-- /layer -->
|
||||
<script type="text/javascript" src="suites/layer/FeatureGroupSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/layer/LayerGroupSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/layer/TileLayerSpec.js"></script>
|
||||
|
||||
<!-- /layer/vector/ -->
|
||||
|
58
spec/suites/layer/LayerGroupSpec.js
Normal file
58
spec/suites/layer/LayerGroupSpec.js
Normal file
@ -0,0 +1,58 @@
|
||||
describe('LayerGroup', function () {
|
||||
describe("#addLayer", function () {
|
||||
it('adds a layer', function() {
|
||||
var lg = L.layerGroup(),
|
||||
marker = L.marker([0, 0]);
|
||||
|
||||
expect(lg.addLayer(marker)).toEqual(lg);
|
||||
|
||||
expect(lg.hasLayer(marker)).toBe(true);
|
||||
});
|
||||
});
|
||||
describe("#removeLayer", function () {
|
||||
it('removes a layer', function() {
|
||||
var lg = L.layerGroup(),
|
||||
marker = L.marker([0, 0]);
|
||||
|
||||
lg.addLayer(marker);
|
||||
expect(lg.removeLayer(marker)).toEqual(lg);
|
||||
|
||||
expect(lg.hasLayer(marker)).toBe(false);
|
||||
});
|
||||
});
|
||||
describe("#clearLayers", function () {
|
||||
it('removes all layers', function() {
|
||||
var lg = L.layerGroup(),
|
||||
marker = L.marker([0, 0]);
|
||||
|
||||
lg.addLayer(marker);
|
||||
expect(lg.clearLayers()).toEqual(lg);
|
||||
|
||||
expect(lg.hasLayer(marker)).toBe(false);
|
||||
});
|
||||
});
|
||||
describe("#getLayers", function () {
|
||||
it('gets all layers', function() {
|
||||
var lg = L.layerGroup(),
|
||||
marker = L.marker([0, 0]);
|
||||
|
||||
lg.addLayer(marker);
|
||||
|
||||
expect(lg.getLayers()).toEqual([marker]);
|
||||
});
|
||||
});
|
||||
describe("#eachLayer", function () {
|
||||
it('iterates over all layers', function() {
|
||||
var lg = L.layerGroup(),
|
||||
marker = L.marker([0, 0]),
|
||||
ctx = { foo: 'bar' };
|
||||
|
||||
lg.addLayer(marker);
|
||||
|
||||
lg.eachLayer(function(layer) {
|
||||
expect(layer).toEqual(marker);
|
||||
expect(this).toEqual(ctx);
|
||||
}, ctx);
|
||||
});
|
||||
});
|
||||
});
|
@ -93,6 +93,16 @@ L.LayerGroup = L.Class.extend({
|
||||
return this;
|
||||
},
|
||||
|
||||
getLayers: function () {
|
||||
var layers = [];
|
||||
for (var i in this._layers) {
|
||||
if (this._layers.hasOwnProperty(i)) {
|
||||
layers.push(this._layers[i]);
|
||||
}
|
||||
}
|
||||
return layers;
|
||||
},
|
||||
|
||||
setZIndex: function (zIndex) {
|
||||
return this.invoke('setZIndex', zIndex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user