Avoid multiple canvas updatePaths/redraws during viewreset (#5250)

* Avoid multiple canvas updatePaths/redraws during viewreset

Close #5170.

* Fix code style

* Add a code comment
This commit is contained in:
Per Liedman
2017-01-23 11:06:03 +01:00
committed by Iván Sánchez Ortega
parent 2b5d401976
commit 67f12ee6e9

View File

@ -31,6 +31,16 @@
*/
L.Canvas = L.Renderer.extend({
getEvents: function () {
var events = L.Renderer.prototype.getEvents.call(this);
events.viewprereset = this._onViewPreReset;
return events;
},
_onViewPreReset: function () {
// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once
this._postponeUpdatePaths = true;
},
onAdd: function () {
L.Renderer.prototype.onAdd.call(this);
@ -52,6 +62,8 @@ L.Canvas = L.Renderer.extend({
},
_updatePaths: function () {
if (this._postponeUpdatePaths) { return; }
var layer;
this._redrawBounds = null;
for (var id in this._layers) {
@ -92,6 +104,15 @@ L.Canvas = L.Renderer.extend({
this.fire('update');
},
_reset: function () {
L.Renderer.prototype._reset.call(this);
if (this._postponeUpdatePaths) {
this._postponeUpdatePaths = false;
this._updatePaths();
}
},
_initPath: function (layer) {
this._updateDashArray(layer);
this._layers[L.stamp(layer)] = layer;