From befc5eb99295aeac7c45832d76f91aa0160882d7 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 17 Sep 2013 17:36:05 -0400 Subject: [PATCH] Add support for layers lacking Events mixin. Fixes #1962 --- spec/suites/layer/FeatureGroupSpec.js | 10 ++++++++++ src/layer/FeatureGroup.js | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/suites/layer/FeatureGroupSpec.js b/spec/suites/layer/FeatureGroupSpec.js index fd875e8d..f160a1fe 100644 --- a/spec/suites/layer/FeatureGroupSpec.js +++ b/spec/suites/layer/FeatureGroupSpec.js @@ -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 () { diff --git a/src/layer/FeatureGroup.js b/src/layer/FeatureGroup.js index 83bc1179..3e4aaf08 100644 --- a/src/layer/FeatureGroup.js +++ b/src/layer/FeatureGroup.js @@ -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);