2 * L.LayerGroup is a class to combine several layers so you can manipulate the group (e.g. add/remove it) as one layer.
5 L
.LayerGroup
= L
.Class
.extend({
6 initialize: function(layers
) {
10 for (var i
= 0, len
= layers
.length
; i
< len
; i
++) {
11 this.addLayer(layers
[i
]);
16 addLayer: function(layer
) {
17 var id
= L
.Util
.stamp(layer
);
18 this._layers
[id
] = layer
;
21 this._map
.addLayer(layer
);
26 removeLayer: function(layer
) {
27 var id
= L
.Util
.stamp(layer
);
28 delete this._layers
[id
];
31 this._map
.removeLayer(layer
);
36 clearLayers: function() {
37 this._iterateLayers(this.removeLayer
, this);
41 onAdd: function(map
) {
43 this._iterateLayers(map
.addLayer
, map
);
46 onRemove: function(map
) {
47 this._iterateLayers(map
.removeLayer
, map
);
51 _iterateLayers: function(method
, context
) {
52 for (var i
in this._layers
) {
53 if (this._layers
.hasOwnProperty(i
)) {
54 method
.call(context
, this._layers
[i
]);