2011-06-10 17:38:24 +08:00
|
|
|
/*
|
2011-12-09 22:35:15 +08:00
|
|
|
* L.FeatureGroup extends L.LayerGroup by introducing mouse events and bindPopup method shared between a group of layers.
|
2011-06-10 17:38:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
L.FeatureGroup = L.LayerGroup.extend({
|
|
|
|
includes: L.Mixin.Events,
|
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
addLayer: function (layer) {
|
2012-07-12 13:01:19 +08:00
|
|
|
if (this._layers[L.Util.stamp(layer)]) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-07-05 19:45:06 +08:00
|
|
|
layer.on('click dblclick mouseover mouseout', this._propagateEvent, this);
|
2012-02-15 19:17:25 +08:00
|
|
|
|
2011-06-10 17:38:24 +08:00
|
|
|
L.LayerGroup.prototype.addLayer.call(this, layer);
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-06-10 21:24:49 +08:00
|
|
|
if (this._popupContent && layer.bindPopup) {
|
|
|
|
layer.bindPopup(this._popupContent);
|
2011-12-09 22:35:15 +08:00
|
|
|
}
|
2012-07-05 19:45:06 +08:00
|
|
|
|
|
|
|
return this;
|
2011-06-10 17:38:24 +08:00
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2012-07-03 07:49:09 +08:00
|
|
|
removeLayer: function (layer) {
|
2012-07-05 19:45:06 +08:00
|
|
|
layer.off('click dblclick mouseover mouseout', this._propagateEvent, this);
|
2012-07-03 07:49:09 +08:00
|
|
|
|
|
|
|
L.LayerGroup.prototype.removeLayer.call(this, layer);
|
|
|
|
|
2012-07-05 19:45:06 +08:00
|
|
|
return this.invoke('unbindPopup');
|
2012-07-03 07:49:09 +08:00
|
|
|
},
|
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
bindPopup: function (content) {
|
2011-06-10 21:24:49 +08:00
|
|
|
this._popupContent = content;
|
2011-12-15 19:25:25 +08:00
|
|
|
return this.invoke('bindPopup', content);
|
|
|
|
},
|
|
|
|
|
|
|
|
setStyle: function (style) {
|
|
|
|
return this.invoke('setStyle', style);
|
2011-06-10 17:38:24 +08:00
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2012-03-04 13:54:50 +08:00
|
|
|
getBounds: function () {
|
|
|
|
var bounds = new L.LatLngBounds();
|
|
|
|
this._iterateLayers(function (layer) {
|
|
|
|
bounds.extend(layer instanceof L.Marker ? layer.getLatLng() : layer.getBounds());
|
|
|
|
}, this);
|
|
|
|
return bounds;
|
|
|
|
},
|
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_propagateEvent: function (e) {
|
2012-02-15 19:17:25 +08:00
|
|
|
e.layer = e.target;
|
2011-06-10 17:38:24 +08:00
|
|
|
e.target = this;
|
2012-02-15 19:17:25 +08:00
|
|
|
|
2011-06-10 17:38:24 +08:00
|
|
|
this.fire(e.type, e);
|
|
|
|
}
|
2011-12-09 22:35:15 +08:00
|
|
|
});
|
2012-07-05 19:45:06 +08:00
|
|
|
|
|
|
|
L.featureGroup = function (layers) {
|
|
|
|
return new L.FeatureGroup(layers);
|
|
|
|
};
|