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

## Statements: 41.38% (12 / 29) Branches: 41.67% (5 / 12) Functions: 30% (3 / 10) Lines: 41.38% (12 / 29)

All files » src/layer/ » FeatureGroup.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

    1

    2

    2

    2

    2

    2

    2
    1

    2

    2

    1
    2

     /*
     * L.FeatureGroup extends L.LayerGroup by introducing mouse events and additional methods
     * shared between a group of interactive layers (like vectors or markers).
     */

    L.FeatureGroup = L.LayerGroup.extend({
    	includes: L.Mixin.Events,

    	statics: {
    		EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu'
    	},

    	addLayer: function (layer) {
    		Iif (this._layers[L.stamp(layer)]) {
    			return this;
    		}

    		layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this);

    		L.LayerGroup.prototype.addLayer.call(this, layer);

    		Iif (this._popupContent && layer.bindPopup) {
    			layer.bindPopup(this._popupContent, this._popupOptions);
    		}

    		return this.fire('layeradd', {layer: layer});
    	},

    	removeLayer: function (layer) {
    		layer.off(L.FeatureGroup.EVENTS, this._propagateEvent, this);

    		L.LayerGroup.prototype.removeLayer.call(this, layer);

    		if (this._popupContent) {
    			this.invoke('unbindPopup');
    		}

    		return this.fire('layerremove', {layer: layer});
    	},

    	bindPopup: function (content, options) {
    		this._popupContent = content;
    		this._popupOptions = options;
    		return this.invoke('bindPopup', content, options);
    	},

    	setStyle: function (style) {
    		return this.invoke('setStyle', style);
    	},

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

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

    	getBounds: function () {
    		var bounds = new L.LatLngBounds();

    		this.eachLayer(function (layer) {
    			bounds.extend(layer instanceof L.Marker ? layer.getLatLng() : layer.getBounds());
    		});

    		return bounds;
    	},

    	_propagateEvent: function (e) {
    		if (!e.layer) {
    			e.layer = e.target;
    		}
    		e.target = this;

    		this.fire(e.type, e);
    	}
    });

    L.featureGroup = function (layers) {
    	return new L.FeatureGroup(layers);
    };