'How to add bounds and padding in MapBox constructor?
With map.fitBounds(bounds, {padding: 100}), it is possible to add padding while setting the bounds making sure your markers (on which 'bounds' are based) are all nicely shown inside the viewable part of the map.
I'd like to achive the same in the constructor where the bounds can be set like this:
var map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds});
I can't find a way to include the padding - does anyone know how?
Update: Thanks @Steve - just confirming your solution solves my problem.
Solution 1:[1]
That's what the fitBoundsOptions parameter is for:
A Map#fitBounds options object to use only when fitting the initial bounds provided above.
Use it like this:
const map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds,
fitBoundsOptions: { padding: {top: 10, bottom:25, left: 15, right: 5}}});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Steve Bennett |
