Fit a map to a bounding box
Replicates the MapLibre example Fit a map to a bounding box: the initial view frames a bounding box (here Kenya) regardless of the container’s pixel size.
The complete document
Section titled “The complete document”# yaml-language-server: $schema=https://docs.maplibre-yaml.org/schema/latest/map.schema.json# Gallery twin of https://maplibre.org/maplibre-gl-js/docs/examples/fit-a-map-to-a-bounding-box/# The initial viewport is the bounding box, whatever the container's pixels.type: mapid: fit-a-map-to-a-bounding-boxconfig: center: [0, 0] zoom: 1 bounds: [32.958984, -5.353521, 43.50585, 5.615985] mapStyle: "https://demotiles.maplibre.org/style.json"What to notice
Section titled “What to notice”config.bounds([west, south, east, north]) wins overcenter/zoomfor the initial camera — the upstream version needs afitBounds()call after construction.- Fitting to a source’s extent rather than literal bounds is a tracked gap (see the gallery index).