From 69cb97973c66091ddfb57a3ada298c2c9a3a7790 Mon Sep 17 00:00:00 2001 From: Sam Claus Date: Sun, 30 Jul 2023 00:30:46 -0400 Subject: [PATCH 1/4] Clean up DOM event listeners when destroying Map's animation proxy --- src/map/Map.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map/Map.js b/src/map/Map.js index 70527d81076..1a5e578dd7e 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -1643,6 +1643,7 @@ export const Map = Evented.extend({ }, _destroyAnimProxy() { + DomEvent.off(this._proxy, 'transitionend', this._catchTransitionEnd, this); this._proxy.remove(); this.off('load moveend', this._animMoveEnd, this); delete this._proxy; From a230c4f1d9f80c10f9703b9826cc57b2116646be Mon Sep 17 00:00:00 2001 From: Sam Claus Date: Sun, 30 Jul 2023 14:44:22 -0400 Subject: [PATCH 2/4] Implement requested changes and clean up animation proxy code --- src/map/Map.js | 62 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 1a5e578dd7e..ab2f5d01776 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -159,7 +159,6 @@ export const Map = Evented.extend({ // happens after starting zoom animation (propagating to the map pane), we know that it ended globally if (this._zoomAnimated) { this._createAnimProxy(); - DomEvent.on(this._proxy, 'transitionend', this._catchTransitionEnd, this); } this._addLayers(this.options.layers); @@ -779,6 +778,8 @@ export const Map = Evented.extend({ this.fire('unload'); } + this._destroyAnimProxy(); + let i; for (i in this._layers) { if (Object.hasOwn(this._layers, i)) { @@ -1622,37 +1623,54 @@ export const Map = Evented.extend({ }, _createAnimProxy() { + this._proxy = DomUtil.create('div', 'leaflet-proxy leaflet-zoom-animated'); + this._panes.mapPane.appendChild(this._proxy); - const proxy = this._proxy = DomUtil.create('div', 'leaflet-proxy leaflet-zoom-animated'); - this._panes.mapPane.appendChild(proxy); + this.on('zoomanim', this._animateProxyZoom, this); + this.on('load moveend', this._animMoveEnd, this); - this.on('zoomanim', function (e) { - const transform = this._proxy.style.transform; + DomEvent.on(this._proxy, 'transitionend', this._catchTransitionEnd, this); + }, - DomUtil.setTransform(this._proxy, this.project(e.center, e.zoom), this.getZoomScale(e.zoom, 1)); + _animateProxyZoom(e) { + const transform = this._proxy.style.transform; - // workaround for case when transform is the same and so transitionend event is not fired - if (transform === this._proxy.style.transform && this._animatingZoom) { - this._onZoomTransitionEnd(); - } - }, this); + DomUtil.setTransform( + this._proxy, + this.project(e.center, e.zoom), + this.getZoomScale(e.zoom, 1), + ); - this.on('load moveend', this._animMoveEnd, this); + // workaround for case when transform is the same and so transitionend event is not fired + if (transform === this._proxy.style.transform && this._animatingZoom) { + this._onZoomTransitionEnd(); + } + }, - this._on('unload', this._destroyAnimProxy, this); + _animMoveEnd() { + const + c = this.getCenter(), + z = this.getZoom(); + + DomUtil.setTransform( + this._proxy, + this.project(c, z), + this.getZoomScale(z, 1), + ); }, _destroyAnimProxy() { - DomEvent.off(this._proxy, 'transitionend', this._catchTransitionEnd, this); - this._proxy.remove(); - this.off('load moveend', this._animMoveEnd, this); - delete this._proxy; - }, + // Just make sure this method is safe to call from anywhere, without knowledge + // of whether the animation proxy was created in the first place. + if (this._proxy) { + DomEvent.off(this._proxy, 'transitionend', this._catchTransitionEnd, this); - _animMoveEnd() { - const c = this.getCenter(), - z = this.getZoom(); - DomUtil.setTransform(this._proxy, this.project(c, z), this.getZoomScale(z, 1)); + this._proxy.remove(); + this.off('zoomanim', this._animateProxyZoom, this); + this.off('load moveend', this._animMoveEnd, this); + + delete this._proxy; + } }, _catchTransitionEnd(e) { From 80f36ac615ee48b6b0f09254071f996ea1c0f41f Mon Sep 17 00:00:00 2001 From: Florian Bischof Date: Sun, 30 Jul 2023 22:31:42 +0200 Subject: [PATCH 3/4] Update src/map/Map.js --- src/map/Map.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index ab2f5d01776..4fe2a1ae3b2 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -1648,9 +1648,9 @@ export const Map = Evented.extend({ }, _animMoveEnd() { - const - c = this.getCenter(), - z = this.getZoom(); + const c = this.getCenter(), + z = this.getZoom(); + DomUtil.setTransform( this._proxy, From bee51c35e6959d49231773580ec2feb049a538b6 Mon Sep 17 00:00:00 2001 From: Florian Bischof Date: Sun, 30 Jul 2023 22:36:02 +0200 Subject: [PATCH 4/4] Update src/map/Map.js --- src/map/Map.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 4fe2a1ae3b2..a21e9c0b39d 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -1648,8 +1648,9 @@ export const Map = Evented.extend({ }, _animMoveEnd() { - const c = this.getCenter(), - z = this.getZoom(); + const c = this.getCenter(); + const z = this.getZoom(); + DomUtil.setTransform(