Merge pull request #2032 from Leaflet/featuregroup-check

Add support for layers lacking Events mixin. Fixes #1962
This commit is contained in:
Vladimir Agafonkin 2013-09-17 14:50:47 -07:00
commit 74a5b4dba7
2 changed files with 13 additions and 1 deletions

View File

@ -47,6 +47,16 @@
expect(fg.hasLayer(marker)).to.be(true);
});
it('supports non-evented layers', function () {
var fg = L.featureGroup(),
g = L.layerGroup();
expect(fg.hasLayer(g)).to.be(false);
fg.addLayer(g);
expect(fg.hasLayer(g)).to.be(true);
});
});
describe('removeLayer', function () {
it('removes the layer passed to it', function () {

View File

@ -15,7 +15,9 @@ L.FeatureGroup = L.LayerGroup.extend({
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);