2013-07-12 06:13:25 +08:00
|
|
|
|
describe('FeatureGroup', function () {
|
|
|
|
|
var map;
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
map = L.map(document.createElement('div'));
|
|
|
|
|
map.setView([0, 0], 1);
|
|
|
|
|
});
|
2013-02-08 09:44:28 +08:00
|
|
|
|
describe("#_propagateEvent", function () {
|
2013-07-12 06:13:25 +08:00
|
|
|
|
var marker;
|
2013-02-08 09:44:28 +08:00
|
|
|
|
beforeEach(function () {
|
|
|
|
|
marker = L.marker([0, 0]);
|
|
|
|
|
});
|
|
|
|
|
describe("when a Marker is added to multiple FeatureGroups ", function () {
|
|
|
|
|
it("e.layer should be the Marker", function () {
|
|
|
|
|
var fg1 = L.featureGroup(),
|
|
|
|
|
fg2 = L.featureGroup();
|
|
|
|
|
|
|
|
|
|
fg1.addLayer(marker);
|
|
|
|
|
fg2.addLayer(marker);
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
var wasClicked1,
|
|
|
|
|
wasClicked2;
|
|
|
|
|
|
|
|
|
|
fg2.on('click', function (e) {
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(e.layer).to.be(marker);
|
|
|
|
|
expect(e.target).to.be(fg2);
|
2013-11-08 05:54:33 +08:00
|
|
|
|
wasClicked2 = true;
|
2013-02-08 09:44:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fg1.on('click', function (e) {
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(e.layer).to.be(marker);
|
|
|
|
|
expect(e.target).to.be(fg1);
|
2013-11-08 05:54:33 +08:00
|
|
|
|
wasClicked1 = true;
|
2013-02-08 09:44:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
marker.fire('click', { type: 'click' });
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
expect(wasClicked1).to.be(true);
|
|
|
|
|
expect(wasClicked2).to.be(true);
|
2013-02-08 09:44:28 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-07-12 06:13:25 +08:00
|
|
|
|
describe('addLayer', function () {
|
|
|
|
|
it('adds the layer', function () {
|
|
|
|
|
var fg = L.featureGroup(),
|
|
|
|
|
marker = L.marker([0, 0]);
|
|
|
|
|
|
|
|
|
|
expect(fg.hasLayer(marker)).to.be(false);
|
|
|
|
|
|
|
|
|
|
fg.addLayer(marker);
|
|
|
|
|
|
|
|
|
|
expect(fg.hasLayer(marker)).to.be(true);
|
|
|
|
|
});
|
2013-09-18 05:36:05 +08:00
|
|
|
|
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);
|
|
|
|
|
});
|
2013-07-12 06:13:25 +08:00
|
|
|
|
});
|
|
|
|
|
describe('removeLayer', function () {
|
|
|
|
|
it('removes the layer passed to it', function () {
|
|
|
|
|
var fg = L.featureGroup(),
|
|
|
|
|
marker = L.marker([0, 0]);
|
|
|
|
|
|
|
|
|
|
fg.addLayer(marker);
|
|
|
|
|
expect(fg.hasLayer(marker)).to.be(true);
|
|
|
|
|
|
|
|
|
|
fg.removeLayer(marker);
|
|
|
|
|
expect(fg.hasLayer(marker)).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
it('removes the layer passed to it by id', function () {
|
|
|
|
|
var fg = L.featureGroup(),
|
|
|
|
|
marker = L.marker([0, 0]);
|
|
|
|
|
|
|
|
|
|
fg.addLayer(marker);
|
|
|
|
|
expect(fg.hasLayer(marker)).to.be(true);
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
fg.removeLayer(L.stamp(marker));
|
2013-07-12 06:13:25 +08:00
|
|
|
|
expect(fg.hasLayer(marker)).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-02-20 03:21:06 +08:00
|
|
|
|
});
|