Add support for layers lacking Events mixin. Fixes #1962

This commit is contained in:
Tom MacWright 2013-09-17 17:36:05 -04:00
parent 6c77fe64c2
commit befc5eb992
2 changed files with 13 additions and 1 deletions

View File

@ -47,6 +47,16 @@
expect(fg.hasLayer(marker)).to.be(true); 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 () { describe('removeLayer', function () {
it('removes the layer passed to it', function () { it('removes the layer passed to it', function () {

View File

@ -15,7 +15,9 @@ L.FeatureGroup = L.LayerGroup.extend({
return this; return this;
} }
if ('on' in layer) {
layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this); layer.on(L.FeatureGroup.EVENTS, this._propagateEvent, this);
}
L.LayerGroup.prototype.addLayer.call(this, layer); L.LayerGroup.prototype.addLayer.call(this, layer);