map.fitBounds with padding affects the map.getBounds
Author: benderlidzeCreated Feb 18, 2025Updated Aug 26, 2026
Labelsbug :lady_beetle:auto-triaged
map.fitBounds(bounds, { padding: 150 }) in v3.10 somehow sets the global bounds. If you call map.getBounds(), it returns the bounds including the 150 px padding, which is incorrect.
In v2, map.getBounds() returns the correct bounds covering 100% of the height and width without any padding.
map.fitBounds(bounds, { padding: 150 });
const s = map.getBounds();
console.log('s', s);v2 Results: [7.1204, 52.6618, 13.8875, 59.2029] v3 Results: [8.4594, 53.4663, 12.5486, 58.5104]
Source: mapbox/mapbox-gl-js