From 158dece43a7fcf613e5376c960cd1991c4590a42 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Thu, 6 May 2021 12:25:05 -0700 Subject: [PATCH] Directly use DOM queue rencently introduced by #10530 --- src/ui/marker.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/ui/marker.js b/src/ui/marker.js index 29d2a11ed49..20d65d59c2b 100644 --- a/src/ui/marker.js +++ b/src/ui/marker.js @@ -448,7 +448,7 @@ export default class Marker extends Evented { return this; } - _evaluateOpacity(requestAnimationFrame: boolean = false) { + _evaluateOpacity() { const position = this._pos ? this._pos.sub(this._transformedOffset()) : null; if (!this._withinScreenBounds(position)) { @@ -472,16 +472,8 @@ export default class Marker extends Evented { const fogOpacity = this._map.queryFogOpacity(mapLocation); const opacity = (1.0 - fogOpacity) * (terrainOccluded ? TERRAIN_OCCLUDED_OPACITY : 1.0); - const updateStyle = () => { - this._element.style.opacity = `${opacity}`; - if (this._popup) this._popup._setOpacity(`${opacity}`); - }; - - if (requestAnimationFrame) { - window.requestAnimationFrame(updateStyle); - } else { - updateStyle(); - } + this._element.style.opacity = `${opacity}`; + if (this._popup) this._popup._setOpacity(`${opacity}`); this._fadeTimer = null; } @@ -531,14 +523,16 @@ export default class Marker extends Evented { } this._map._requestDomTask(() => { + if (!this._map) return; + if (this._element && this._pos && this._anchor) { DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`); } - }); - if ((this._map.getTerrain() || this._map.getFog()) && !this._fadeTimer) { - this._fadeTimer = setTimeout(this._evaluateOpacity.bind(this, true), 60); - } + if ((this._map.getTerrain() || this._map.getFog()) && !this._fadeTimer) { + this._fadeTimer = setTimeout(this._evaluateOpacity.bind(this), 60); + } + }); } /**