fixes problem with leaks on map move

This commit is contained in:
javi 2014-03-21 13:27:04 +01:00
parent fc09a86e51
commit 2d22276bfd

View File

@ -31,11 +31,13 @@ L.CanvasLayer = L.Class.extend({
// backCanvas for zoom animation
this._backCanvas = this._createCanvas();
this._ctx = this._canvas.getContext('2d');
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
this.currentAnimationFrame = -1;
this.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
return window.setTimeout(callback, 1000 / 60);
};
this.requestAnimationFrame = requestAnimationFrame;
this.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame ||
window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || function(id) { clearTimeout(id); };
},
_createCanvas: function() {
@ -189,7 +191,10 @@ L.CanvasLayer = L.Class.extend({
_updateOpacity: function () { },
_render: function() {
this.requestAnimationFrame.call(window, this.render);
if (this.currentAnimationFrame >= 0) {
this.cancelAnimationFrame.call(window, this.currentAnimationFrame);
}
this.currentAnimationFrame = this.requestAnimationFrame.call(window, this.render);
},
// use direct: true if you are inside an animation frame call