mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

fitBound end up in error of NaN after call

Open mogobruno opened this issue 4 years ago • 1 comments

mapbox-gl-js version: 1.13.1

browser: Tested in Chrome and Firefox

Steps to Trigger Behavior

  1. Set a map element with a size x (example: 400px)
  2. Call fitBounds method passing CameraOptions with padding being x / 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 scaleX being assigned to 0 as tr.width being x (e.g: 400px) and edgePadding.left or .right being 0 and eOptions.padding.left or right being x / 2 (e.g: 200px)

  • https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/camera.js#L588 zoom is assigned to -Infinity as in tr. scaleZoom it does Math.log(scale) / Math.LN2 and log of 0 if -Infinity

  • https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/camera.js#L597 offsetAtFinalZoom is assigned to { x: NaN, y: NaN } as we have tr.zoomScale(zoom) returning 0 as result to Math.pow(2, -Infinity) and we get y/0 which turns into Infinity and finally we get .mult returning NaN from 0 * Infinity

test

mogobruno avatar Mar 16 '21 16:03 mogobruno

This might be a duplicate of #8732?

tv42 avatar Dec 28 '22 00:12 tv42