Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removing canvas bug (#6030) #6033

Merged
merged 1 commit into from Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions spec/suites/layer/vector/CanvasSpec.js
Expand Up @@ -190,3 +190,49 @@ describe('Canvas', function () {
});

});

describe('Canvas remove', function () {

var c;

before(function () {
c = document.createElement('div');
c.style.width = '400px';
c.style.height = '400px';
c.style.position = 'absolute';
c.style.top = '0';
c.style.left = '0';
document.body.appendChild(c);
});

after(function () {
document.body.removeChild(c);
});

function createCanvasMap(c, options) {
var map = new L.Map(c, options);
map.setView([0, 0], 6);
var p2ll = function (x, y) {
return map.layerPointToLatLng([x, y]);
};
var latLngs = [p2ll(0, 0), p2ll(0, 100), p2ll(100, 100), p2ll(100, 0)];
var layer = L.polygon(latLngs).addTo(map);
return map;
}

it("can remove the map without errors", function (done) {
var map1 = createCanvasMap(c, {preferCanvas: true, zoomControl: false});
map1.remove();
L.Util.requestAnimFrame(function () { done(); });
});

it("can remove renderer without errors", function (done) {
var canvas = L.canvas();
var map = createCanvasMap(c, {renderer: canvas, zoomControl: false});
canvas.remove();
map.remove();
L.Util.requestAnimFrame(function () { done(); });
});

});

1 change: 1 addition & 0 deletions src/layer/vector/Canvas.js
Expand Up @@ -68,6 +68,7 @@ export var Canvas = Renderer.extend({
},

_destroyContainer: function () {
Util.cancelAnimFrame(this._redrawRequest);
delete this._ctx;
DomUtil.remove(this._container);
DomEvent.off(this._container);
Expand Down