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) {
|
2011-06-10 17:38:24 +08:00
|
|
|
this._initEvents(layer);
|
|
|
|
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
|
|
|
}
|
2011-06-10 17:38:24 +08:00
|
|
|
},
|
2011-12-09 22:35:15 +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-09 22:35:15 +08:00
|
|
|
|
2011-06-10 17:38:24 +08:00
|
|
|
for (var i in this._layers) {
|
|
|
|
if (this._layers.hasOwnProperty(i) && this._layers[i].bindPopup) {
|
|
|
|
this._layers[i].bindPopup(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-06-10 17:38:24 +08:00
|
|
|
_events: ['click', 'dblclick', 'mouseover', 'mouseout'],
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_initEvents: function (layer) {
|
2011-06-10 17:38:24 +08:00
|
|
|
for (var i = 0, len = this._events.length; i < len; i++) {
|
|
|
|
layer.on(this._events[i], this._propagateEvent, this);
|
|
|
|
}
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_propagateEvent: function (e) {
|
2011-06-10 17:38:24 +08:00
|
|
|
e.layer = e.target;
|
|
|
|
e.target = this;
|
|
|
|
this.fire(e.type, e);
|
|
|
|
}
|
2011-12-09 22:35:15 +08:00
|
|
|
});
|