diff --git a/src/ui/control/navigation_control.js b/src/ui/control/navigation_control.js index 145f313fcc4..65515352200 100644 --- a/src/ui/control/navigation_control.js +++ b/src/ui/control/navigation_control.js @@ -91,9 +91,10 @@ class NavigationControl { `scale(${1 / Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)), 0.5)}) rotateX(${this._map.transform.pitch}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` : `rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`; - const icon = this._compassIcon; this._map._domRenderTaskQueue.add(() => { - icon.style.transform = rotate; + if (this._compassIcon) { + this._compassIcon.style.transform = rotate; + } }); } diff --git a/src/ui/control/scale_control.js b/src/ui/control/scale_control.js index c60b87018a1..1ce825a7871 100644 --- a/src/ui/control/scale_control.js +++ b/src/ui/control/scale_control.js @@ -103,24 +103,24 @@ function updateScale(map, container, options) { const maxFeet = 3.2808 * maxMeters; if (maxFeet > 5280) { const maxMiles = maxFeet / 5280; - setScale(map, container, maxWidth, maxMiles, map._getUIString('ScaleControl.Miles')); + setScale(container, maxWidth, maxMiles, map._getUIString('ScaleControl.Miles'), map._domRenderTaskQueue); } else { - setScale(map, container, maxWidth, maxFeet, map._getUIString('ScaleControl.Feet')); + setScale(container, maxWidth, maxFeet, map._getUIString('ScaleControl.Feet'), map._domRenderTaskQueue); } } else if (options && options.unit === 'nautical') { const maxNauticals = maxMeters / 1852; - setScale(map, container, maxWidth, maxNauticals, map._getUIString('ScaleControl.NauticalMiles')); + setScale(container, maxWidth, maxNauticals, map._getUIString('ScaleControl.NauticalMiles'), map._domRenderTaskQueue); } else if (maxMeters >= 1000) { - setScale(map, container, maxWidth, maxMeters / 1000, map._getUIString('ScaleControl.Kilometers')); + setScale(container, maxWidth, maxMeters / 1000, map._getUIString('ScaleControl.Kilometers'), map._domRenderTaskQueue); } else { - setScale(map, container, maxWidth, maxMeters, map._getUIString('ScaleControl.Meters')); + setScale(container, maxWidth, maxMeters, map._getUIString('ScaleControl.Meters'), map._domRenderTaskQueue); } } -function setScale(map, container, maxWidth, maxDistance, unit) { +function setScale(container, maxWidth, maxDistance, unit, mapQueue) { const distance = getRoundNum(maxDistance); const ratio = distance / maxDistance; - map._domRenderTaskQueue.add(() => { + mapQueue.add(() => { container.style.width = `${maxWidth * ratio}px`; container.innerHTML = `${distance} ${unit}`; }); diff --git a/src/ui/handler/box_zoom.js b/src/ui/handler/box_zoom.js index 8928aaae6d0..aed9237ef86 100644 --- a/src/ui/handler/box_zoom.js +++ b/src/ui/handler/box_zoom.js @@ -107,12 +107,13 @@ class BoxZoomHandler { minY = Math.min(p0.y, pos.y), maxY = Math.max(p0.y, pos.y); - const box = this._box; this._map._domRenderTaskQueue.add(() => { - DOM.setTransform(box, `translate(${minX}px,${minY}px)`); + if (this._box) { + DOM.setTransform(this._box, `translate(${minX}px,${minY}px)`); - box.style.width = `${maxX - minX}px`; - box.style.height = `${maxY - minY}px`; + this._box.style.width = `${maxX - minX}px`; + this._box.style.height = `${maxY - minY}px`; + } }); } diff --git a/src/ui/popup.js b/src/ui/popup.js index 13aa924c383..c7db0632fa5 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -572,11 +572,11 @@ export default class Popup extends Evented { } const offsetedPos = pos.add(offset[anchor]).round(); - const container = this._container; - const _anchor = anchor; this._map._domRenderTaskQueue.add(() => { - DOM.setTransform(container, `${anchorTranslate[_anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`); - applyAnchorClass(container, _anchor, 'popup'); + if (this._container && anchor) { + DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`); + applyAnchorClass(this._container, anchor, 'popup'); + } }); }