Skip to content

Commit

Permalink
Throw if argument to addLayer is not actually a layer (Leaflet#5689)
Browse files Browse the repository at this point in the history
  • Loading branch information
perliedman authored Aug 6, 2017
1 parent ce107a9 commit 54ce147
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/suites/map/MapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54ce147

Please sign in to comment.