fitBound end up in error of NaN after call
mapbox-gl-js version: 1.13.1
browser: Tested in Chrome and Firefox
Steps to Trigger Behavior
- Set a map element with a size
x(example: 400px) - Call
fitBoundsmethod passing CameraOptions with padding beingx / 2(example: 200px)
Expected Behavior
Map should fit to provided boundaries
Actual Behavior
At this moment when it happens to map element width to be x and the padding (right and left) to be x / 2 we end up with the Point object generated in _cameraForBoxAndBearing to be a set of NaN of x and y, this happens due to the fact we multiply 0 with Infinity and the method just throw an error.
-
https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/camera.js#L579 Here we have
scaleXbeing assigned to 0 astr.widthbeingx(e.g: 400px) andedgePadding.left or .rightbeing 0 andeOptions.padding.left or rightbeingx / 2(e.g: 200px) -
https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/camera.js#L588
zoomis assigned to-Infinityas intr. scaleZoomit doesMath.log(scale) / Math.LN2and log of 0 if-Infinity -
https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/camera.js#L597
offsetAtFinalZoomis assigned to{ x: NaN, y: NaN }as we havetr.zoomScale(zoom)returning 0 as result toMath.pow(2, -Infinity)and we gety/0which turns intoInfinityand finally we get.multreturningNaNfrom0 * Infinity

This might be a duplicate of #8732?