Fix Canvas rendering after removing and adding (#9608)

This commit is contained in:
Florian Bischof
2025-03-15 09:50:12 +01:00
committed by GitHub
parent 0549bf24ed
commit d2ed402d3d
2 changed files with 20 additions and 0 deletions

View File

@ -222,6 +222,25 @@ describe('Canvas', () => {
}, this);
});
it('adds vectors even if the canvas container was removed', (done) => {
const layer = new Circle([0, 0]).addTo(map);
map.eachLayer((layer) => {
map.removeLayer(layer);
});
const spy = sinon.spy();
const canvas = map.getRenderer(layer);
canvas._redraw = spy;
map.addLayer(layer);
setTimeout(() => {
// we need the timeout, because else the requestAnimFrame is not called
expect(spy.callCount).to.eql(1);
done();
}, 50);
});
describe('#bringToBack', () => {
it('is a no-op for layers not on a map', () => {
const path = new Polyline([[1, 2], [3, 4], [5, 6]]);

View File

@ -79,6 +79,7 @@ export const Canvas = Renderer.extend({
_destroyContainer() {
Util.cancelAnimFrame(this._redrawRequest);
this._redrawRequest = null;
delete this._ctx;
Renderer.prototype._destroyContainer.call(this);
},