/* * L.FeatureGroup extends L.LayerGroup by introducing mouse events and bindPopup method shared between a group of layers. */ L.FeatureGroup = L.LayerGroup.extend({ includes: L.Mixin.Events, statics: { EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu' }, addLayer: function (layer) { if (this._layers[L.stamp(layer)]) { return this; } layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this); L.LayerGroup.prototype.addLayer.call(this, layer); if (this._popupContent && layer.bindPopup) { layer.bindPopup(this._popupContent); } 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) { this._popupContent = content; return this.invoke('bindPopup', content); }, 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) { e.layer = e.target; e.target = this; this.fire(e.type, e); } }); L.featureGroup = function (layers) { return new L.FeatureGroup(layers); };