Skip to content

Commit

Permalink
Refactor L.Path _update and _project into L.Renderer so that no event…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
IvanSanchez authored and DiogoMCampos committed Dec 18, 2016
1 parent 1f85003 commit 4c1ac3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/layer/vector/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 0 additions & 9 deletions src/layer/vector/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/layer/vector/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 2 additions & 0 deletions src/layer/vector/SVG.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ L.SVG = L.Renderer.extend({
}

this._updateStyle(layer);
this._layers[L.stamp(layer)] = layer;
},

_addPath: function (layer) {
Expand All @@ -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) {
Expand Down

0 comments on commit 4c1ac3d

Please sign in to comment.