2013-02-28 06:10:19 +08:00
|
|
|
|
describe('LayerGroup', function () {
|
2013-12-14 06:51:37 +08:00
|
|
|
|
describe("#hasLayer", function () {
|
|
|
|
|
it("returns false when passed undefined, null, or false", function () {
|
|
|
|
|
var lg = L.layerGroup();
|
|
|
|
|
expect(lg.hasLayer(undefined)).to.equal(false);
|
|
|
|
|
expect(lg.hasLayer(null)).to.equal(false);
|
|
|
|
|
expect(lg.hasLayer(false)).to.equal(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2013-02-28 06:10:19 +08:00
|
|
|
|
describe("#addLayer", function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
it('adds a layer', function () {
|
2013-02-28 06:10:19 +08:00
|
|
|
|
var lg = L.layerGroup(),
|
2015-09-25 18:55:37 +08:00
|
|
|
|
marker = L.marker([0, 0]);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.addLayer(marker)).to.eql(lg);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.hasLayer(marker)).to.be(true);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
2013-12-14 06:51:37 +08:00
|
|
|
|
|
2013-02-28 06:10:19 +08:00
|
|
|
|
describe("#removeLayer", function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
it('removes a layer', function () {
|
2013-02-28 06:10:19 +08:00
|
|
|
|
var lg = L.layerGroup(),
|
2015-09-25 18:55:37 +08:00
|
|
|
|
marker = L.marker([0, 0]);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
|
|
|
|
lg.addLayer(marker);
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.removeLayer(marker)).to.eql(lg);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.hasLayer(marker)).to.be(false);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
2013-12-14 06:51:37 +08:00
|
|
|
|
|
2013-02-28 06:10:19 +08:00
|
|
|
|
describe("#clearLayers", function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
it('removes all layers', function () {
|
2013-02-28 06:10:19 +08:00
|
|
|
|
var lg = L.layerGroup(),
|
2015-09-25 18:55:37 +08:00
|
|
|
|
marker = L.marker([0, 0]);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
|
|
|
|
lg.addLayer(marker);
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.clearLayers()).to.eql(lg);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.hasLayer(marker)).to.be(false);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
2013-12-14 06:51:37 +08:00
|
|
|
|
|
2013-02-28 06:10:19 +08:00
|
|
|
|
describe("#getLayers", function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
it('gets all layers', function () {
|
2013-02-28 06:10:19 +08:00
|
|
|
|
var lg = L.layerGroup(),
|
2015-09-25 18:55:37 +08:00
|
|
|
|
marker = L.marker([0, 0]);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
|
|
|
|
lg.addLayer(marker);
|
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(lg.getLayers()).to.eql([marker]);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
2013-12-14 06:51:37 +08:00
|
|
|
|
|
2013-02-28 06:10:19 +08:00
|
|
|
|
describe("#eachLayer", function () {
|
2013-11-08 05:54:33 +08:00
|
|
|
|
it('iterates over all layers', function () {
|
2013-02-28 06:10:19 +08:00
|
|
|
|
var lg = L.layerGroup(),
|
2015-09-25 18:55:37 +08:00
|
|
|
|
marker = L.marker([0, 0]),
|
|
|
|
|
ctx = {foo: 'bar'};
|
2013-02-28 06:10:19 +08:00
|
|
|
|
|
|
|
|
|
lg.addLayer(marker);
|
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
|
lg.eachLayer(function (layer) {
|
2013-03-02 05:49:20 +08:00
|
|
|
|
expect(layer).to.eql(marker);
|
|
|
|
|
expect(this).to.eql(ctx);
|
2013-02-28 06:10:19 +08:00
|
|
|
|
}, ctx);
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-11-10 20:53:38 +08:00
|
|
|
|
|
|
|
|
|
describe("#toGeoJSON", function () {
|
|
|
|
|
it('should return valid GeoJSON for a layer with a FeatureCollection', function () {
|
|
|
|
|
var geoJSON = {
|
|
|
|
|
"type":"FeatureCollection",
|
|
|
|
|
"features":[
|
|
|
|
|
{
|
|
|
|
|
"type":"Feature",
|
|
|
|
|
"properties":{},
|
|
|
|
|
"geometry": {
|
|
|
|
|
"type":"Point",
|
|
|
|
|
"coordinates": [78.3984375, 56.9449741808516]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var layerGroup = L.layerGroup();
|
|
|
|
|
var layer = L.geoJSON(geoJSON);
|
|
|
|
|
layerGroup.addLayer(layer);
|
|
|
|
|
|
|
|
|
|
L.geoJson(layerGroup.toGeoJSON());
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-02-28 06:10:19 +08:00
|
|
|
|
});
|