Skip to content

Restrict map panning to an area

Replicates the MapLibre example Restrict map panning to an area: the camera cannot leave Manhattan.

Try panning away — the camera stays inside the bounds
restrict-map-panning-to-an-area.yaml
# 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/restrict-map-panning-to-an-area/
# Try panning away from Manhattan — the camera snaps back inside maxBounds.
type: map
id: restrict-map-panning-to-an-area
config:
center: [-73.9978, 40.7209]
zoom: 12
maxBounds: [-74.047285, 40.683927, -73.910586, 40.877645]
mapStyle: "https://demotiles.maplibre.org/style.json"
  • config.maxBounds constrains panning and zooming-out. Its friends minZoom/maxZoom/minPitch/maxPitch cover the other camera constraints.