lib/leaflet/src/layer/FeatureGroup.js in leaflet-js-0.6.beta4 vs lib/leaflet/src/layer/FeatureGroup.js in leaflet-js-0.7.0
- old
+ new
@@ -5,19 +5,21 @@
L.FeatureGroup = L.LayerGroup.extend({
includes: L.Mixin.Events,
statics: {
- EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu'
+ EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose'
},
addLayer: function (layer) {
if (this.hasLayer(layer)) {
return this;
}
- layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this);
+ if ('on' in layer) {
+ layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this);
+ }
L.LayerGroup.prototype.addLayer.call(this, layer);
if (this._popupContent && layer.bindPopup) {
layer.bindPopup(this._popupContent, this._popupOptions);
@@ -25,10 +27,17 @@
return this.fire('layeradd', {layer: layer});
},
removeLayer: function (layer) {
+ if (!this.hasLayer(layer)) {
+ return this;
+ }
+ if (layer in this._layers) {
+ layer = this._layers[layer];
+ }
+
layer.off(L.FeatureGroup.EVENTS, this._propagateEvent, this);
L.LayerGroup.prototype.removeLayer.call(this, layer);
if (this._popupContent) {
@@ -42,10 +51,19 @@
this._popupContent = content;
this._popupOptions = options;
return this.invoke('bindPopup', content, options);
},
+ openPopup: function (latlng) {
+ // open popup on the first layer
+ for (var id in this._layers) {
+ this._layers[id].openPopup(latlng);
+ break;
+ }
+ return this;
+ },
+
setStyle: function (style) {
return this.invoke('setStyle', style);
},
bringToFront: function () {
@@ -65,14 +83,13 @@
return bounds;
},
_propagateEvent: function (e) {
- if (!e.layer) {
- e.layer = e.target;
- }
- e.target = this;
-
+ e = L.extend({}, e, {
+ layer: e.target,
+ target: this
+ });
this.fire(e.type, e);
}
});
L.featureGroup = function (layers) {