Skip to content

Commit 4c1ac3d

Browse files
IvanSanchezDiogoMCampos
authored andcommitted
Refactor L.Path _update and _project into L.Renderer so that no event handling is needed (Leaflet#5054)
* Refactor L.Path _update and _project into L.Renderer so that no event handling is needed * Refactor away L.Path's _update event logic
1 parent 1f85003 commit 4c1ac3d

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/layer/vector/Canvas.js

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ L.Canvas = L.Renderer.extend({
3535
onAdd: function () {
3636
L.Renderer.prototype.onAdd.call(this);
3737

38-
this._layers = this._layers || {};
39-
4038
// Redraw vectors since canvas is cleared upon removal,
4139
// in case of removing the renderer itself from the map.
4240
this._draw();

src/layer/vector/Path.js

-9
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,10 @@ L.Path = L.Layer.extend({
7676
this._renderer._initPath(this);
7777
this._reset();
7878
this._renderer._addPath(this);
79-
this._renderer.on('update', this._update, this);
8079
},
8180

8281
onRemove: function () {
8382
this._renderer._removePath(this);
84-
this._renderer.off('update', this._update, this);
85-
},
86-
87-
getEvents: function () {
88-
return {
89-
zoomend: this._project,
90-
viewreset: this._reset
91-
};
9283
},
9384

9485
// @method redraw(): this

src/layer/vector/Renderer.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ L.Renderer = L.Layer.extend({
3232
initialize: function (options) {
3333
L.setOptions(this, options);
3434
L.stamp(this);
35+
this._layers = this._layers || {};
3536
},
3637

3738
onAdd: function () {
@@ -45,17 +46,20 @@ L.Renderer = L.Layer.extend({
4546

4647
this.getPane().appendChild(this._container);
4748
this._update();
49+
this.on('update', this._updatePaths, this);
4850
},
4951

5052
onRemove: function () {
5153
L.DomUtil.remove(this._container);
54+
this.off('update', this._updatePaths, this);
5255
},
5356

5457
getEvents: function () {
5558
var events = {
5659
viewreset: this._reset,
5760
zoom: this._onZoom,
58-
moveend: this._update
61+
moveend: this._update,
62+
zoomend: this._onZoomEnd
5963
};
6064
if (this._zoomAnimated) {
6165
events.zoomanim = this._onAnimZoom;
@@ -91,6 +95,22 @@ L.Renderer = L.Layer.extend({
9195
_reset: function () {
9296
this._update();
9397
this._updateTransform(this._center, this._zoom);
98+
99+
for (var id in this._layers) {
100+
this._layers[id]._reset();
101+
}
102+
},
103+
104+
_onZoomEnd: function () {
105+
for (var id in this._layers) {
106+
this._layers[id]._project();
107+
}
108+
},
109+
110+
_updatePaths: function () {
111+
for (var id in this._layers) {
112+
this._layers[id]._update();
113+
}
94114
},
95115

96116
_update: function () {

src/layer/vector/SVG.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ L.SVG = L.Renderer.extend({
9999
}
100100

101101
this._updateStyle(layer);
102+
this._layers[L.stamp(layer)] = layer;
102103
},
103104

104105
_addPath: function (layer) {
@@ -109,6 +110,7 @@ L.SVG = L.Renderer.extend({
109110
_removePath: function (layer) {
110111
L.DomUtil.remove(layer._path);
111112
layer.removeInteractiveTarget(layer._path);
113+
delete this._layers[L.stamp(layer)];
112114
},
113115

114116
_updatePath: function (layer) {

0 commit comments

Comments
 (0)