Atlaslog
Atlaslog / MapLibre GL JS / API / fitBounds
MapLibre GL JS · API reference

fitBounds

Quick answer

fitBounds ( bounds : LngLatBoundsLike , options? : FitBoundsOptions , eventData? : any ): this

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Runnable examplesChinese noteAll API topics
fitBounds()

fitBounds(bounds: LngLatBoundsLike, options?: FitBoundsOptions, eventData?: any): this

Defined in: ui/map.ts:1394

Pans and zooms the map to contain its visible area within the specified geographical bounds. This function will also reset the map's bearing to 0 if bearing is nonzero.

Triggers the following events: movestart and moveend.

Parameters

Parameter Type Description
bounds LngLatBoundsLike Center these bounds in the viewport and use the highest zoom level up to and including Map.getMaxZoom that fits them in the viewport. Bounds will be taken in [sw, ne] order. Southwest point will always be to the left of the northeast point.
options? FitBoundsOptions Options supports all properties from AnimationOptions and CameraOptions in addition to the fields below.
eventData? any Additional properties to be added to event objects of events triggered by this method.

Returns

this

Example

let bbox = [[-79, 43], [-73, 45]];
map.fitBounds(bbox, {
  padding: {top: 10, bottom:25, left: 15, right: 5}
});

See

Fit a map to a bounding box


TutorialsAPI index
English reference text adapted from the official MapLibre GL JS documentation, © MapLibre contributors, licensed under BSD-3-Clause.
Original page: https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ · Chinese note: /maplibre/api/fit-bounds.html
Cite this page

Atlaslog (2026). fitBounds. https://www.jingweizhi.com/en/maplibre/api/fit-bounds.html (accessed 2026-11-03).