You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am removing a canvas map using map.remove() and creating a new canvas map and I am getting the error: Uncaught TypeError: Cannot read property 'clearRect' of undefined
I have created a codepen to show the issue, just uncomment the mymap.remove(); and comment out the setTimeout and you will see the error. https://codepen.io/moxy/pen/QaeKdp
, so that everything is drawn during the next frame.
In this case, the map (or the canvas renderer) is removed during that request for the animation frame, so the delayed call to _redraw is trying to get the drawing context, which has already been destroyed.
There are several approaches to this, but I feel that the cleanest is to call Util.cancelAnimFrame(this._requestRedraw) in L.Canvas._destroyContainer, next to
This bug seems that can be triggered programatically, so if anybody wants to fix this, I encourage to do Test-Driven Development for this one. Add a unit test over at https://github.com/Leaflet/Leaflet/blob/master/spec/suites/layer/vector/CanvasSpec.js , make sure it fails with the same error message, then fix the bug, then check if the tests pass.
Cancel animation frame before removing the map.
This fixes the bug where the the delayed call to _redraw is trying to get the drawing context which has already been destroyed.
I am removing a canvas map using map.remove() and creating a new canvas map and I am getting the error:
Uncaught TypeError: Cannot read property 'clearRect' of undefined
I have created a codepen to show the issue, just uncomment the mymap.remove(); and comment out the setTimeout and you will see the error.
https://codepen.io/moxy/pen/QaeKdp
The text was updated successfully, but these errors were encountered: