From 2396a102822ad06878bc92de3f0785e222484d17 Mon Sep 17 00:00:00 2001 From: danzel Date: Thu, 30 Jan 2014 16:15:03 +1300 Subject: [PATCH] Fix adding and immediately removing a Layer from the map when the map is never initialized --- spec/suites/map/MapSpec.js | 6 ++++++ src/layer/Layer.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 6d846f09..62f6c64c 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -376,6 +376,12 @@ describe("Map", function () { map.removeLayer(layer); }); + it("supports adding and removing a tile layer without initializing the map", function () { + var layer = L.tileLayer("{z}{x}{y}"); + map.addLayer(layer); + map.removeLayer(layer); + }); + describe("when the last tile layer on a map is removed", function () { it("fires a zoomlevelschange event", function () { map.whenReady(function () { diff --git a/src/layer/Layer.js b/src/layer/Layer.js index f7ac7edd..6938300b 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -56,8 +56,8 @@ L.Layer = L.Evented.extend({ this.onRemove(map); } - if (this.getAttribution && this._map.attributionControl) { - this._map.attributionControl.removeAttribution(this.getAttribution()); + if (this.getAttribution && map.attributionControl) { + map.attributionControl.removeAttribution(this.getAttribution()); } if (this.getEvents) {