Make paths insensitive to the order of its map's moveend handlers (#4855)
* Make Paths always update after renderer updates Close #4851 * Add test * Add docs for update event * Remove listener when layer is removed
This commit is contained in:
parent
2ced69db12
commit
ed1a612e6f
@ -52,5 +52,30 @@ describe('Path', function () {
|
||||
expect(mapSpy.called).to.be.ok();
|
||||
});
|
||||
|
||||
it('can add a layer while being inside a moveend handler', function (done) {
|
||||
var zoneLayer = L.layerGroup();
|
||||
var polygon;
|
||||
map.addLayer(zoneLayer);
|
||||
|
||||
map.on('moveend', function () {
|
||||
zoneLayer.clearLayers();
|
||||
polygon = new L.Polygon([[1, 2], [3, 4], [5, 6]]);
|
||||
zoneLayer.addLayer(polygon);
|
||||
});
|
||||
|
||||
map.invalidateSize();
|
||||
map.setView([1, 2], 12, {animate: false});
|
||||
|
||||
map.panBy([-260, 0]);
|
||||
setTimeout(function () {
|
||||
expect(polygon._parts.length).to.be(0);
|
||||
map.panBy([260, 0]);
|
||||
setTimeout(function () {
|
||||
expect(polygon._parts.length).to.be(1);
|
||||
done();
|
||||
}, 300);
|
||||
}, 300);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -76,16 +76,17 @@ 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,
|
||||
moveend: this._update,
|
||||
viewreset: this._reset
|
||||
};
|
||||
},
|
||||
|
@ -13,6 +13,9 @@
|
||||
*
|
||||
* Do not use this class directly, use `SVG` and `Canvas` instead.
|
||||
*
|
||||
* @event update: Event
|
||||
* Fired when the renderer updates its bounds, center and zoom, for example when
|
||||
* its map has moved
|
||||
*/
|
||||
|
||||
L.Renderer = L.Layer.extend({
|
||||
@ -100,6 +103,8 @@ L.Renderer = L.Layer.extend({
|
||||
|
||||
this._center = this._map.getCenter();
|
||||
this._zoom = this._map.getZoom();
|
||||
|
||||
this.fire('update');
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user