diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index 37b5f689..44fdc1b0 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -35,8 +35,6 @@ L.Canvas = L.Renderer.extend({ onAdd: function () { L.Renderer.prototype.onAdd.call(this); - this._layers = this._layers || {}; - // Redraw vectors since canvas is cleared upon removal, // in case of removing the renderer itself from the map. this._draw(); diff --git a/src/layer/vector/Path.js b/src/layer/vector/Path.js index 9b10e852..dca7a032 100644 --- a/src/layer/vector/Path.js +++ b/src/layer/vector/Path.js @@ -76,19 +76,10 @@ L.Path = L.Layer.extend({ this._renderer._initPath(this); this._reset(); this._renderer._addPath(this); - this._renderer.on('update', this._update, this); }, onRemove: function () { this._renderer._removePath(this); - this._renderer.off('update', this._update, this); - }, - - getEvents: function () { - return { - zoomend: this._project, - viewreset: this._reset - }; }, // @method redraw(): this diff --git a/src/layer/vector/Renderer.js b/src/layer/vector/Renderer.js index 81bd26bd..b7638de1 100644 --- a/src/layer/vector/Renderer.js +++ b/src/layer/vector/Renderer.js @@ -32,6 +32,7 @@ L.Renderer = L.Layer.extend({ initialize: function (options) { L.setOptions(this, options); L.stamp(this); + this._layers = this._layers || {}; }, onAdd: function () { @@ -45,17 +46,20 @@ L.Renderer = L.Layer.extend({ this.getPane().appendChild(this._container); this._update(); + this.on('update', this._updatePaths, this); }, onRemove: function () { L.DomUtil.remove(this._container); + this.off('update', this._updatePaths, this); }, getEvents: function () { var events = { viewreset: this._reset, zoom: this._onZoom, - moveend: this._update + moveend: this._update, + zoomend: this._onZoomEnd }; if (this._zoomAnimated) { events.zoomanim = this._onAnimZoom; @@ -91,6 +95,22 @@ L.Renderer = L.Layer.extend({ _reset: function () { this._update(); this._updateTransform(this._center, this._zoom); + + for (var id in this._layers) { + this._layers[id]._reset(); + } + }, + + _onZoomEnd: function () { + for (var id in this._layers) { + this._layers[id]._project(); + } + }, + + _updatePaths: function () { + for (var id in this._layers) { + this._layers[id]._update(); + } }, _update: function () { diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index a670b63f..66be5b67 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -99,6 +99,7 @@ L.SVG = L.Renderer.extend({ } this._updateStyle(layer); + this._layers[L.stamp(layer)] = layer; }, _addPath: function (layer) { @@ -109,6 +110,7 @@ L.SVG = L.Renderer.extend({ _removePath: function (layer) { L.DomUtil.remove(layer._path); layer.removeInteractiveTarget(layer._path); + delete this._layers[L.stamp(layer)]; }, _updatePath: function (layer) {