Bug when using map option `preferCanvas: true` (canvas renderer for paths) and removing then adding back a vector within the same animation frame (typically in the same sequence, as done by Leaflet.markercluster at `"zoomend"` event, to remove layers and clusters outside visible bounds). This commit clears the `_removed` flag from paths when they are added to the canvas. Also added corresponding test suites.
This commit is contained in:
parent
814fe5dab4
commit
34dca3cfd9
@ -157,4 +157,36 @@ describe('Canvas', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('removes vector on next animation frame', function (done) {
|
||||||
|
var layer = L.circle([0, 0]).addTo(map),
|
||||||
|
layerId = L.stamp(layer),
|
||||||
|
canvas = map.getRenderer(layer);
|
||||||
|
|
||||||
|
expect(canvas._layers.hasOwnProperty(layerId)).to.be(true);
|
||||||
|
|
||||||
|
map.removeLayer(layer);
|
||||||
|
// Defer check due to how Canvas renderer manages layer removal.
|
||||||
|
L.Util.requestAnimFrame(function () {
|
||||||
|
expect(canvas._layers.hasOwnProperty(layerId)).to.be(false);
|
||||||
|
done();
|
||||||
|
}, this);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds vectors even if they have been removed just before', function (done) {
|
||||||
|
var layer = L.circle([0, 0]).addTo(map),
|
||||||
|
layerId = L.stamp(layer),
|
||||||
|
canvas = map.getRenderer(layer);
|
||||||
|
|
||||||
|
expect(canvas._layers.hasOwnProperty(layerId)).to.be(true);
|
||||||
|
|
||||||
|
map.removeLayer(layer);
|
||||||
|
map.addLayer(layer);
|
||||||
|
expect(canvas._layers.hasOwnProperty(layerId)).to.be(true);
|
||||||
|
// Re-perform a deferred check due to how Canvas renderer manages layer removal.
|
||||||
|
L.Util.requestAnimFrame(function () {
|
||||||
|
expect(canvas._layers.hasOwnProperty(layerId)).to.be(true);
|
||||||
|
done();
|
||||||
|
}, this);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -89,7 +89,9 @@ L.Canvas = L.Renderer.extend({
|
|||||||
this._layers[L.stamp(layer)] = layer;
|
this._layers[L.stamp(layer)] = layer;
|
||||||
},
|
},
|
||||||
|
|
||||||
_addPath: L.Util.falseFn,
|
_addPath: function (layer) {
|
||||||
|
layer._removed = false;
|
||||||
|
},
|
||||||
|
|
||||||
_removePath: function (layer) {
|
_removePath: function (layer) {
|
||||||
layer._removed = true;
|
layer._removed = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user