Skip to content

Commit

Permalink
Merge pull request Leaflet#4293 from dr-itz/4285-attribution-text
Browse files Browse the repository at this point in the history
Fix attribution text not removed when Layer is removed from map
  • Loading branch information
mourner committed Mar 2, 2016
2 parents f7d7ad2 + 0af11b0 commit 7ebbd19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 14 additions & 6 deletions spec/suites/control/Control.AttributionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ describe("Control.Attribution", function () {
control = new L.Control.Attribution({
prefix: 'prefix'
}).addTo(map);
map.setView([0, 0], 1);
container = control.getContainer();
});

function dummyLayer() {
var layer = new L.Layer();
layer.onAdd = function () { };
layer.onRemove = function () { };
return layer;
}

it("contains just prefix if no attributions added", function () {
expect(container.innerHTML).to.eql('prefix');
});
Expand Down Expand Up @@ -67,9 +75,9 @@ describe("Control.Attribution", function () {

describe('on layer add/remove', function () {
it('changes text', function () {
var fooLayer = new L.Layer();
var barLayer = new L.Layer();
var bazLayer = new L.Layer();
var fooLayer = dummyLayer();
var barLayer = dummyLayer();
var bazLayer = dummyLayer();
fooLayer.getAttribution = function () { return 'foo'; };
barLayer.getAttribution = function () { return 'bar'; };
bazLayer.getAttribution = function () { return 'baz'; };
Expand All @@ -91,9 +99,9 @@ describe("Control.Attribution", function () {
});

it('keeps count of duplicated attributions', function () {
var fooLayer = new L.Layer();
var fo2Layer = new L.Layer();
var fo3Layer = new L.Layer();
var fooLayer = dummyLayer();
var fo2Layer = dummyLayer();
var fo3Layer = dummyLayer();
fooLayer.getAttribution = function () { return 'foo'; };
fo2Layer.getAttribution = function () { return 'foo'; };
fo3Layer.getAttribution = function () { return 'foo'; };
Expand Down
4 changes: 0 additions & 4 deletions src/layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ L.Map.include({
layer.beforeAdd(this);
}

if (layer.getAttribution && this.attributionControl) {
this.attributionControl.addAttribution(layer.getAttribution());
}

this.whenReady(layer._layerAdd, layer);

return this;
Expand Down

0 comments on commit 7ebbd19

Please sign in to comment.