Throw if argument to addLayer is not actually a layer (#5689)
Fixes #5225.
This commit is contained in:
parent
ce107a9f1b
commit
54ce147f3d
@ -419,6 +419,13 @@ describe("Map", function () {
|
||||
map.addLayer(layer);
|
||||
});
|
||||
|
||||
it("throws if adding something which is not a layer", function () {
|
||||
var control = L.control.layers();
|
||||
expect(function () {
|
||||
map.addLayer(control);
|
||||
}).to.throwError();
|
||||
});
|
||||
|
||||
describe("When the first layer is added to a map", function () {
|
||||
it("fires a zoomlevelschange event", function () {
|
||||
var spy = sinon.spy();
|
||||
|
@ -155,6 +155,10 @@ Map.include({
|
||||
// @method addLayer(layer: Layer): this
|
||||
// Adds the given layer to the map
|
||||
addLayer: function (layer) {
|
||||
if (!layer._layerAdd) {
|
||||
throw new Error('The provided object is not a Layer.');
|
||||
}
|
||||
|
||||
var id = Util.stamp(layer);
|
||||
if (this._layers[id]) { return this; }
|
||||
this._layers[id] = layer;
|
||||
|
Loading…
Reference in New Issue
Block a user