optimize canvas layers update, closes #732, closes #785

This commit is contained in:
Vladimir Agafonkin 2012-07-16 13:57:00 +03:00
parent 6bc8ea6eb5
commit f99a4173fe

View File

@ -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,13 +133,6 @@ 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');
}
});