From f99a4173fea9cb2ef7557eede0e6ed4ba1eeb536 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 16 Jul 2012 13:57:00 +0300 Subject: [PATCH] optimize canvas layers update, closes #732, closes #785 --- src/layer/vector/canvas/Path.Canvas.js | 48 +++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/layer/vector/canvas/Path.Canvas.js b/src/layer/vector/canvas/Path.Canvas.js index 6ff49c0e..c8131911 100644 --- a/src/layer/vector/canvas/Path.Canvas.js +++ b/src/layer/vector/canvas/Path.Canvas.js @@ -13,6 +13,45 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : SVG: false }, + redraw: function () { + if (this._map) { + this.projectLatlngs(); + this._requestUpdate(); + } + return this; + }, + + setStyle: function (style) { + L.Util.setOptions(this, style); + + if (this._map) { + this._updateStyle(); + this._requestUpdate(); + } + return this; + }, + + onRemove: function (map) { + map + .off('viewreset', this.projectLatlngs, this) + .off('moveend', this._updatePath, this); + + this._requestUpdate(); + + this._map = null; + }, + + _requestUpdate: function () { + if (this._map) { + L.Util.cancelAnimFrame(this._fireMapMoveEnd); + this._updateRequest = L.Util.requestAnimFrame(this._fireMapMoveEnd, this._map); + } + }, + + _fireMapMoveEnd: function () { + this.fire('moveend'); + }, + _initElements: function () { this._map._initPathRoot(); this._ctx = this._map._canvasCtx; @@ -94,14 +133,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path : if (this._containsPoint(e.layerPoint)) { this.fire('click', e); } - }, - - onRemove: function (map) { - map - .off('viewreset', this._projectLatlngs, this) - .off('moveend', this._updatePath, this) - .fire('moveend'); - } + } }); L.Map.include((L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? {} : {