# Code coverage report for src/layer/LayerGroup.js

## Statements: 59.57% (28 / 47) Branches: 37.5% (6 / 16) Functions: 61.54% (8 / 13) Lines: 60.87% (28 / 46)

All files » src/layer/ » LayerGroup.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114

    1

    7

    7

    7

    7

    7

    7

    7

    2

    2

    2

    2

    3

    3
    3

    1
    1

    2
    2
    2

    2

    1
    1
    1
    1

    1

    1
    5

     /*
     * L.LayerGroup is a class to combine several layers into one so that
     * you can manipulate the group (e.g. add/remove it) as one layer.
     */

    L.LayerGroup = L.Class.extend({
    	initialize: function (layers) {
    		this._layers = {};

    		var i, len;

    		Iif (layers) {
    			for (i = 0, len = layers.length; i < len; i++) {
    				this.addLayer(layers[i]);
    			}
    		}
    	},

    	addLayer: function (layer) {
    		var id = L.stamp(layer);

    		this._layers[id] = layer;

    		Iif (this._map) {
    			this._map.addLayer(layer);
    		}

    		return this;
    	},

    	removeLayer: function (layer) {
    		var id = L.stamp(layer);

    		delete this._layers[id];

    		Iif (this._map) {
    			this._map.removeLayer(layer);
    		}

    		return this;
    	},

    	hasLayer: function (layer) {
    		Iif (!layer) { return false; }

    		var id = L.stamp(layer);
    		return this._layers.hasOwnProperty(id);
    	},

    	clearLayers: function () {
    		this.eachLayer(this.removeLayer, this);
    		return this;
    	},

    	invoke: function (methodName) {
    		var args = Array.prototype.slice.call(arguments, 1),
    		    i, layer;

    		for (i in this._layers) {
    			if (this._layers.hasOwnProperty(i)) {
    				layer = this._layers[i];

    				if (layer[methodName]) {
    					layer[methodName].apply(layer, args);
    				}
    			}
    		}

    		return this;
    	},

    	onAdd: function (map) {
    		this._map = map;
    		this.eachLayer(map.addLayer, map);
    	},

    	onRemove: function (map) {
    		this.eachLayer(map.removeLayer, map);
    		this._map = null;
    	},

    	addTo: function (map) {
    		map.addLayer(this);
    		return this;
    	},

    	eachLayer: function (method, context) {
    		for (var i in this._layers) {
    			Eif (this._layers.hasOwnProperty(i)) {
    				method.call(context, this._layers[i]);
    			}
    		}
    		return this;
    	},

    	getLayers: function () {
    		var layers = [];
    		for (var i in this._layers) {
    			Eif (this._layers.hasOwnProperty(i)) {
    				layers.push(this._layers[i]);
    			}
    		}
    		return layers;
    	},

    	setZIndex: function (zIndex) {
    		return this.invoke('setZIndex', zIndex);
    	}
    });

    L.layerGroup = function (layers) {
    	return new L.LayerGroup(layers);
    };